diff --git a/app/controllers/carto/api/map_presenter.rb b/app/controllers/carto/api/map_presenter.rb index 88a7c3c9e9..50f46a2f33 100644 --- a/app/controllers/carto/api/map_presenter.rb +++ b/app/controllers/carto/api/map_presenter.rb @@ -12,7 +12,7 @@ module Carto bounding_box_ne: @map.bounding_box_ne, bounding_box_sw: @map.bounding_box_sw, center: @map.center, - embed_options: @map.embed_options, + options: @map.options, id: @map.id, provider: @map.provider, user_id: @map.user_id, diff --git a/app/controllers/carto/api/maps_controller.rb b/app/controllers/carto/api/maps_controller.rb index 40ccd386bb..e1b1e07394 100644 --- a/app/controllers/carto/api/maps_controller.rb +++ b/app/controllers/carto/api/maps_controller.rb @@ -43,7 +43,7 @@ module Carto params.slice(:bounding_box_ne, :bounding_box_sw, :center, - :embed_options, + :options, :provider, :view_bounds_ne, :view_bounds_sw, diff --git a/app/controllers/carto/api/vizjson3_presenter.rb b/app/controllers/carto/api/vizjson3_presenter.rb index abdf2e3d63..49cad7633e 100644 --- a/app/controllers/carto/api/vizjson3_presenter.rb +++ b/app/controllers/carto/api/vizjson3_presenter.rb @@ -82,7 +82,7 @@ module Carto center: map.center, datasource: datasource_vizjson(options, forced_privacy_version), description: html_safe(@visualization.description), - embed_options: map.embed_options, + options: map.options, id: @visualization.id, layers: layers_vizjson(forced_privacy_version), likes: @visualization.likes.count, diff --git a/app/models/carto/map.rb b/app/models/carto/map.rb index 5d8f4cfa3a..02218f98b5 100644 --- a/app/models/carto/map.rb +++ b/app/models/carto/map.rb @@ -28,12 +28,12 @@ class Carto::Map < ActiveRecord::Base center: [30, 0] }.freeze - serialize :embed_options, ::Carto::CartoJsonSerializer - validates :embed_options, carto_json_symbolizer: true + serialize :options, ::Carto::CartoJsonSerializer + validates :options, carto_json_symbolizer: true - validate :validate_embed_options + validate :validate_options - after_initialize :ensure_embed_options + after_initialize :ensure_options after_commit :force_notify_map_change def data_layers @@ -132,25 +132,25 @@ class Carto::Map < ActiveRecord::Base end def dashboard_menu=(value) - embed_options[:dashboard_menu] = value + options[:dashboard_menu] = value end def dashboard_menu - embed_options[:dashboard_menu] + options[:dashboard_menu] end def layer_selector=(value) - embed_options[:layer_selector] = value + options[:layer_selector] = value end def layer_selector - embed_options[:layer_selector] + options[:layer_selector] end private - def ensure_embed_options - self.embed_options ||= { + def ensure_options + self.options ||= { dashboard_menu: true, layer_selector: true, legends: legends, @@ -158,13 +158,13 @@ class Carto::Map < ActiveRecord::Base } end - def validate_embed_options - location = "#{Rails.root}/lib/formats/map/embed_options.json" + def validate_options + location = "#{Rails.root}/lib/formats/map/options.json" schema = Carto::Definition.instance.load_from_file(location) - embed_options_wia = embed_options.with_indifferent_access - json_errors = JSON::Validator.fully_validate(schema, embed_options_wia) - errors.add(:embed_options, json_errors.join(', ')) if json_errors.any? + options_wia = options.with_indifferent_access + json_errors = JSON::Validator.fully_validate(schema, options_wia) + errors.add(:options, json_errors.join(', ')) if json_errors.any? end def get_the_last_time_tiles_have_changed_to_render_it_in_vizjsons diff --git a/db/migrate/20160928095559_add_embed_options_to_map.rb b/db/migrate/20160928095559_add_options_to_map.rb similarity index 72% rename from db/migrate/20160928095559_add_embed_options_to_map.rb rename to db/migrate/20160928095559_add_options_to_map.rb index 42013c89ab..0769de8d7c 100644 --- a/db/migrate/20160928095559_add_embed_options_to_map.rb +++ b/db/migrate/20160928095559_add_options_to_map.rb @@ -1,7 +1,7 @@ Sequel.migration do up do alter_table :maps do - add_column :embed_options, + add_column :options, :string, type: 'json' end @@ -9,7 +9,7 @@ Sequel.migration do down do alter_table :maps do - drop_column :embed_options + drop_column :options end end end diff --git a/spec/models/map_spec.rb b/spec/models/map_spec.rb index 60dd6a1880..db801a0001 100644 --- a/spec/models/map_spec.rb +++ b/spec/models/map_spec.rb @@ -55,7 +55,7 @@ describe Map do @map_user.destroy end - describe '#embed_options' do + describe '#options' do it 'sets dashboard_menu true by default' do @map.dashboard_menu.should eq true end @@ -84,68 +84,68 @@ describe Map do @map.dashboard_menu = 'patata' @map.valid?.should be_false - @map.errors[:embed_options][0].should include('String did not match the following type: boolean') + @map.errors[:options][0].should include('String did not match the following type: boolean') end it 'rejects a non-boolean layer_selector value' do @map.layer_selector = 'patata' @map.valid?.should be_false - @map.errors[:embed_options][0].should include('String did not match the following type: boolean') + @map.errors[:options][0].should include('String did not match the following type: boolean') end it 'requires a dashboard_menu value' do @map.dashboard_menu = nil @map.valid?.should be_false - @map.errors[:embed_options].should_not be_empty - @map.errors[:embed_options][0].should include('NilClass did not match the following type: boolean') + @map.errors[:options].should_not be_empty + @map.errors[:options][0].should include('NilClass did not match the following type: boolean') end it 'requires a layer_selector value' do @map.layer_selector = nil @map.valid?.should be_false - @map.errors[:embed_options].should_not be_empty - @map.errors[:embed_options][0].should include('NilClass did not match the following type: boolean') + @map.errors[:options].should_not be_empty + @map.errors[:options][0].should include('NilClass did not match the following type: boolean') end it 'requires dashboard_menu to be present' do - old_options = @map.embed_options.dup - @map.embed_options = Hash.new + old_options = @map.options.dup + @map.options = Hash.new @map.valid?.should be_false - @map.errors[:embed_options].should_not be_empty - @map.errors[:embed_options][0].should include('did not contain a required property of \'dashboard_menu\'') + @map.errors[:options].should_not be_empty + @map.errors[:options][0].should include('did not contain a required property of \'dashboard_menu\'') - @map.embed_options = old_options + @map.options = old_options end it 'requires layer_selector to be present' do - old_options = @map.embed_options.dup - @map.embed_options = Hash.new + old_options = @map.options.dup + @map.options = Hash.new @map.valid?.should be_false - @map.errors[:embed_options].should_not be_empty - @map.errors[:embed_options][0].should include('did not contain a required property of \'layer_selector\'') + @map.errors[:options].should_not be_empty + @map.errors[:options][0].should include('did not contain a required property of \'layer_selector\'') - @map.embed_options = old_options + @map.options = old_options end - it 'rejects spammy embed_options' do - @map.embed_options[:spam] = 'hell' + it 'rejects spammy options' do + @map.options[:spam] = 'hell' @map.valid?.should be_false - @map.errors[:embed_options].should_not be_empty - @map.errors[:embed_options][0].should include('spam') + @map.errors[:options].should_not be_empty + @map.errors[:options][0].should include('spam') end - it 'rejects incomplete embed_options' do - @map.embed_options.delete(:dashboard_menu) + it 'rejects incomplete options' do + @map.options.delete(:dashboard_menu) @map.valid?.should be_false - @map.errors[:embed_options].should_not be_empty - @map.errors[:embed_options][0].should include('dashboard_menu') + @map.errors[:options].should_not be_empty + @map.errors[:options][0].should include('dashboard_menu') end end end diff --git a/spec/requests/carto/api/maps_controller_spec.rb b/spec/requests/carto/api/maps_controller_spec.rb index 62f5f10e45..6ef4816a61 100644 --- a/spec/requests/carto/api/maps_controller_spec.rb +++ b/spec/requests/carto/api/maps_controller_spec.rb @@ -38,7 +38,7 @@ describe Carto::Api::MapsController do view_bounds_ne: "[32.30570601389429, -76.32202148437499]", view_bounds_sw: "[24.51713945052515, -89.329833984375]", zoom: 7, - embed_options: { + options: { dashboard_menu: false, legends: true, scrollwheel: true, @@ -54,7 +54,7 @@ describe Carto::Api::MapsController do end it 'validates on update' do - payload[:embed_options] = { spammy: 'hell', dashboard_menu: true } + payload[:options] = { spammy: 'hell', dashboard_menu: true } put_json create_show_map_url, payload do |response| response.status.should eq 422 end @@ -124,11 +124,11 @@ describe Carto::Api::MapsController do response.body[:view_bounds_sw].should eq @map.view_bounds_sw response.body[:view_bounds_ne].should eq @map.view_bounds_ne - response_embed_options = response.body[:embed_options] - response_embed_options[:dashboard_menu].should eq @map.dashboard_menu - response_embed_options[:layer_selector].should eq @map.layer_selector - response_embed_options[:legends].should eq @map.embed_options[:legends] - response_embed_options[:scrollwheel].should eq @map.embed_options[:scrollwheel] + response_options = response.body[:options] + response_options[:dashboard_menu].should eq @map.dashboard_menu + response_options[:layer_selector].should eq @map.layer_selector + response_options[:legends].should eq @map.options[:legends] + response_options[:scrollwheel].should eq @map.options[:scrollwheel] end end