From 2736ff5e010586266176a9a0fb0ac8dc6e227f63 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 17:01:49 +0100 Subject: Ref #5291@2h; Specs setup - Refactor specs helper to be more generic - Write missing specs for the Workbenches#show view We now have failing tests highlighting the bug --- spec/support/integration_spec_helper.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'spec/support') diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 182cadf24..5bcf0bd3a 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -4,9 +4,39 @@ module IntegrationSpecHelper let(:permissions){ [permission] } context('', &block) if block_given? end + + def paginate_collection klass, decorator, page=1 + ModelDecorator.decorate( klass.page(page), with: decorator ) + end + + def build_paginated_collection factory, decorator, opts={} + count = opts.delete(:count) || 2 + page = opts.delete(:page) || 1 + klass = nil + count.times { klass ||= create(factory, opts).class } + paginate_collection klass, decorator, page + end end end RSpec.configure do |config| config.extend IntegrationSpecHelper, type: :view end + +RSpec::Matchers.define :have_link_for_each_item do |collection, name, href| + match do |actual| + collection.each do |item| + expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a[href='#{href.call(item)}']", count: 1) + end + end + description { "have #{name} link for each item" } +end + +RSpec::Matchers.define :have_the_right_number_of_links do |collection, count| + match do |actual| + collection.each do |item| + expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a", count: count) + end + end + description { "have #{count} links for each item" } +end -- cgit v1.2.3