From 011ef41ae18ea42dc8d5a2ba384499a05e6fe754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Tue, 8 Aug 2017 12:33:52 +0200 Subject: [PATCH] Add map location missing specs --- app/assets/stylesheets/admin.scss | 1 - app/helpers/map_locations_helper.rb | 2 +- app/models/map_location.rb | 2 +- spec/factories.rb | 16 ++++++++++++++- spec/models/map_location_spec.rb | 31 +++++++++++++++++++++++++++-- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index c025944f6..b6f237c15 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -982,7 +982,6 @@ table { top: 50%; margin-top: -5px; .map-icon{ - transform: rotate(-45deg); width: 30px; height: 30px; border-radius: 50% 50% 50% 0; diff --git a/app/helpers/map_locations_helper.rb b/app/helpers/map_locations_helper.rb index 8d295b1b6..03823e25c 100644 --- a/app/helpers/map_locations_helper.rb +++ b/app/helpers/map_locations_helper.rb @@ -1,7 +1,7 @@ module MapLocationsHelper def map_location_available?(map_location) - map_location.present? && map_location.filled? + map_location.present? && map_location.available? end def map_location_latitude(map_location) diff --git a/app/models/map_location.rb b/app/models/map_location.rb index 8db4cda9c..6635bf995 100644 --- a/app/models/map_location.rb +++ b/app/models/map_location.rb @@ -3,7 +3,7 @@ class MapLocation < ActiveRecord::Base belongs_to :proposal belongs_to :investment - def filled? + def available? latitude.present? && longitude.present? && zoom.present? end diff --git a/spec/factories.rb b/spec/factories.rb index 160b81664..3fc3d7c36 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -821,7 +821,7 @@ LOREM_IPSUM factory :direct_upload do user - + trait :proposal do resource_type "Proposal" end @@ -840,4 +840,18 @@ LOREM_IPSUM initialize_with { new(attributes) } end + factory :map_location do + latitude 51.48 + longitude 0.0 + zoom 10 + + trait :proposal_map_location do + proposal + end + + trait :investment_map_location do + investment + end + end + end diff --git a/spec/models/map_location_spec.rb b/spec/models/map_location_spec.rb index e0b61f53a..bd093a71e 100644 --- a/spec/models/map_location_spec.rb +++ b/spec/models/map_location_spec.rb @@ -2,8 +2,35 @@ require 'rails_helper' describe MapLocation do - context "#filled?" do - + let(:map_location) { build(:map_location, :proposal_map_location ) } + + it "should be valid" do + expect(map_location).to be_valid + end + + context "#available?" do + + it "should return true when latitude, longitude and zoom defined" do + expect(map_location.available?).to be(true) + end + + it "should return false when longitude is nil" do + map_location.longitude = nil + + expect(map_location.available?).to be(false) + end + + it "should return false when latitude is nil" do + map_location.latitude = nil + + expect(map_location.available?).to be(false) + end + + it "should return false when zoom is nil" do + map_location.zoom = nil + + expect(map_location.available?).to be(false) + end end end