diff options
| -rw-r--r-- | spec/support/integration_spec_helper.rb | 12 | ||||
| -rw-r--r-- | spec/views/connection_links/show.html.slim_spec.rb | 32 | ||||
| -rw-r--r-- | spec/views/stop_areas/index.html.slim_spec.rb | 53 | 
3 files changed, 97 insertions, 0 deletions
| diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb new file mode 100644 index 000000000..182cadf24 --- /dev/null +++ b/spec/support/integration_spec_helper.rb @@ -0,0 +1,12 @@ +module IntegrationSpecHelper +  def with_permission permission, &block +    context "with permission #{permission}" do +      let(:permissions){ [permission] } +      context('', &block) if block_given? +    end +  end +end + +RSpec.configure do |config| +  config.extend IntegrationSpecHelper, type: :view +end diff --git a/spec/views/connection_links/show.html.slim_spec.rb b/spec/views/connection_links/show.html.slim_spec.rb new file mode 100644 index 000000000..afe94fc6c --- /dev/null +++ b/spec/views/connection_links/show.html.slim_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe "/connection_links/show", :type => :view do + +  assign_referential +  let!(:connection_link) { assign(:connection_link, create(:connection_link)) } +  let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } + +  before do +    allow(view).to receive_messages(current_organisation: referential.organisation) +  end + +  it "should render h2 with the connection_link name" do +    render +    expect(rendered).to have_selector("h2", :text => Regexp.new(connection_link.name)) +  end + +  with_permission "connection_links.update" do +    it "should render a link to edit the connection_link" do +      render +      expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_connection_link_path(referential, connection_link)}']") +    end +  end + +  with_permission "connection_links.destroy" do +    it "should render a link to remove the connection_link" do +      render +      expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_connection_link_path(referential, connection_link)}'][class='remove']") +    end +  end + +end diff --git a/spec/views/stop_areas/index.html.slim_spec.rb b/spec/views/stop_areas/index.html.slim_spec.rb new file mode 100644 index 000000000..e0c50685c --- /dev/null +++ b/spec/views/stop_areas/index.html.slim_spec.rb @@ -0,0 +1,53 @@ +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) } +    assign :stop_areas, ModelDecorator.decorate( Chouette::StopArea.page(1), with: StopAreaDecorator ) +  end +  let!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) } + +  before :each do +    allow(view).to receive(:link_with_search).and_return("#") +    allow(view).to receive(:collection).and_return(stop_areas) +    allow(view).to receive(:current_referential).and_return(stop_area_referential) +    controller.request.path_parameters[:stop_area_referential_id] = stop_area_referential.id +    render +  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 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 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 | 
