diff --git a/app/controllers/cities_controller.rb b/app/controllers/cities_controller.rb index 9bf9e62f..863f301c 100644 --- a/app/controllers/cities_controller.rb +++ b/app/controllers/cities_controller.rb @@ -50,7 +50,7 @@ def create # PATCH/PUT /cities/1.json def update if params[:approval_action] - approver = CityApprover.new(@city) + approver = CityApprover.new(@city.id) case params[:approval_action] when "merge" approver.merge!(params[:merge_city_id]) diff --git a/app/services/city_approver.rb b/app/services/city_approver.rb index 73d4478e..34e7e426 100644 --- a/app/services/city_approver.rb +++ b/app/services/city_approver.rb @@ -25,7 +25,7 @@ def merge!(existing_city_id) existing = City.find(existing_city_id) approval_gate do User.where(home_city: @city.id).update_all(home_city_id: existing.id) - self.reject!(false) + self.reject!(mail_user: false) UserMailer.delay.notify_city_suggestor(@city, :merged) end end diff --git a/spec/controllers/cities_controller_spec.rb b/spec/controllers/cities_controller_spec.rb new file mode 100644 index 00000000..0e342db3 --- /dev/null +++ b/spec/controllers/cities_controller_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe CitiesController do + before do + [:away_ye_waitlisted, :authenticate_user!, :authorized?].each do |s| + allow(controller).to receive(s).and_return true + end + end + + describe '#update' do + let(:unapproved_city) { + city = create(:city, :unapproved) + (1..10).each { |i| create(:user, home_city: city) } + city + } + + let(:merge_request) { + { + id: unapproved_city.city_code, + city: {id: unapproved_city.id}, + merge_city_id: create(:city).id, + approval_action: "merge" + } + } + + it 'should move all users from City A to City B upon merge' do + city_a = unapproved_city + city_a_users = city_a.users + city_b_id = merge_request[:merge_city_id] + + patch :update, merge_request + expect(response).to redirect_to(city_path(city_a)) + expect(city_a_users.map { + |u| u.reload.home_city_id == city_b_id + }.all?).to eq(true) + end + end +end