Add missing specs from Maps on New, Edit and Show.
This commit is contained in:
committed by
Senén Rodero Rodríguez
parent
7b54451491
commit
51c53b6f31
@@ -37,6 +37,7 @@ module MapLocationsHelper
|
|||||||
content_tag :div, class: "text-right" do
|
content_tag :div, class: "text-right" do
|
||||||
content_tag :a,
|
content_tag :a,
|
||||||
id: map_location_remove_marker_link_id(map_location),
|
id: map_location_remove_marker_link_id(map_location),
|
||||||
|
href: "#",
|
||||||
class: "location-map-remove-marker-button delete" do
|
class: "location-map-remove-marker-button delete" do
|
||||||
text
|
text
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class MapLocation < ActiveRecord::Base
|
class MapLocation < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :proposal
|
belongs_to :proposal
|
||||||
belongs_to :investment
|
belongs_to :investment, class_name: Budget::Investment
|
||||||
|
|
||||||
def available?
|
def available?
|
||||||
latitude.present? && longitude.present? && zoom.present?
|
latitude.present? && longitude.present? && zoom.present?
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
<%= render_map(map_location, parent_class, editable = true, remove_marker_label) %>
|
<%= render_map(map_location, parent_class, editable = true, remove_marker_label) %>
|
||||||
|
|
||||||
<%= form.fields_for :map_location, map_location do |m_l_fields| %>
|
<%= form.fields_for :map_location, map_location do |m_l_fields| %>
|
||||||
|
<%= m_l_fields.hidden_field :id,
|
||||||
|
value: map_location.id,
|
||||||
|
id: map_location_input_id(parent_class, 'id') %>
|
||||||
<%= m_l_fields.hidden_field :latitude,
|
<%= m_l_fields.hidden_field :latitude,
|
||||||
value: map_location.latitude,
|
value: map_location.latitude,
|
||||||
id: map_location_input_id(parent_class, 'latitude') %>
|
id: map_location_input_id(parent_class, 'latitude') %>
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ Setting['feature.budgets'] = true
|
|||||||
Setting['feature.signature_sheets'] = true
|
Setting['feature.signature_sheets'] = true
|
||||||
Setting['feature.legislation'] = true
|
Setting['feature.legislation'] = true
|
||||||
Setting['feature.community'] = true
|
Setting['feature.community'] = true
|
||||||
Setting['feature.map'] = true
|
Setting['feature.map'] = nil
|
||||||
|
|
||||||
# Spending proposals feature flags
|
# Spending proposals feature flags
|
||||||
Setting['feature.spending_proposal_features.voting_allowed'] = nil
|
Setting['feature.spending_proposal_features.voting_allowed'] = nil
|
||||||
|
|||||||
@@ -849,8 +849,8 @@ LOREM_IPSUM
|
|||||||
proposal
|
proposal
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :investment_map_location do
|
trait :budget_investment_map_location do
|
||||||
investment
|
association :investment, factory: :budget_investment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -485,6 +485,14 @@ feature 'Budget Investments' do
|
|||||||
"Create Investment",
|
"Create Investment",
|
||||||
"Budget Investment created successfully."
|
"Budget Investment created successfully."
|
||||||
|
|
||||||
|
it_behaves_like "mapeable",
|
||||||
|
"budget_investment",
|
||||||
|
"investment",
|
||||||
|
"new_budget_investment_path",
|
||||||
|
"",
|
||||||
|
"budget_investment_path",
|
||||||
|
{ "budget_id": "budget_id" }
|
||||||
|
|
||||||
context "Destroy" do
|
context "Destroy" do
|
||||||
|
|
||||||
scenario "Admin cannot destroy budget investments" do
|
scenario "Admin cannot destroy budget investments" do
|
||||||
|
|||||||
@@ -1328,6 +1328,14 @@ feature 'Proposals' do
|
|||||||
"Save changes",
|
"Save changes",
|
||||||
"Proposal updated successfully"
|
"Proposal updated successfully"
|
||||||
|
|
||||||
|
it_behaves_like "mapeable",
|
||||||
|
"proposal",
|
||||||
|
"proposal",
|
||||||
|
"new_proposal_path",
|
||||||
|
"edit_proposal_path",
|
||||||
|
"proposal_path",
|
||||||
|
{ }
|
||||||
|
|
||||||
scenario 'Erased author' do
|
scenario 'Erased author' do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
proposal = create(:proposal, author: user)
|
proposal = create(:proposal, author: user)
|
||||||
@@ -1533,6 +1541,37 @@ feature 'Proposals' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Add Map on proposal' do
|
||||||
|
author = create(:user)
|
||||||
|
login_as(author)
|
||||||
|
|
||||||
|
visit new_proposal_path
|
||||||
|
fill_in 'proposal_title', with: 'Help refugees'
|
||||||
|
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
|
||||||
|
fill_in 'proposal_summary', with: 'In summary, what we want is...'
|
||||||
|
check 'proposal_terms_of_service'
|
||||||
|
|
||||||
|
click_button 'Create proposal'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Proposal created successfully.'
|
||||||
|
expect(page).to have_content 'Help refugees'
|
||||||
|
expect(page).not_to have_content 'You can also see more information about improving your campaign'
|
||||||
|
|
||||||
|
click_link 'Not now, go to my proposal'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Help refugees'
|
||||||
|
expect(page).to have_content '¿Would you like to give assistance to war refugees?'
|
||||||
|
expect(page).to have_content 'In summary, what we want is...'
|
||||||
|
expect(page).to have_content 'This is very important because...'
|
||||||
|
expect(page).to have_content 'http://rescue.org/refugees'
|
||||||
|
expect(page).to have_content 'http://youtube.com'
|
||||||
|
expect(page).to have_content author.name
|
||||||
|
expect(page).to have_content 'Refugees'
|
||||||
|
expect(page).to have_content 'Solidarity'
|
||||||
|
expect(page).to have_content I18n.l(Proposal.last.created_at.to_date)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
feature 'Successful proposals' do
|
feature 'Successful proposals' do
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path,
|
|||||||
let!(:user) { create(:user) }
|
let!(:user) { create(:user) }
|
||||||
let!(:arguments) { {} }
|
let!(:arguments) { {} }
|
||||||
let!(:documentable) { create(documentable_factory_name, author: user) }
|
let!(:documentable) { create(documentable_factory_name, author: user) }
|
||||||
let!(:documentable_dom_name) { documentable_factory_name.parameterize }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create(:administrator, user: administrator)
|
create(:administrator, user: administrator)
|
||||||
|
|||||||
220
spec/shared/features/mapeable.rb
Normal file
220
spec/shared/features/mapeable.rb
Normal file
@@ -0,0 +1,220 @@
|
|||||||
|
shared_examples "mapeable" do |mapeable_factory_name, mapeable_association_name, mapeable_new_path, mapeable_edit_path, mapeable_show_path, mapeable_path_arguments|
|
||||||
|
|
||||||
|
include ActionView::Helpers
|
||||||
|
|
||||||
|
let!(:user) { create(:user, :level_two) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Setting['feature.map'] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "At #{mapeable_new_path}" do
|
||||||
|
|
||||||
|
let!(:arguments) { {} }
|
||||||
|
let!(:mapeable) { create("#{mapeable_factory_name}".to_sym) }
|
||||||
|
let!(:map_location) { create(:map_location, "#{mapeable_factory_name}_map_location".to_sym, "#{mapeable_association_name}": mapeable) }
|
||||||
|
|
||||||
|
before { set_arguments(arguments, mapeable, mapeable_path_arguments) }
|
||||||
|
|
||||||
|
scenario "Should not show marker by default on create #{mapeable_factory_name}", :js do
|
||||||
|
login_as user
|
||||||
|
visit send(mapeable_new_path, arguments)
|
||||||
|
|
||||||
|
send("fill_in_#{mapeable_factory_name}_form")
|
||||||
|
|
||||||
|
within ".map_location" do
|
||||||
|
expect(page).not_to have_css(".map-icon")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should show marker on create #{mapeable_factory_name} when click on map", :js do
|
||||||
|
login_as user
|
||||||
|
visit send(mapeable_new_path, arguments)
|
||||||
|
|
||||||
|
send("fill_in_#{mapeable_factory_name}_form")
|
||||||
|
find("#new_map_location").click
|
||||||
|
|
||||||
|
within ".map_location" do
|
||||||
|
expect(page).to have_css(".map-icon")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should create #{mapeable_factory_name} with map", :js do
|
||||||
|
login_as user
|
||||||
|
visit send(mapeable_new_path, arguments)
|
||||||
|
|
||||||
|
send("fill_in_#{mapeable_factory_name}_form")
|
||||||
|
find("#new_map_location").click
|
||||||
|
send("submit_#{mapeable_factory_name}_form")
|
||||||
|
|
||||||
|
expect(page).to have_css(".map_location")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Can not display map on #{mapeable_factory_name} when not fill marker on map", :js do
|
||||||
|
login_as user
|
||||||
|
visit send(mapeable_new_path, arguments)
|
||||||
|
|
||||||
|
send("fill_in_#{mapeable_factory_name}_form")
|
||||||
|
expect(page).to have_css ".map_location"
|
||||||
|
send("submit_#{mapeable_factory_name}_form")
|
||||||
|
|
||||||
|
expect(page).not_to have_css(".map_location")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Can not display map on #{mapeable_factory_name} when feature.map is disabled", :js do
|
||||||
|
Setting['feature.map'] = false
|
||||||
|
login_as user
|
||||||
|
visit send(mapeable_new_path, arguments)
|
||||||
|
|
||||||
|
send("fill_in_#{mapeable_factory_name}_form")
|
||||||
|
expect(page).not_to have_css ".map_location"
|
||||||
|
send("submit_#{mapeable_factory_name}_form")
|
||||||
|
|
||||||
|
expect(page).not_to have_css(".map_location")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "At #{mapeable_edit_path}" do
|
||||||
|
|
||||||
|
let!(:mapeable) { create("#{mapeable_factory_name}".to_sym) }
|
||||||
|
let!(:map_location) { create(:map_location, "#{mapeable_factory_name}_map_location".to_sym, "#{mapeable_association_name}": mapeable) }
|
||||||
|
|
||||||
|
before { skip } unless mapeable_edit_path.present?
|
||||||
|
|
||||||
|
scenario "Should edit map on #{mapeable_factory_name} and contain default values", :js do
|
||||||
|
login_as mapeable.author
|
||||||
|
|
||||||
|
visit send(mapeable_edit_path, id: mapeable.id)
|
||||||
|
|
||||||
|
expect(page).to have_content "Navigate the map to the location and place the marker."
|
||||||
|
validate_latitude_longitude(mapeable_factory_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should edit default values from map on #{mapeable_factory_name} edit page", :js do
|
||||||
|
login_as mapeable.author
|
||||||
|
|
||||||
|
visit send(mapeable_edit_path, id: mapeable.id)
|
||||||
|
find(".map_location").click
|
||||||
|
click_on("Save changes")
|
||||||
|
mapeable.reload
|
||||||
|
|
||||||
|
expect(page).to have_css(".map_location")
|
||||||
|
expect(page).not_to have_selector(".map_location[data-marker-latitude='#{map_location.latitude}']")
|
||||||
|
expect(page).to have_selector(".map_location[data-marker-latitude='#{mapeable.map_location.latitude}']")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should edit mapeable on #{mapeable_factory_name} without change map", :js do
|
||||||
|
login_as mapeable.author
|
||||||
|
|
||||||
|
visit send(mapeable_edit_path, id: mapeable.id)
|
||||||
|
fill_in "#{mapeable_factory_name}_title", with: "New title"
|
||||||
|
click_on("Save changes")
|
||||||
|
mapeable.reload
|
||||||
|
|
||||||
|
expect(page).to have_css(".map_location")
|
||||||
|
expect(page).to have_selector(".map_location[data-marker-latitude='#{map_location.latitude}']")
|
||||||
|
expect(page).to have_selector(".map_location[data-marker-latitude='#{mapeable.map_location.latitude}']")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Can not display map on #{mapeable_factory_name} edit when remove map marker", :js do
|
||||||
|
login_as mapeable.author
|
||||||
|
|
||||||
|
visit send(mapeable_edit_path, id: mapeable.id)
|
||||||
|
click_link "Remove map marker"
|
||||||
|
click_on "Save changes"
|
||||||
|
|
||||||
|
expect(page).not_to have_css(".map_location")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Can not display map on #{mapeable_factory_name} edit when feature.map is disabled", :js do
|
||||||
|
Setting['feature.map'] = false
|
||||||
|
login_as mapeable.author
|
||||||
|
|
||||||
|
visit send(mapeable_edit_path, id: mapeable.id)
|
||||||
|
fill_in "#{mapeable_factory_name}_title", with: "New title"
|
||||||
|
click_on("Save changes")
|
||||||
|
|
||||||
|
expect(page).not_to have_css(".map_location")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "At #{mapeable_show_path}" do
|
||||||
|
|
||||||
|
let!(:arguments) { {} }
|
||||||
|
let!(:mapeable) { create("#{mapeable_factory_name}".to_sym) }
|
||||||
|
let!(:map_location) { create(:map_location, "#{mapeable_factory_name}_map_location".to_sym, "#{mapeable_association_name}": mapeable) }
|
||||||
|
|
||||||
|
before { set_arguments(arguments, mapeable, mapeable_path_arguments) }
|
||||||
|
|
||||||
|
scenario "Should display map on #{mapeable_factory_name} show page", :js do
|
||||||
|
arguments.merge!("id": mapeable.id)
|
||||||
|
|
||||||
|
visit send(mapeable_show_path, arguments)
|
||||||
|
|
||||||
|
expect(page).to have_css(".map_location")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should not display map on #{mapeable_factory_name} show when marker is not defined", :js do
|
||||||
|
mapeable_without_map = create("#{mapeable_factory_name}".to_sym)
|
||||||
|
set_arguments(arguments, mapeable_without_map, mapeable_path_arguments)
|
||||||
|
arguments.merge!("id": mapeable_without_map.id)
|
||||||
|
|
||||||
|
visit send(mapeable_show_path, arguments)
|
||||||
|
|
||||||
|
expect(page).not_to have_css(".map_location")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Should not display map on #{mapeable_factory_name} show page when feature.map is disable", :js do
|
||||||
|
Setting['feature.map'] = false
|
||||||
|
arguments.merge!("id": mapeable.id)
|
||||||
|
|
||||||
|
visit send(mapeable_show_path, arguments)
|
||||||
|
|
||||||
|
expect(page).not_to have_css(".map_location")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def fill_in_proposal_form
|
||||||
|
fill_in 'proposal_title', with: 'Help refugees'
|
||||||
|
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'
|
||||||
|
fill_in 'proposal_summary', with: 'In summary, what we want is...'
|
||||||
|
end
|
||||||
|
|
||||||
|
def submit_proposal_form
|
||||||
|
check :proposal_terms_of_service
|
||||||
|
click_button 'Create proposal'
|
||||||
|
|
||||||
|
click_link 'Not now, go to my proposal'
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_latitude_longitude(mapeable_factory_name)
|
||||||
|
expect(find("##{mapeable_factory_name}_map_location_attributes_latitude", visible: false).value).to eq "51.48"
|
||||||
|
expect(find("##{mapeable_factory_name}_map_location_attributes_longitude", visible: false).value).to eq "0.0"
|
||||||
|
expect(mapeable.map_location.latitude).to eq 51.48
|
||||||
|
expect(mapeable.map_location.longitude).to eq 0.0
|
||||||
|
end
|
||||||
|
|
||||||
|
def fill_in_budget_investment_form
|
||||||
|
page.select mapeable.heading.name_scoped_by_group, from: :budget_investment_heading_id
|
||||||
|
fill_in :budget_investment_title, with: "Budget investment title"
|
||||||
|
fill_in_ckeditor "budget_investment_description", with: "Budget investment description"
|
||||||
|
check :budget_investment_terms_of_service
|
||||||
|
end
|
||||||
|
|
||||||
|
def submit_budget_investment_form
|
||||||
|
check :budget_investment_terms_of_service
|
||||||
|
click_button 'Create Investment'
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_arguments(arguments, mapeable, mapeable_path_arguments)
|
||||||
|
if mapeable_path_arguments
|
||||||
|
mapeable_path_arguments.each do |argument_name, path_to_value|
|
||||||
|
arguments.merge!("#{argument_name}": mapeable.send(path_to_value))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user