_id is the only name of the entity identifier attribute
did
committed Oct 09, 2015
commit a0be241b7e9bd53ccfce8e37c927d6bb6e17e29e
Showing 4
changed files with
6 additions
and 4 deletions
locomotive/steam/entities/content_entry.rb b/lib/locomotive/steam/entities/content_entry.rb
+3
-1
| @@ | @@ -17,6 +17,8 @@ module Locomotive::Steam |
| }.merge(attributes)) | |
| end | |
| + | def _id; self[:_id] || self[:id]; end |
| + | |
| def _visible?; !!self[:_visible]; end | |
| alias :visible? :_visible? | |
| @@ | @@ -75,7 +77,7 @@ module Locomotive::Steam |
| def to_hash | |
| # default attributes | |
| - | _attributes = %i(id _slug _label _visible _position content_type_slug created_at updated_at) |
| + | _attributes = %i(_id _slug _label _visible _position content_type_slug created_at updated_at) |
| # dynamic attributes | |
| _attributes += content_type.persisted_field_names | |
locomotive/steam/liquid/drops/content_entry.rb b/lib/locomotive/steam/liquid/drops/content_entry.rb
+1
-1
| @@ | @@ -58,7 +58,7 @@ module Locomotive |
| def to_hash | |
| @_source.to_hash.tap do |hash| | |
| - | hash['_id'] = hash['id'] |
| + | hash['id'] = hash['_id'] |
| @_source.content_type.fields_by_name.each do |name, field| | |
| case field.type | |
spec/unit/entities/content_entry_spec.rb
+1
-1
| @@ | @@ -67,7 +67,7 @@ describe Locomotive::Steam::ContentEntry do |
| allow(type).to receive(:persisted_field_names).and_return([:title, :picture]) | |
| end | |
| - | it { expect(Set.new(subject.keys)).to eq(Set.new(['id', '_position', '_visible', '_label', '_slug', 'content_type_slug', 'title', 'picture', 'created_at', 'updated_at'])) } |
| + | it { expect(Set.new(subject.keys)).to eq(Set.new(['_id', '_position', '_visible', '_label', '_slug', 'content_type_slug', 'title', 'picture', 'created_at', 'updated_at'])) } |
| context 'when decorated' do | |
spec/unit/liquid/drops/content_entry_spec.rb
+1
-1
| @@ | @@ -102,7 +102,7 @@ describe Locomotive::Steam::Liquid::Drops::ContentEntry do |
| let(:picture_field) { Locomotive::Steam::ContentEntry::FileField.new('foo.png', 'http://assets.dev', 42) } | |
| before do | |
| - | allow(entry).to receive(:to_hash).and_return({ 'id' => 1, 'title' => 'Hello world', 'picture' => picture_field, 'category_id' => 42 }) |
| + | allow(entry).to receive(:to_hash).and_return({ '_id' => 1, 'title' => 'Hello world', 'picture' => picture_field, 'category_id' => 42 }) |
| allow(entry).to receive(:category).and_return('Test') | |
| end | |