Skip to content

Commit

Permalink
Merge pull request #700 from koffeinfrei/chores/remove-timecop
Browse files Browse the repository at this point in the history
Remove timecop gem
  • Loading branch information
koffeinfrei committed Aug 31, 2024
2 parents 3e4713f + ecf0bb3 commit 28622a6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 46 deletions.
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,3 @@ group :development do
gem 'rubocop-rspec', '~> 2.19', require: false
gem 'seed_box'
end

group :test do
gem 'timecop'
end
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ GEM
stringio (3.1.0)
strscan (3.1.0)
thor (1.3.1)
timecop (0.9.9)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -421,7 +420,6 @@ DEPENDENCIES
selenium-webdriver
spring
spring-commands-rspec
timecop
webrick

BUNDLED WITH
Expand Down
68 changes: 36 additions & 32 deletions spec/features/edit_note_conflict_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,49 @@
require 'rails_helper'

RSpec.describe 'Edit note with conflict', :js do
include ActiveSupport::Testing::TimeHelpers

context 'as logged in user' do
let(:user) { create_user }

before { login_as user }

it 'A copy of the note is created' do
Timecop.travel(Time.zone.local(2016, 8, 1, 15, 33)) do
note = Note.create!(
title: 'my note',
user: user,
content: 'note content',
uid: SecureRandom.uuid
)

# load the note...
visit_and_wait "/#/notes/#{note.uid}"
expect(page).to have_content 'my note'
expect(page).to have_content 'note content'

# ...in the meantime there's an edit
note.update! content: '<p>note content - update 1</p>'

find('.ql-editor').set('note content - update 2')

after_save_cycle do
expect(page).to have_content 'SAVED'
end

expect(page).to have_content 'my note (conflict 2016-08-01 15:33)'

# the note has the updated content
expect(note.reload.content).to eq '<p>note content - update 2</p>'

# the conflict copy has the old content
expect(Note.last).to have_attributes(
title: 'my note (conflict 2016-08-01 15:33)',
content: '<p>note content - update 1</p>'
)
travel_to Time.zone.local(2016, 8, 1, 15, 33)

note = Note.create!(
title: 'my note',
user: user,
content: 'note content',
uid: SecureRandom.uuid
)

# load the note...
visit_and_wait "/#/notes/#{note.uid}"
expect(page).to have_content 'my note'
expect(page).to have_content 'note content'

# ...in the meantime there's an edit
travel_to Time.zone.local(2016, 8, 1, 15, 34)
note.update! content: '<p>note content - update 1</p>'

travel_to Time.zone.local(2016, 8, 1, 15, 35)
find('.ql-editor').set('note content - update 2')

after_save_cycle do
expect(page).to have_content 'SAVED'
end

expect(page).to have_content 'my note (conflict 2016-08-01 15:35)'

# the note has the updated content
expect(note.reload.content).to eq '<p>note content - update 2</p>'

# the conflict copy has the old content
expect(Note.last).to have_attributes(
title: 'my note (conflict 2016-08-01 15:35)',
content: '<p>note content - update 1</p>'
)
end
end
end
18 changes: 10 additions & 8 deletions spec/models/note_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'rails_helper'

RSpec.describe Note do
include ActiveSupport::Testing::TimeHelpers

describe '#as_json' do
context 'when no options provided' do
it 'returns the whitelisted attributes' do
Expand Down Expand Up @@ -120,16 +122,16 @@
it 'sets the archived_at timestamp' do
now = Time.zone.local(2016, 8, 1, 15, 33)

Timecop.freeze(now) do
note = described_class.create!(
uid: SecureRandom.uuid,
user: create_user
)
travel_to now

note = described_class.create!(
uid: SecureRandom.uuid,
user: create_user
)

note.archive!
note.archive!

expect(note.archived_at).to eq now
end
expect(note.archived_at).to eq now
end
end

Expand Down

0 comments on commit 28622a6

Please sign in to comment.