aboutsummaryrefslogtreecommitdiffstats
path: root/spec/views
diff options
context:
space:
mode:
Diffstat (limited to 'spec/views')
-rw-r--r--spec/views/stop_areas/index.html.erb_spec.rb78
1 files changed, 27 insertions, 51 deletions
diff --git a/spec/views/stop_areas/index.html.erb_spec.rb b/spec/views/stop_areas/index.html.erb_spec.rb
index a354586d2..e0c50685c 100644
--- a/spec/views/stop_areas/index.html.erb_spec.rb
+++ b/spec/views/stop_areas/index.html.erb_spec.rb
@@ -1,6 +1,25 @@
require 'spec_helper'
+RSpec::Matchers.define :have_link_for_each_stop_area do |stop_areas, name, href|
+ match do |actual|
+ stop_areas.each do |stop_area|
+ expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{href.call(stop_area)}']", count: 1)
+ end
+ end
+ description { "have #{name} link for each stop area" }
+end
+
+RSpec::Matchers.define :have_the_right_number_of_links do |stop_areas, count|
+ match do |actual|
+ stop_areas.each do |stop_area|
+ expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: count)
+ end
+ end
+ description { "have #{count} links for each stop area" }
+end
+
describe "/stop_areas/index", :type => :view do
+
let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) }
let!(:stop_areas) do
2.times { create(:stop_area, stop_area_referential: stop_area_referential) }
@@ -16,62 +35,19 @@ describe "/stop_areas/index", :type => :view do
render
end
- it "should render a row for each group" do
- stop_areas.each do |stop_area|
- expect(rendered).to have_selector("tr.stoparea-#{stop_area.id}", count: 1)
- end
- end
-
- it "should render a show link for each group" do
- stop_areas.each do |stop_area|
- expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", count: 1)
- end
- end
-
- it "should render no other link for each group" do
- stop_areas.each do |stop_area|
- expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: 1)
- end
- end
+ it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) }
+ it { should have_the_right_number_of_links(stop_areas, 1) }
with_permission "stop_areas.create" do
- it "should render a show link for each group" do
- stop_areas.each do |stop_area|
- expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", count: 1)
- end
- end
-
- it "should render a create link for each group" do
- stop_areas.each do |stop_area|
- expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.new_stop_area_referential_stop_area_path(stop_area_referential)}']", count: 1)
- end
- end
-
- it "should render no other link for each group" do
- stop_areas.each do |stop_area|
- expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: 2)
- end
- end
+ it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) }
+ it { should have_link_for_each_stop_area(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) }
+ it { should have_the_right_number_of_links(stop_areas, 2) }
end
with_permission "stop_areas.update" do
- it "should render a show link for each group" do
- stop_areas.each do |stop_area|
- expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", count: 1)
- end
- end
-
- it "should render a edit link for each group" do
- stop_areas.each do |stop_area|
- expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area.id)}']", count: 1)
- end
- end
-
- it "should render no other link for each group" do
- stop_areas.each do |stop_area|
- expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: 2)
- end
- end
+ it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) }
+ it { should have_link_for_each_stop_area(stop_areas, "edit", -> (stop_area){ view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) }
+ it { should have_the_right_number_of_links(stop_areas, 2) }
end
end