Validates map presence only on create

As we are using an attr_accessor to make sure a user accepts that the
proposal “has no map”, the validation was being run in every save.

Making other things break, for example the updating of the counter
cache `cached_votes_up`, when someone voted for the proposal, as the
attr_accessor `skip_map` was not present
This commit is contained in:
rgarcia
2017-12-26 12:39:29 +01:00
parent f6d23df862
commit 96066aee44
2 changed files with 5 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ module Mappable
has_one :map_location, dependent: :destroy
accepts_nested_attributes_for :map_location, allow_destroy: true
validate :map_must_be_valid, if: :feature_maps?
validate :map_must_be_valid, on: :create, if: :feature_maps?
def map_must_be_valid
return true if skip_map?

View File

@@ -175,22 +175,22 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
expect(page).not_to have_css(".map_location")
end
scenario 'Errors on update', :js do
scenario 'No errors on update', :js do
skip ""
login_as mappable.author
visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker"
click_on "Save changes"
expect(page).to have_content "Map location can't be blank"
expect(page).to_not have_content "Map location can't be blank"
end
scenario 'Skip map on update' do
scenario 'No need to skip map on update' do
login_as mappable.author
visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker"
check "#{mappable_factory_name}_skip_map"
click_on "Save changes"
expect(page).to_not have_content "Map location can't be blank"