-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor specs and add module_releases shared context
- Loading branch information
1 parent
379ebe6
commit 61bf0e5
Showing
10 changed files
with
112 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 4 additions & 11 deletions
15
app/services/visit_changes.rb → app/services/content_changes.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ContentChanges do | ||
subject(:changes) { described_class.new(user: user) } | ||
|
||
let(:user) { create(:user) } | ||
|
||
include_context 'with module releases' | ||
|
||
describe '#new_modules?' do | ||
context 'without previous visits' do | ||
it 'returns false' do | ||
expect(changes.new_modules?).to be false | ||
end | ||
end | ||
|
||
context 'with visits predating a modules release' do | ||
before do | ||
create :visit, | ||
id: 1, | ||
visitor_token: '123', | ||
user_id: user.id, | ||
started_at: 1.day.ago | ||
|
||
create :visit, | ||
id: 2, | ||
visitor_token: '456', | ||
user_id: user.id, | ||
started_at: 1.minute.ago | ||
end | ||
|
||
it 'returns true' do | ||
expect(changes.new_modules?).to be true | ||
end | ||
end | ||
end | ||
|
||
describe '#new_module?' do | ||
let(:alpha) { Training::Module.by_name(:alpha) } | ||
|
||
context 'without previous visits' do | ||
it 'returns false' do | ||
expect(changes.new_module?(alpha)).to be false | ||
end | ||
end | ||
|
||
context 'with visits since the modules release' do | ||
before do | ||
create :visit, | ||
id: 1, | ||
visitor_token: '123', | ||
user_id: user.id, | ||
started_at: 1.minute.ago | ||
end | ||
|
||
it 'returns false' do | ||
expect(changes.new_module?(alpha)).to be false | ||
end | ||
end | ||
|
||
context 'with visits predating a modules release' do | ||
before do | ||
create :visit, | ||
id: 1, | ||
visitor_token: '123', | ||
user_id: user.id, | ||
started_at: 5.days.ago | ||
|
||
create :visit, | ||
id: 2, | ||
visitor_token: '456', | ||
user_id: user.id, | ||
started_at: 5.days.ago | ||
end | ||
|
||
it 'returns true' do | ||
expect(changes.new_module?(alpha)).to be true | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
RSpec.shared_context 'with module releases' do | ||
before do | ||
create_module_release(1, 'alpha', 2.days.ago) | ||
create_module_release(2, 'bravo', 3.days.ago) | ||
create_module_release(3, 'charlie', 2.minutes.ago) | ||
end | ||
|
||
def create_module_release(id, name, first_published_at) | ||
create(:release, id: id) | ||
create(:module_release, release_id: id, module_position: id, name: name, first_published_at: first_published_at) | ||
end | ||
end |