adds specs

This commit is contained in:
rgarcia
2017-12-19 20:36:10 +01:00
parent e58ff785cd
commit 0152b6301c
4 changed files with 118 additions and 1 deletions

View File

@@ -165,6 +165,7 @@ FactoryGirl.define do
video_url 'https://youtu.be/nhuNb0XtRhQ'
responsible_name 'John Snow'
terms_of_service '1'
skip_map '1'
association :author, factory: :user
trait :hidden do
@@ -279,6 +280,7 @@ FactoryGirl.define do
price 10
unfeasibility_explanation ''
external_url 'http://external_documention.org'
skip_map '1'
terms_of_service '1'
incompatible false

View File

@@ -7,6 +7,7 @@ describe Proposal do
describe "Concerns" do
it_behaves_like "has_public_author"
it_behaves_like "notifiable"
it_behaves_like "map validations"
end
it "should be valid" do

View File

@@ -56,6 +56,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
send("fill_in_#{mappable_factory_name}_form")
expect(page).to have_css ".map_location"
check "#{mappable_factory_name}_skip_map"
send("submit_#{mappable_factory_name}_form")
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")
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
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)
click_link "Remove map marker"
check "#{mappable_factory_name}_skip_map"
click_on "Save changes"
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")
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
describe "At #{mappable_show_path}" do
@@ -189,9 +247,12 @@ def submit_proposal_form
check :proposal_terms_of_service
click_button 'Create proposal'
click_link 'Not now, go to my proposal'
if page.has_content?('Not now, go to my proposal')
click_link 'Not now, go to my proposal'
end
end
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_longitude", visible: false).value).to eq "0.0"

View 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