aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support
diff options
context:
space:
mode:
authorZog2017-12-15 17:01:49 +0100
committerZog2017-12-19 14:21:52 +0100
commit74a601f6f35e0a547d3cde0501081e6e9f509959 (patch)
treedd744b2ec44513fc32dfd51c20bda9219e16406a /spec/support
parentc78489f389cdb27c0afec254c7e5b76190ca2f54 (diff)
downloadchouette-core-74a601f6f35e0a547d3cde0501081e6e9f509959.tar.bz2
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
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/integration_spec_helper.rb30
1 files changed, 30 insertions, 0 deletions
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