-
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.
* check if module has been released since user's last visit * update account page for one login * Add new module indicator tag * revert account page changes * temporarily remove conditional logic from tags to aid reviewing * fix merge conflicts * prevent any available or complete modules from showing new module indicator * add check for module release record to new mod method * rubocop * move styling to stylesheet * revert schema changes * move new module logic to new service * VisitChanges #new_modules without previous visits returns no modules with previous visits returns newly released modules * add started guard clause to new tag * guarding alternatives * refactor specs and add module_releases shared context * add module_release spec * add test for new module indicator on in progress modules * update account page for one login * remove unnecessary visits from spec * revert account changes * Merge remote-tracking branch 'origin/main' into new-module-indicator * revert github workflows * revert erroneous changes * revert changes to course_progress * undo revert to course_progress --------- Co-authored-by: Peter David Hamilton <[email protected]>
- Loading branch information
1 parent
df57829
commit 9475685
Showing
14 changed files
with
199 additions
and
18 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
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,34 @@ | ||
# Content changes since the user's last visit, powered by Ahoy::Visit | ||
# | ||
class ContentChanges | ||
extend Dry::Initializer | ||
|
||
option :user, required: true | ||
|
||
# @return [Boolean] | ||
def new_modules? | ||
return false if previous_visit.nil? | ||
|
||
new_modules.any? | ||
end | ||
|
||
# @param mod [Training::Module] | ||
# @return [Boolean] | ||
def new_module?(mod) | ||
return false if previous_visit.nil? || user.course.started?(mod) | ||
|
||
previous_visit.started_at < mod.first_published_at | ||
end | ||
|
||
# @return [Array<Training::Module>] | ||
def new_modules | ||
user.course.available_modules.select { |mod| new_module?(mod) } | ||
end | ||
|
||
private | ||
|
||
# @return [Ahoy::Visit] | ||
def previous_visit | ||
user.visits.order(started_at: :desc).second | ||
end | ||
end |
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,10 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ModuleRelease, type: :model do | ||
describe '.ordered' do | ||
include_context 'with module releases' | ||
it 'returns module releases in order of module position' do | ||
expect(described_class.ordered.map(&:module_position)).to eq([1, 2, 3]) | ||
end | ||
end | ||
end |
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,92 @@ | ||
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 | ||
|
||
context 'and a module in progress' do | ||
include_context 'with progress' | ||
before do | ||
start_module(alpha) | ||
end | ||
|
||
it 'returns false' do | ||
expect(changes.new_module?(alpha)).to be false | ||
end | ||
end | ||
end | ||
end | ||
end |
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 |