still fixing the integration specs
did
committed Mar 12, 2015
commit 7f3739c2e6eee1862217f889c799232bdfebf2f0
Showing 18
changed files with
57 additions
and 34 deletions
locomotive/steam/adapters/filesystem/sanitizers/content_entry.rb b/lib/locomotive/steam/adapters/filesystem/sanitizers/content_entry.rb
+7
-2
| @@ | @@ -33,7 +33,11 @@ module Locomotive::Steam |
| end | |
| def set_id(entry) | |
| - | entry[:_id] = entry[:_slug][locale] |
| + | if (slug = entry[:_slug]).respond_to?(:translations) |
| + | entry[:_id] = slug[locale] |
| + | else |
| + | entry[:_id] = slug |
| + | end |
| end | |
| def set_slug(entry, dataset) | |
| @@ | @@ -42,7 +46,8 @@ module Locomotive::Steam |
| entry[:_slug][locale] ||= slugify(entry._id, label, dataset, locale) | |
| end | |
| else | |
| - | entry[:_slug][locale] = slugify(entry._id, entry._label, dataset) |
| + | # not a big deal if we replace the I18nField by a string |
| + | entry[:_slug] = slugify(entry._id, entry._label, dataset) |
| end | |
| end | |
locomotive/steam/adapters/filesystem/yaml_loader.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loader.rb
+1
-1
| @@ | @@ -15,7 +15,7 @@ module Locomotive::Steam |
| end | |
| def default_locale | |
| - | @scope.locale |
| + | @scope.default_locale |
| end | |
| def _load(path, frontmatter = false, &block) | |
locomotive/steam/adapters/filesystem/yaml_loaders/page.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb
+3
-2
| @@ | @@ -78,8 +78,9 @@ module Locomotive |
| relative_path = get_relative_path(filepath) | |
| - | fullpath, locale = relative_path.split('.')[0..1] |
| - | locale = default_locale if template_extensions.include?(locale) |
| + | fullpath, extension_or_locale = relative_path.split('.')[0..1] |
| + | |
| + | locale = template_extensions.include?(extension_or_locale) ? default_locale : extension_or_locale |
| yield(filepath, relative_path, fullpath, locale.to_sym) | |
| end | |
locomotive/steam/adapters/memory/condition.rb b/lib/locomotive/steam/adapters/memory/condition.rb
+2
-2
| @@ | @@ -40,8 +40,8 @@ module Locomotive::Steam |
| end | |
| end | |
| - | def to_s |
| - | "#{field} #{operator} #{@value.to_s}" |
| + | def inspect |
| + | "#{field}.#{operator} #{value}" |
| end | |
| protected | |
locomotive/steam/adapters/memory/query.rb b/lib/locomotive/steam/adapters/memory/query.rb
+2
-0
| @@ | @@ -63,6 +63,8 @@ module Locomotive::Steam |
| end | |
| def all | |
| + | # TODO: instrumentation here |
| + | # Locomotive::Common::Logger.debug "[dataset][#{@dataset.name}] conditions = #{@conditions.map(&:inspect).join(' AND ')}" |
| limited sorted(filtered) | |
| end | |
locomotive/steam/decorators/i18n_decorator.rb b/lib/locomotive/steam/decorators/i18n_decorator.rb
+6
-10
| @@ | @@ -22,9 +22,9 @@ module Locomotive |
| class << self | |
| - | def decorate(object_or_list, attributes = nil, locale = nil, default_locale = nil) |
| + | def decorate(object_or_list, locale = nil, default_locale = nil) |
| decorated = [[object_or_list]].flatten.map do |object| | |
| - | new(object, attributes, locale, default_locale) |
| + | new(object, locale, default_locale) |
| end | |
| object_or_list.respond_to?(:attributes) ? decorated.first : decorated | |
| @@ | @@ -60,6 +60,7 @@ module Locomotive |
| end | |
| def __is_localized_attribute__(name) | |
| + | return false if name == :try |
| # __localized_attributes__.include?(name.to_sym) | |
| field = __getobj__.public_send(name.to_sym) | |
| field.respond_to?(:__translations__) | |
| @@ | @@ -84,9 +85,7 @@ module Locomotive |
| def __set_localized_value__(name, value) | |
| field = __getobj__.public_send(name.to_sym) | |
| - | binding.pry |
| - | field[__locale__] || field[__default_locale__] |
| - | |
| + | field[__locale__] = value |
| # field = __getobj__.public_send(name.to_sym) | |
| # if field.respond_to?(:__translations__) | |
| @@ | @@ -97,20 +96,17 @@ module Locomotive |
| end | |
| def method_missing(name, *args, &block) | |
| - | ::Object.send(:puts, "YOUPI (1) #{name.inspect} #{args.inspect}") |
| - | # # ::Object.send(:puts, "[#{name}][#{__locale__.inspect}][#{__default_locale__.inspect}] with #{args.inspect}") # DEBUG: |
| + | # ::Object.send(:puts, "[#{name}][#{__locale__.inspect}][#{__default_locale__.inspect}] with #{args.inspect}") # DEBUG: |
| if name.to_s.end_with?('=') && __is_localized_attribute__(name.to_s.chop) | |
| - | ::Object.send(:puts, "YOUPI (2)") |
| __set_localized_value__(name.to_s.chop, args.first) | |
| - | elsif __is_localized_attribute__(name) |
| + | elsif !name.to_s.end_with?('=') && __is_localized_attribute__(name) |
| __get_localized_value__(name) | |
| else | |
| # Note: we want to hit the method_missing of the target object | |
| __getobj__.send(name, *args, &block) | |
| end | |
| - | |
| # if __is_localized_attribute__(name) | |
| # __get_localized_value__(name) | |
| # elsif name.to_s.end_with?('=') && __is_localized_attribute__(name.to_s.chop) | |
locomotive/steam/entities/page.rb b/lib/locomotive/steam/entities/page.rb
+1
-1
| @@ | @@ -39,7 +39,7 @@ module Locomotive::Steam |
| end | |
| def to_liquid | |
| - | Steam::Liquid::Drops::Page.new(self) |
| + | Locomotive::Steam::Liquid::Drops::Page.new(self) |
| end | |
| end | |
locomotive/steam/entities/site.rb b/lib/locomotive/steam/entities/site.rb
+1
-1
| @@ | @@ -31,7 +31,7 @@ module Locomotive::Steam |
| end | |
| def to_liquid | |
| - | Steam::Liquid::Drops::Site.new(self) |
| + | Locomotive::Steam::Liquid::Drops::Site.new(self) |
| end | |
| end | |
locomotive/steam/entities/translation.rb b/lib/locomotive/steam/entities/translation.rb
+4
-0
| @@ | @@ -10,6 +10,10 @@ module Locomotive::Steam |
| }.merge(attributes)) | |
| end | |
| + | def values |
| + | self[:values] |
| + | end |
| + | |
| end | |
| end | |
locomotive/steam/liquid/drops/content_types.rb b/lib/locomotive/steam/liquid/drops/content_types.rb
+1
-2
| @@ | @@ -58,8 +58,7 @@ module Locomotive |
| end | |
| def collection | |
| - | # TODO: repository.with(@content_type).all(....) |
| - | @collection ||= repository.all(@content_type, @context['with_scope']) |
| + | @collection ||= repository.with(@content_type).all(@context['with_scope']) |
| end | |
| end | |
locomotive/steam/liquid/tags/nav.rb b/lib/locomotive/steam/liquid/tags/nav.rb
+1
-1
| @@ | @@ -278,7 +278,7 @@ module Locomotive |
| def decorate_page(page) | |
| klass = Locomotive::Steam::Decorators::I18nDecorator | |
| - | klass.new(page, page.localized_attributes, current_locale, current_site.default_locale) |
| + | klass.new(page, current_locale, current_site.default_locale) |
| end | |
| def bootstrap? | |
locomotive/steam/middlewares/templatized_page.rb b/lib/locomotive/steam/middlewares/templatized_page.rb
+1
-1
| @@ | @@ -34,7 +34,7 @@ module Locomotive::Steam |
| def fetch_content_entry(slug) | |
| if type = content_type_repository.by_slug(page.content_type) | |
| - | decorate(content_entry_repository.by_slug(type, slug)) |
| + | decorate(content_entry_repository.with(type).by_slug(slug)) |
| else | |
| nil | |
| end | |
locomotive/steam/repositories/page_repository.rb b/lib/locomotive/steam/repositories/page_repository.rb
+4
-5
| @@ | @@ -20,18 +20,17 @@ module Locomotive |
| end | |
| def by_handle(handle) | |
| - | query { where(handle: handle) }.first |
| + | first { where(handle: handle) } |
| end | |
| def by_fullpath(path) | |
| - | query { where(fullpath: path) }.first |
| + | first { where(fullpath: path) } |
| end | |
| def matching_fullpath(list) | |
| all(k(:fullpath, :in) => list) | |
| end | |
| - | # Engine: ??? [TODO] |
| def template_for(entry, handle = nil) | |
| conditions = { templatized?: true, content_type: entry.try(:content_type_slug) } | |
| @@ | @@ -43,12 +42,12 @@ module Locomotive |
| end | |
| def root | |
| - | query { where(fullpath: 'index') }.first |
| + | first { where(fullpath: 'index') } |
| end | |
| def parent_of(page) | |
| return nil if page.nil? || page.index? | |
| - | query { where(_id: page.parent_id) }.first |
| + | first { where(_id: page.parent_id) } |
| end | |
| # Note: Ancestors and self | |
locomotive/steam/repositories/translation_repository.rb b/lib/locomotive/steam/repositories/translation_repository.rb
+1
-1
| @@ | @@ -9,7 +9,7 @@ module Locomotive |
| mapping :translations, entity: Translation | |
| def by_key(key) | |
| - | query { where(key: key) }.first |
| + | first { where(key: key) } |
| end | |
| end | |
locomotive/steam/services/concerns/decorator.rb b/lib/locomotive/steam/services/concerns/decorator.rb
+1
-1
| @@ | @@ -11,7 +11,7 @@ module Locomotive |
| if (object = yield).blank? | |
| object | |
| else | |
| - | klass.decorate(object, nil, locale, default_locale) |
| + | klass.decorate(object, locale, default_locale) |
| end | |
| end | |
locomotive/steam/services/translator_service.rb b/lib/locomotive/steam/services/translator_service.rb
+1
-1
| @@ | @@ -15,7 +15,7 @@ module Locomotive |
| locale ||= self.current_locale | |
| if scope.blank? | |
| - | values = repository.find(input).try(:values) || {} |
| + | values = repository.by_key(input).try(:values) || {} |
| if translation = values[locale.to_s] | |
| translation | |
spec/unit/adapters/filesystem/yaml_loaders/page_spec.rb
+3
-2
| @@ | @@ -10,13 +10,14 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::Page do |
| describe '#load' do | |
| - | let(:scope) { instance_double('Scope', locale: :en) } |
| + | let(:scope) { instance_double('Scope', locale: :fr, default_locale: :en) } |
| subject { loader.load(scope).sort { |a, b| a[:_fullpath] <=> b[:_fullpath] } } | |
| it 'tests various stuff' do | |
| expect(subject.size).to eq 24 | |
| - | expect(subject.first[:title]).to eq({ en: 'Page not found' }) |
| + | expect(subject.first[:title]).to eq(en: 'Page not found') |
| + | expect(subject[14][:slug]).to eq(en: 'music', fr: 'notre-musique') |
| end | |
| end | |
spec/unit/repositories/page_repository_spec.rb
+17
-1
| @@ | @@ -1,7 +1,6 @@ |
| require 'spec_helper' | |
| require_relative '../../../lib/locomotive/steam/adapters/filesystem.rb' | |
| - | # require_relative '../../../lib/locomotive/steam/repositories/editable_element_repository.rb' |
| describe Locomotive::Steam::PageRepository do | |
| @@ | @@ -79,6 +78,23 @@ describe Locomotive::Steam::PageRepository do |
| end | |
| + | describe '#find' do |
| + | |
| + | let(:id) { 15 } |
| + | let(:pages) do |
| + | [ |
| + | { _id: 15, parent_id: 1, title: { en: 'Somewhere' }, slug: { en: 'music', fr: 'notre-musique' }, _fullpath: 'music', template_path: { en: 'somewhere.liquid' } }, |
| + | { _id: 1, title: { en: 'Home' }, slug: { en: 'index' }, _fullpath: 'index', template_path: { en: 'index.liquid' } } |
| + | ] |
| + | end |
| + | |
| + | subject { repository.find(id) } |
| + | |
| + | it { expect(subject.slug.translations).to eq('en' => 'music', 'fr' => 'notre-musique') } |
| + | it { expect(subject.fullpath.translations).to eq('en' => 'music', 'fr' => 'notre-musique') } |
| + | |
| + | end |
| + | |
| describe '#by_fullpath' do | |
| let(:path) { nil } | |