Skip to content

Commit

Permalink
Adding spec for related translations
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveitaly committed Aug 19, 2016
1 parent c6810ae commit 690cdd3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/models/cangaroo/translation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@
Rails.configuration.cangaroo.payload_keys = ['id', 'order_id']
end

describe '#related_translations' do
it 'returns other translation of this same object that have been sent through the pipeline' do
translation.save!

previous_translation = FactoryGirl.build(:translation)

previous_translation.object_type = translation.object_type
# copying the request will also copy the ID + key type on save
previous_translation.request = translation.request.deep_dup
previous_translation.request['another_field'] = Faker::Lorem.word
previous_translation.save!

expect(translation.related_translations).to_not be_empty
expect(translation.related_translations.first.id).to eq(previous_translation.id)
end

it 'returns an empty collection when on previous objects exist' do
expect(translation.related_translations).to be_empty
end
end

describe "#object_key" do
it "chooses the first primary key available" do
translation.request = {
Expand Down

0 comments on commit 690cdd3

Please sign in to comment.