-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature incognito mode #112
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bafe648
Introducing some delegations
flbulgarelli 5d47b87
Adding nil_user
flbulgarelli 6308000
Making try_submit! polymorphic too
flbulgarelli cecadeb
Reifying incognito mode
flbulgarelli c0e19b8
Making next_exercise work
flbulgarelli 723b3b7
Restoring unordered behaviour of pending_exercises
flbulgarelli cff7534
Making incognito discussion-less
flbulgarelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
5 changes: 5 additions & 0 deletions
5
db/migrate/20200804191643_add_incognito_mode_enabled_to_organization.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddIncognitoModeEnabledToOrganization < ActiveRecord::Migration[5.1] | ||
def change | ||
add_column :organizations, :incognito_mode_enabled, :boolean | ||
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,108 @@ | ||
module Mumuki::Domain | ||
class IncognitoClass | ||
|
||
def incognito? | ||
true | ||
end | ||
|
||
# ============ | ||
# Permissions | ||
# ============ | ||
|
||
def ensure_enabled! | ||
end | ||
|
||
def has_student_granted_organizations? | ||
false | ||
end | ||
|
||
def teacher_here? | ||
false | ||
end | ||
|
||
def teacher_of?(*) | ||
false | ||
end | ||
|
||
def profile_completed? | ||
true | ||
end | ||
|
||
def writer? | ||
false | ||
end | ||
|
||
def moderator_here? | ||
false | ||
end | ||
|
||
# ======== | ||
# Visiting | ||
# ======== | ||
|
||
def visit!(*) | ||
end | ||
|
||
# ======== | ||
# Progress | ||
# ======== | ||
|
||
def next_exercise_at(guide) | ||
guide.exercises.first | ||
end | ||
|
||
# def completed_containers_with_lookahead(*) | ||
# raise 'Unsupported operation. Userless mode and progressive display modes are incompatible' | ||
# end | ||
|
||
def progress_at(content, organization) | ||
Indicator.new content: content, organization: organization | ||
end | ||
|
||
def build_assignment(exercise, organization) | ||
Assignment.new exercise: exercise, organization: organization, submitter: self | ||
end | ||
|
||
def pending_siblings_at(content) | ||
[] | ||
end | ||
|
||
# ============ | ||
# ActiveRecord | ||
# ============ | ||
|
||
def id | ||
'<incognito>' | ||
end | ||
|
||
def is_a?(other) | ||
other.is_a?(Class) && other.name == 'User' || super | ||
end | ||
|
||
def _read_attribute(key) | ||
return id if key == 'id' | ||
raise "unknown attribute #{key}" | ||
end | ||
|
||
def self.primary_key | ||
'id' | ||
end | ||
|
||
# ========== | ||
# Evaluation | ||
# ========== | ||
|
||
def interpolations | ||
[] | ||
end | ||
|
||
def run_submission!(submission, assignment, evaluation) | ||
results = submission.dry_run! assignment, evaluation | ||
assignment.assign_attributes results | ||
results | ||
end | ||
|
||
end | ||
|
||
Incognito = IncognitoClass.new | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'spec_helper' | ||
|
||
describe Mumuki::Domain::Incognito do | ||
let(:user) { Mumuki::Domain::Incognito } | ||
let(:organization) { create(:organization) } | ||
|
||
it 'can mock an AR relation' do | ||
Assignment.new submitter: user | ||
end | ||
|
||
describe 'ensure_enabled!' do | ||
it { expect { user.ensure_enabled! }.to_not raise_error } | ||
end | ||
|
||
describe 'assignment fooling' do | ||
let(:assignment) { user.build_assignment(exercise, organization) } | ||
|
||
context 'when exercise has no default content' do | ||
let(:exercise) { create(:exercise) } | ||
|
||
it { expect(assignment).to be_an Assignment } | ||
it { expect(assignment.submitter).to be user } | ||
it { expect(assignment.current_content).to eq '' } | ||
end | ||
|
||
context 'when exercise has default content' do | ||
let(:exercise) { create(:exercise, default_content: '...') } | ||
|
||
it { expect(assignment.current_content).to eq '...' } | ||
end | ||
end | ||
|
||
describe 'guide fooling' do | ||
let(:guide) { create(:guide, exercises: [ create(:exercise), create(:exercise) ]) } | ||
|
||
describe 'completion_percentage_for', organization_workspace: :test do | ||
it { expect(guide.completion_percentage_for(user)).to eq 0 } | ||
end | ||
|
||
describe 'next_exercise', organization_workspace: :test do | ||
# TODO this looks weird. Why do we need a non-polymorphic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently we aren't using indicators for this one as progress is shared between organizations. |
||
# next_exercise? Aren't indicators not enought? | ||
it { expect(guide.next_exercise(user)).to eq guide.exercises.first } | ||
end | ||
end | ||
|
||
describe 'exercise fooling' do | ||
let(:problem) { create(:problem) } | ||
|
||
describe 'next_for' do | ||
it { expect(problem.next_for(user)).to be nil } | ||
end | ||
|
||
describe 'try_submit_solution!', organization_workspace: :test do | ||
let!(:chapter) do | ||
create(:chapter, name: 'Functional Programming', lessons: [ | ||
create(:lesson, exercises: [problem]) | ||
]) | ||
end | ||
let(:bridge_response) { {result: '0 failures', status: :passed} } | ||
|
||
before { reindex_current_organization! } | ||
before { expect_any_instance_of(Language).to receive(:run_tests!).and_return(bridge_response) } | ||
|
||
let!(:assignment) { problem.try_submit_solution!(user) } | ||
|
||
it { expect(assignment).to_not be nil } | ||
it { expect(assignment.status).to be_like :passed } | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ordering logic it's related to
next_exercise
, not topending_exercises
.It's an important distinction because we'll use indicators to easily get pending_items but ordering logic is not included there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I had that doubt 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please review it again!