Skip to content

Commit

Permalink
Correct time sensitive tests
Browse files Browse the repository at this point in the history
  - change to their more robust form using `be_withing(3.seconds)` or

    update the `updated_at` column manually to an older date
  • Loading branch information
mtomov authored and tvdeyen committed Jun 20, 2017
1 parent 2afef6a commit e618d5c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
12 changes: 6 additions & 6 deletions lib/alchemy/test_support/essence_shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

it "touches the content after update" do
element = create(:alchemy_element)
content = create(:alchemy_content, element: element)
essence.save
content.update(essence: essence, essence_type: essence.class.name)
date = content.updated_at
content.essence.update(essence.ingredient_column.to_sym => ingredient_value)
content = create(:alchemy_content, element: element, essence: essence, essence_type: essence.class.name)

content.update_column(:updated_at, 3.days.ago)
content.essence.update_attributes(essence.ingredient_column.to_sym => ingredient_value)

content.reload
expect(content.updated_at).not_to eq(date)
expect(content.updated_at).to be_within(3.seconds).of(Time.current)
end

it "should have correct partial path" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module Alchemy
end

it "updates the @content.updated_at column" do
content.update_column(:updated_at, 3.days.ago)
expect {
alchemy_xhr :put, :assign, content_id: content.id, attachment_id: attachment.id
}.to change(content, :updated_at)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ module Alchemy
end

it "updates the content timestamp" do
content.update_column(:updated_at, 3.days.ago)
expect {
alchemy_xhr :put, :assign, content_id: '1', picture_id: '1'
}.to change(content, :updated_at)
Expand Down
1 change: 1 addition & 0 deletions spec/models/alchemy/element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ module Alchemy
let!(:element) { create(:alchemy_element, name: 'slide', parent_element: parent_element) }

it "touches parent after update" do
parent_element.update_column(:updated_at, 3.days.ago)
expect { element.update!(public: false) }.to change(parent_element, :updated_at)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/alchemy/essence_date_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Alchemy

it_behaves_like "an essence" do
let(:essence) { EssenceDate.new }
let(:ingredient_value) { DateTime.current }
let(:ingredient_value) { DateTime.current.iso8601 }
end

describe '#preview_text' do
Expand Down
8 changes: 4 additions & 4 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2394,20 +2394,20 @@ module Alchemy

describe '#published_at' do
context 'with published_at date set' do
let(:published_at) { Time.current }
let(:published_at) { 3.days.ago }
let(:page) { build_stubbed(:alchemy_page, published_at: published_at) }

it "returns the published_at value from database" do
expect(page.published_at).to eq(published_at)
expect(page.published_at).to be_within(1.second).of(published_at)
end
end

context 'with published_at is nil' do
let(:updated_at) { Time.current }
let(:updated_at) { 3.days.ago }
let(:page) { build_stubbed(:alchemy_page, published_at: nil, updated_at: updated_at) }

it "returns the updated_at value" do
expect(page.published_at).to eq(updated_at)
expect(page.published_at).to be_within(1.second).of(updated_at)
end
end
end
Expand Down

0 comments on commit e618d5c

Please sign in to comment.