aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorAlban Peignier2017-12-21 21:40:47 +0100
committerGitHub2017-12-21 21:40:47 +0100
commit09f335237d39e9cce1d4051355d16f2781806cbd (patch)
tree64b18197dff4d6707be10bfccca9240c601ffded /spec
parent01b2d2b785d99c9b031269fc741b70ee9c248f16 (diff)
parente8285678efc9a62115fe0af4086c7a3959666bf8 (diff)
downloadchouette-core-09f335237d39e9cce1d4051355d16f2781806cbd.tar.bz2
Merge pull request #169 from af83/5349-deactivate-stop-areas
Deactivate StopAreas. Refs #5349
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/stop_areas_controller_spec.rb38
-rw-r--r--spec/factories/chouette_stop_areas.rb4
-rw-r--r--spec/views/stop_areas/index.html.slim_spec.rb54
3 files changed, 90 insertions, 6 deletions
diff --git a/spec/controllers/stop_areas_controller_spec.rb b/spec/controllers/stop_areas_controller_spec.rb
new file mode 100644
index 000000000..2b5f8c3e2
--- /dev/null
+++ b/spec/controllers/stop_areas_controller_spec.rb
@@ -0,0 +1,38 @@
+RSpec.describe StopAreasController, :type => :controller do
+ login_user
+
+ let(:stop_area_referential) { create :stop_area_referential }
+ let(:stop_area) { create :stop_area, stop_area_referential: stop_area_referential }
+
+ describe 'PUT deactivate' do
+ let(:request){ put :deactivate, id: stop_area.id, stop_area_referential_id: stop_area_referential.id }
+
+ it 'should redirect to 403' do
+ expect(request).to redirect_to "/403"
+ end
+
+ with_permission "stop_areas.change_status" do
+ it 'returns HTTP success' do
+ expect(request).to redirect_to [stop_area_referential, stop_area]
+ expect(stop_area.reload).to be_deactivated
+ end
+ end
+ end
+
+ describe 'PUT activate' do
+ let(:request){ put :activate, id: stop_area.id, stop_area_referential_id: stop_area_referential.id }
+ before(:each){
+ stop_area.deactivate!
+ }
+ it 'should redirect to 403' do
+ expect(request).to redirect_to "/403"
+ end
+
+ with_permission "stop_areas.change_status" do
+ it 'returns HTTP success' do
+ expect(request).to redirect_to [stop_area_referential, stop_area]
+ expect(stop_area.reload).to be_activated
+ end
+ end
+ end
+end
diff --git a/spec/factories/chouette_stop_areas.rb b/spec/factories/chouette_stop_areas.rb
index 7f937e361..94517f856 100644
--- a/spec/factories/chouette_stop_areas.rb
+++ b/spec/factories/chouette_stop_areas.rb
@@ -8,5 +8,9 @@ FactoryGirl.define do
longitude {10.0 * rand}
association :stop_area_referential
+
+ trait :deactivated do
+ deleted_at { 1.hour.ago }
+ 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
index 8daa5eb4b..520cecc1a 100644
--- a/spec/views/stop_areas/index.html.slim_spec.rb
+++ b/spec/views/stop_areas/index.html.slim_spec.rb
@@ -1,14 +1,15 @@
require 'spec_helper'
describe "/stop_areas/index", :type => :view do
-
- let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) }
- let!(:stop_areas) do
+ let(:deactivated_stop_area){ nil }
+ let(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) }
+ let(:stop_areas) do
assign :stop_areas, build_paginated_collection(:stop_area, StopAreaDecorator, stop_area_referential: stop_area_referential)
end
let!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) }
before :each do
+ deactivated_stop_area
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)
@@ -16,19 +17,60 @@ describe "/stop_areas/index", :type => :view do
render
end
- it { should have_link_for_each_item(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) }
+ common_items = ->{
+ it { should have_link_for_each_item(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) }
+ }
+
+ common_items.call()
it { should have_the_right_number_of_links(stop_areas, 1) }
with_permission "stop_areas.create" do
- it { should have_link_for_each_item(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) }
+ common_items.call()
it { should_not have_link_for_each_item(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, 1) }
end
with_permission "stop_areas.update" do
- it { should have_link_for_each_item(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) }
+ common_items.call()
it { should have_link_for_each_item(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
+ with_permission "stop_areas.change_status" do
+ common_items.call()
+ it { should have_link_for_each_item(stop_areas, "deactivate", -> (stop_area){ view.deactivate_stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) }
+ it { should have_the_right_number_of_links(stop_areas, 2) }
+ end
+
+ with_permission "stop_areas.destroy" do
+ common_items.call()
+ it {
+ should have_link_for_each_item(stop_areas, "destroy", {
+ href: ->(stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)},
+ method: :delete
+ })
+ }
+ it { should have_the_right_number_of_links(stop_areas, 2) }
+ end
+
+ context "with a deactivated item" do
+ with_permission "stop_areas.change_status" do
+ let(:deactivated_stop_area){ create :stop_area, :deactivated, stop_area_referential: stop_area_referential }
+
+ common_items.call()
+ it "should display an activate link for the deactivated one" do
+ stop_areas.each do |stop_area|
+ if stop_area == deactivated_stop_area
+ href = view.activate_stop_area_referential_stop_area_path(stop_area_referential, stop_area)
+ else
+ href = view.deactivate_stop_area_referential_stop_area_path(stop_area_referential, stop_area)
+ end
+ selector = "tr.#{TableBuilderHelper.item_row_class_name(stop_areas)}-#{stop_area.id} .actions a[href='#{href}']"
+ expect(rendered).to have_selector(selector, count: 1)
+ end
+ end
+ it { should have_the_right_number_of_links(stop_areas, 2) }
+ end
+ end
+
end