adds specs
This commit is contained in:
@@ -165,6 +165,7 @@ FactoryGirl.define do
|
|||||||
video_url 'https://youtu.be/nhuNb0XtRhQ'
|
video_url 'https://youtu.be/nhuNb0XtRhQ'
|
||||||
responsible_name 'John Snow'
|
responsible_name 'John Snow'
|
||||||
terms_of_service '1'
|
terms_of_service '1'
|
||||||
|
skip_map '1'
|
||||||
association :author, factory: :user
|
association :author, factory: :user
|
||||||
|
|
||||||
trait :hidden do
|
trait :hidden do
|
||||||
@@ -279,6 +280,7 @@ FactoryGirl.define do
|
|||||||
price 10
|
price 10
|
||||||
unfeasibility_explanation ''
|
unfeasibility_explanation ''
|
||||||
external_url 'http://external_documention.org'
|
external_url 'http://external_documention.org'
|
||||||
|
skip_map '1'
|
||||||
terms_of_service '1'
|
terms_of_service '1'
|
||||||
incompatible false
|
incompatible false
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ describe Proposal do
|
|||||||
describe "Concerns" do
|
describe "Concerns" do
|
||||||
it_behaves_like "has_public_author"
|
it_behaves_like "has_public_author"
|
||||||
it_behaves_like "notifiable"
|
it_behaves_like "notifiable"
|
||||||
|
it_behaves_like "map validations"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should be valid" do
|
it "should be valid" do
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
|
|||||||
|
|
||||||
send("fill_in_#{mappable_factory_name}_form")
|
send("fill_in_#{mappable_factory_name}_form")
|
||||||
expect(page).to have_css ".map_location"
|
expect(page).to have_css ".map_location"
|
||||||
|
check "#{mappable_factory_name}_skip_map"
|
||||||
send("submit_#{mappable_factory_name}_form")
|
send("submit_#{mappable_factory_name}_form")
|
||||||
|
|
||||||
expect(page).not_to have_css(".map_location")
|
expect(page).not_to have_css(".map_location")
|
||||||
@@ -73,6 +74,41 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
|
|||||||
expect(page).not_to have_css(".map_location")
|
expect(page).not_to have_css(".map_location")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Errors on create' do
|
||||||
|
login_as user
|
||||||
|
visit send(mappable_new_path, arguments)
|
||||||
|
|
||||||
|
send("submit_#{mappable_factory_name}_form")
|
||||||
|
|
||||||
|
expect(page).to have_content "Map location can't be blank"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Skip map', :js do
|
||||||
|
login_as user
|
||||||
|
visit send(mappable_new_path, arguments)
|
||||||
|
|
||||||
|
send("fill_in_#{mappable_factory_name}_form")
|
||||||
|
check "#{mappable_factory_name}_skip_map"
|
||||||
|
send("submit_#{mappable_factory_name}_form")
|
||||||
|
|
||||||
|
expect(page).to_not have_content "Map location can't be blank"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Toggle map', :js do
|
||||||
|
login_as user
|
||||||
|
visit send(mappable_new_path, arguments)
|
||||||
|
|
||||||
|
check "#{mappable_factory_name}_skip_map"
|
||||||
|
|
||||||
|
expect(page).to_not have_css(".map")
|
||||||
|
expect(page).to_not have_content("Remove map marker")
|
||||||
|
|
||||||
|
uncheck "#{mappable_factory_name}_skip_map"
|
||||||
|
|
||||||
|
expect(page).to have_css(".map")
|
||||||
|
expect(page).to have_content("Remove map marker")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "At #{mappable_edit_path}" do
|
describe "At #{mappable_edit_path}" do
|
||||||
@@ -122,6 +158,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
|
|||||||
|
|
||||||
visit send(mappable_edit_path, id: mappable.id)
|
visit send(mappable_edit_path, id: mappable.id)
|
||||||
click_link "Remove map marker"
|
click_link "Remove map marker"
|
||||||
|
check "#{mappable_factory_name}_skip_map"
|
||||||
click_on "Save changes"
|
click_on "Save changes"
|
||||||
|
|
||||||
expect(page).not_to have_css(".map_location")
|
expect(page).not_to have_css(".map_location")
|
||||||
@@ -138,6 +175,27 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
|
|||||||
expect(page).not_to have_css(".map_location")
|
expect(page).not_to have_css(".map_location")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scenario 'Errors on update', :js do
|
||||||
|
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"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario '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"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "At #{mappable_show_path}" do
|
describe "At #{mappable_show_path}" do
|
||||||
@@ -189,8 +247,11 @@ def submit_proposal_form
|
|||||||
check :proposal_terms_of_service
|
check :proposal_terms_of_service
|
||||||
click_button 'Create proposal'
|
click_button 'Create proposal'
|
||||||
|
|
||||||
|
if page.has_content?('Not now, go to my proposal')
|
||||||
click_link 'Not now, go to my proposal'
|
click_link 'Not now, go to my proposal'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def validate_latitude_longitude(mappable_factory_name)
|
def validate_latitude_longitude(mappable_factory_name)
|
||||||
expect(find("##{mappable_factory_name}_map_location_attributes_latitude", visible: false).value).to eq "51.48"
|
expect(find("##{mappable_factory_name}_map_location_attributes_latitude", visible: false).value).to eq "51.48"
|
||||||
|
|||||||
53
spec/shared/models/map_validations.rb
Normal file
53
spec/shared/models/map_validations.rb
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
shared_examples "map validations" do
|
||||||
|
|
||||||
|
let(:mappable) { build(model_name(described_class)) }
|
||||||
|
|
||||||
|
describe "map" do
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
Setting["feature.map"] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
after(:each) do
|
||||||
|
Setting["feature.map"] = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be valid with a map location" do
|
||||||
|
mappable.map_location = build(:map_location)
|
||||||
|
mappable.skip_map = nil
|
||||||
|
|
||||||
|
expect(mappable).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be valid accepting that the mappable has no map" do
|
||||||
|
mappable.skip_map = "1"
|
||||||
|
mappable.map_location = nil
|
||||||
|
|
||||||
|
expect(mappable).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should be valid when the feature map is deactivated" do
|
||||||
|
Setting["feature.map"] = nil
|
||||||
|
|
||||||
|
mappable.map_location = nil
|
||||||
|
mappable.skip_map = nil
|
||||||
|
|
||||||
|
expect(mappable).to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not be valid without a map location" do
|
||||||
|
mappable.map_location = nil
|
||||||
|
mappable.skip_map = nil
|
||||||
|
|
||||||
|
expect(mappable).to_not be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not be valid without accepting that the mappable has no map" do
|
||||||
|
mappable.skip_map = nil
|
||||||
|
|
||||||
|
expect(mappable).to_not be_valid
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user