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:
@@ -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?
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user