diff --git a/Gemfile.lock b/Gemfile.lock index b4ce7be6..75a976bc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -44,7 +44,7 @@ PATH locomotive_liquid (= 2.2.2) mimetype-fu (~> 0.1.2) mongo (~> 1.5.2) - mongoid (~> 2.4.6) + mongoid (~> 2.4.9) multi_json (= 1.2.0) rack-cache (~> 1.1) rails (~> 3.2.3) @@ -115,7 +115,7 @@ GEM childprocess (0.3.1) ffi (~> 1.0.6) chunky_png (1.2.5) - codemirror-rails (2.23) + codemirror-rails (2.24) railties (~> 3.0) coffee-rails (3.2.2) coffee-script (>= 2.2.0) @@ -215,7 +215,7 @@ GEM mocha (0.9.12) mongo (1.5.2) bson (= 1.5.2) - mongoid (2.4.8) + mongoid (2.4.9) activemodel (~> 3.1) mongo (~> 1.3) tzinfo (~> 0.3.22) diff --git a/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee b/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee index 01c5c681..ab94fad7 100644 --- a/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee @@ -24,10 +24,6 @@ class Locomotive.Views.Shared.Fields.ManyToManyView extends Backbone.View @collection = @model.get(@options.name) @all_entries = @options.all_entries - window.collection = @collection - window.bar = @all_entries - window.model = @model - render: -> $(@el).html(@template()()) diff --git a/app/helpers/locomotive/content_types_helper.rb b/app/helpers/locomotive/content_types_helper.rb index 20eb07cf..443cde41 100644 --- a/app/helpers/locomotive/content_types_helper.rb +++ b/app/helpers/locomotive/content_types_helper.rb @@ -27,6 +27,10 @@ module Locomotive end visible << content_type + + end.each do |content_type| + # make sure to have a fresh copy of the content types because for now we don't have the full content types (ie: content_types.only(...)) + ::Mongoid::IdentityMap.remove(content_type) end if visible.size > 0 diff --git a/app/models/locomotive/content_entry.rb b/app/models/locomotive/content_entry.rb index 8273c46f..5be95ed7 100644 --- a/app/models/locomotive/content_entry.rb +++ b/app/models/locomotive/content_entry.rb @@ -86,7 +86,7 @@ module Locomotive end def as_json(options = {}) - self.to_presenter.as_json + self.to_presenter(options).as_json end protected diff --git a/app/models/locomotive/extensions/page/tree.rb b/app/models/locomotive/extensions/page/tree.rb index a1f97fa4..9edd58d3 100644 --- a/app/models/locomotive/extensions/page/tree.rb +++ b/app/models/locomotive/extensions/page/tree.rb @@ -19,6 +19,9 @@ module Locomotive ## indexes ## index :position index [[:depth, Mongo::ASCENDING], [:position, Mongo::ASCENDING]] + + alias_method_chain :rearrange, :identity_map + alias_method_chain :rearrange_children, :identity_map end module ClassMethods @@ -101,6 +104,16 @@ module Locomotive protected + def rearrange_with_identity_map + ::Mongoid::IdentityMap.clear + rearrange_without_identity_map + end + + def rearrange_children_with_identity_map + self.children.reset + rearrange_children_without_identity_map + end + def persist_depth self.attributes['depth'] = self.depth self.depth_will_change! diff --git a/app/models/locomotive/site.rb b/app/models/locomotive/site.rb index 51e3c5e2..b67db836 100644 --- a/app/models/locomotive/site.rb +++ b/app/models/locomotive/site.rb @@ -54,8 +54,12 @@ module Locomotive Locomotive::Liquid::Drops::Site.new(self) end + def to_presenter(options = {}) + Locomotive::SitePresenter.new(self, options) + end + def as_json(options = {}) - Locomotive::SitePresenter.new(self, options).as_json + self.to_presenter(options).as_json end protected diff --git a/app/presenters/locomotive/membership_presenter.rb b/app/presenters/locomotive/membership_presenter.rb index e0d82227..06b592b5 100644 --- a/app/presenters/locomotive/membership_presenter.rb +++ b/app/presenters/locomotive/membership_presenter.rb @@ -1,7 +1,7 @@ module Locomotive class MembershipPresenter < BasePresenter - delegate :role, :to => :source + delegate :role, :account_id, :to => :source def name self.source.account.name @@ -26,8 +26,13 @@ module Locomotive end def included_methods - super + %w(name email role role_name can_update grant_admin) + super + %w(account_id name email role role_name can_update grant_admin) end + # def light_as_json + # methods = included_methods.clone - %w(name email) + # self.as_json(methods) + # end + end end \ No newline at end of file diff --git a/app/presenters/locomotive/site_presenter.rb b/app/presenters/locomotive/site_presenter.rb index 272571be..406002ee 100644 --- a/app/presenters/locomotive/site_presenter.rb +++ b/app/presenters/locomotive/site_presenter.rb @@ -15,5 +15,10 @@ module Locomotive super + %w(name locales domain_name subdomain domains robots_txt seo_title meta_keywords meta_description domains_without_subdomain memberships) end + def as_json_for_html_view + methods = included_methods.clone - %w(memberships) + self.as_json(methods) + end + end end \ No newline at end of file diff --git a/app/views/locomotive/custom_fields/types/_many_to_many.html.haml b/app/views/locomotive/custom_fields/types/_many_to_many.html.haml index 0aef925b..6680b1fa 100644 --- a/app/views/locomotive/custom_fields/types/_many_to_many.html.haml +++ b/app/views/locomotive/custom_fields/types/_many_to_many.html.haml @@ -1,10 +1,10 @@ - if field.ui_enabled? - target_content_type = Locomotive::ContentType.class_name_to_content_type(field.class_name, current_site) - = f.input name.to_sym, - :label => field.label, - :hint => field.hint, - :as => :'Locomotive::Empty', + = f.input name.to_sym, + :label => field.label, + :hint => field.hint, + :as => :'Locomotive::Empty', :wrapper_html => { :id => "content_entry_#{name}_input", :class => 'empty relationship input' } - content_for :head do @@ -38,4 +38,4 @@ - content_for :backbone_view_data do :plain - , all_#{name}_entries: #{target_content_type.list_or_group_entries.to_json} \ No newline at end of file + , all_#{name}_entries: #{target_content_type.list_or_group_entries.to_json(:depth => 1)} \ No newline at end of file diff --git a/app/views/locomotive/shared/_head.html.haml b/app/views/locomotive/shared/_head.html.haml index fb89e923..754413bd 100644 --- a/app/views/locomotive/shared/_head.html.haml +++ b/app/views/locomotive/shared/_head.html.haml @@ -19,7 +19,7 @@ window.locale = '#{I18n.locale}'; window.content_locale = '#{::Mongoid::Fields::I18n.locale}'; - Locomotive.current_site = new Locomotive.Models.Site(#{current_site.to_json}); + Locomotive.current_site = new Locomotive.Models.Site(#{current_site.to_presenter.as_json_for_html_view.to_json}); Locomotive.current_account = new Locomotive.Models.Account(#{current_locomotive_account.to_json}); $(document).ready(function() { diff --git a/locomotive_cms.gemspec b/locomotive_cms.gemspec index e5d6d902..8f58273b 100755 --- a/locomotive_cms.gemspec +++ b/locomotive_cms.gemspec @@ -27,7 +27,7 @@ Gem::Specification.new do |s| s.add_dependency 'mongo', '~> 1.5.2' s.add_dependency 'bson_ext', '~> 1.5.2' - s.add_dependency 'mongoid', '~> 2.4.6' + s.add_dependency 'mongoid', '~> 2.4.9' s.add_dependency 'locomotive-mongoid-tree', '~> 0.6.2' s.add_dependency 'custom_fields', '~> 2.0.0.rc10' diff --git a/spec/dummy/config/mongoid.yml b/spec/dummy/config/mongoid.yml index 17611c5e..dabbe6ca 100644 --- a/spec/dummy/config/mongoid.yml +++ b/spec/dummy/config/mongoid.yml @@ -10,11 +10,14 @@ defaults: &defaults development: <<: *defaults database: locomotive_engine_dev + identity_map_enabled: true test: <<: *defaults database: locomotive_engine_test + identity_map_enabled: true production: <<: *defaults + identity_map_enabled: true database: locomotive_engine_production diff --git a/spec/models/locomotive/content_type_spec.rb b/spec/models/locomotive/content_type_spec.rb index b3114230..0e7911f9 100644 --- a/spec/models/locomotive/content_type_spec.rb +++ b/spec/models/locomotive/content_type_spec.rb @@ -131,7 +131,7 @@ describe Locomotive::ContentType do it 'updates the information about the order of a has_many relationship if the target class changes its order' do @content_type.order_by = 'description'; @content_type.order_direction = 'ASC'; @content_type.save! - @category_1 = @category_1.class.find(@category_1._id) + @category_1 = safe_find(@category_1.class, @category_1._id) @category_1.projects.metadata.order.should == %w(description ASC) @category_1.projects.map(&:name).should == %w(LocomotiveCMS RubyOnRails) @@ -139,7 +139,9 @@ describe Locomotive::ContentType do it 'uses the order by position if the UI option is enabled' do field = @category_content_type.entries_custom_fields.where(:name => 'projects').first - field.ui_enabled = true; @category_content_type.save!; @category_1 = @category_1.class.find(@category_1._id) + field.ui_enabled = true; + + @category_content_type.save!; @category_1 = safe_find(@category_1.class, @category_1._id) @category_1.projects.metadata.order.to_s.should == 'position_in_category' @category_1.projects.map(&:name).should == %w(LocomotiveCMS RubyOnRails) @@ -337,6 +339,11 @@ describe Locomotive::ContentType do end end + def safe_find(klass, id) + Mongoid::IdentityMap.clear + klass.find(id) + end + def build_content_entry(content_type) content_type.entries.build(:name => 'Asset on steroids', :description => 'Lorem ipsum', :active => true) end diff --git a/spec/models/locomotive/page_spec.rb b/spec/models/locomotive/page_spec.rb index cbcf4ea6..b02075ad 100644 --- a/spec/models/locomotive/page_spec.rb +++ b/spec/models/locomotive/page_spec.rb @@ -143,8 +143,8 @@ describe Locomotive::Page do describe 'tree organization' do before(:each) do - @home = FactoryGirl.create(:page) - @child_1 = FactoryGirl.create(:page, :title => 'Subpage 1', :slug => 'foo', :parent_id => @home._id, :site => @home.site) + @home = FactoryGirl.create(:page) + @child_1 = FactoryGirl.create(:page, :title => 'Subpage 1', :slug => 'foo', :parent_id => @home._id, :site => @home.site) end it 'adds root elements' do @@ -390,4 +390,5 @@ describe Locomotive::Page do def fake_bson_id(id) BSON::ObjectId(id.to_s.rjust(24, '0')) end + end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7256eb21..de9380c0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,6 +27,10 @@ RSpec.configure do |config| DatabaseCleaner.orm = 'mongoid' end + config.before(:each) do + Mongoid::IdentityMap.clear + end + config.before(:each) do DatabaseCleaner.clean end