Use render_map to render the admin settings map
This way we remove duplication.
Note that to check whether to render the button to remove a marker,
we're checking whether the map location belongs to a mappable. This
means we're changing the code that renders the map in the "new proposal"
and "new investment" forms so the map location belongs to a proposal or
investment. We're association the map location to a new record because
writing something like:
```
def map_location
proposal.map_location || MapLocation.new(proposal: proposal)
end
```
Would change the `proposal` object because of the way Rails treats
non-persisted `has_one` associations. Although probably safe in this
case, changing an object when rendering a view could have side effects.
Also note that we're changing the HTML ID of the map element from
`admin-map` to `new_map_location` (the latter is returned by the
`dom_id` method). We were only using this ID in tests since commit
289426c1c, so changing it doesn't really affect us.
This commit is contained in:
@@ -26,11 +26,11 @@ describe "Admin settings", :admin do
|
||||
|
||||
visit admin_settings_path
|
||||
|
||||
expect(page).not_to have_css "#admin-map.leaflet-container", visible: :all
|
||||
expect(page).not_to have_css ".map-location.leaflet-container", visible: :all
|
||||
|
||||
click_link "Map configuration"
|
||||
|
||||
expect(page).to have_css "#admin-map.leaflet-container"
|
||||
expect(page).to have_css ".map-location.leaflet-container"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@ describe "Admin settings", :admin do
|
||||
expect(page).to have_content "To show the map to users you must enable " \
|
||||
'"Proposals and budget investments geolocation" ' \
|
||||
'on "Features" tab.'
|
||||
expect(page).not_to have_css("#admin-map")
|
||||
expect(page).not_to have_css ".map-location"
|
||||
end
|
||||
|
||||
scenario "Should update marker" do
|
||||
@@ -53,7 +53,7 @@ describe "Admin settings", :admin do
|
||||
visit admin_settings_path
|
||||
click_link "Map configuration"
|
||||
|
||||
expect(page).to have_css("#admin-map")
|
||||
expect(page).to have_css ".map-location"
|
||||
expect(page).not_to have_content "To show the map to users you must enable " \
|
||||
'"Proposals and budget investments geolocation" ' \
|
||||
'on "Features" tab.'
|
||||
@@ -62,7 +62,7 @@ describe "Admin settings", :admin do
|
||||
expect(page).to have_field "Longitude", with: "0.0"
|
||||
|
||||
within "#map-form" do
|
||||
find("#admin-map").click
|
||||
find(".map-location").click
|
||||
click_button "Update"
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user