diff options
| author | Zog | 2017-12-15 17:01:49 +0100 |
|---|---|---|
| committer | Zog | 2017-12-19 19:13:26 +0100 |
| commit | 180a1c709a54f76438903af9ea5c361cc365d3e0 (patch) | |
| tree | 7f9381b88ffadbd214b97cbe2802032e9bd97131 | |
| parent | 818bacf718594441052820ea0e7b33b9491a5b71 (diff) | |
| download | chouette-core-180a1c709a54f76438903af9ea5c361cc365d3e0.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
| -rw-r--r-- | spec/support/integration_spec_helper.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 78efb9027..b4d8a8283 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -19,6 +19,18 @@ module IntegrationSpecHelper context('', &block) if block_given? end 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 def self.included into @@ -47,3 +59,21 @@ RSpec::Matchers.define :have_the_right_number_of_links do |collection, count| end description { "have #{count} links for each item" } 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 |
