bring back shoulda-matchers and associated specs

The monkey-patch is necessary to allow shoulda-matchers > 3.0.1
to work with active_model-better_errors.  This essentially
provides a working grep implementation to ErrorMessageSet

test plan:
* Ensure specs pass

Change-Id: I1e4b490e98803a62293702fa38951f3dce5fcde4
Reviewed-on: https://gerrit.instructure.com/98513
Reviewed-by: Simon Williams <simon@instructure.com>
Reviewed-by: Derek Bender <djbender@instructure.com>
Product-Review: Keith T. Garner <kgarner@instructure.com>
QA-Review: Keith T. Garner <kgarner@instructure.com>
Tested-by: Jenkins
This commit is contained in:
Shahbaz Javeed 2016-12-28 08:11:18 -05:00
parent 2bbd3bff4f
commit 06ddfef3d3
9 changed files with 82 additions and 0 deletions

View File

@ -25,6 +25,7 @@ group :test do
gem 'rspec_around_all', '0.2.0' gem 'rspec_around_all', '0.2.0'
gem 'rspec-rails', '3.5.2' gem 'rspec-rails', '3.5.2'
gem 'rspec-collection_matchers', '1.1.3' gem 'rspec-collection_matchers', '1.1.3'
gem 'shoulda-matchers', '3.1.1'
gem 'rubocop-canvas', require: false, path: 'gems/rubocop-canvas' gem 'rubocop-canvas', require: false, path: 'gems/rubocop-canvas'
gem 'rubocop', '0.46.0', require: false gem 'rubocop', '0.46.0', require: false

View File

@ -105,6 +105,12 @@ module ActiveModel
end end
end end
class ErrorMessageSet
def grep(*args)
Array(find(args).first)
end
end
module AutosaveAssociation module AutosaveAssociation
def _ensure_no_duplicate_errors def _ensure_no_duplicate_errors
errors.error_collection.keys.each do |attribute| errors.error_collection.keys.each do |attribute|

View File

@ -4562,6 +4562,8 @@ describe Course, 'touch_root_folder_if_necessary' do
expect { course.broadcast_notifications }.to_not raise_error expect { course.broadcast_notifications }.to_not raise_error
end end
end end
it { is_expected.to have_many(:submission_comments).conditions(-> { published }) }
end end
describe Course, 'invited_count_visible_to' do describe Course, 'invited_count_visible_to' do

View File

@ -18,6 +18,8 @@
require_relative '../spec_helper' require_relative '../spec_helper'
describe GradebookCsv do describe GradebookCsv do
it { is_expected.to validate_presence_of(:progress) }
context "given a course with a teacher" do context "given a course with a teacher" do
def csv(course:, user:, force_failure: false) def csv(course:, user:, force_failure: false)
attachment = course.attachments.create!(uploaded_data: default_uploaded_data) attachment = course.attachments.create!(uploaded_data: default_uploaded_data)

View File

@ -24,6 +24,14 @@ describe GradingPeriodGroup do
let(:account) { Account.default } let(:account) { Account.default }
# after dev lands in master, re add this title validation
# it { is_expected.to validate_presence_of(:title) }
it { is_expected.to belong_to(:course) }
it { is_expected.to have_many(:enrollment_terms).inverse_of(:grading_period_group) }
it { is_expected.to have_many(:grading_periods).dependent(:destroy) }
it { is_expected.to allow_mass_assignment_of(:title) }
describe ".for" do describe ".for" do
context "when given a root account" do context "when given a root account" do
it "fetches sets on a root account" do it "fetches sets on a root account" do

View File

@ -16,6 +16,18 @@ describe ModeratedGrading::ProvisionalGrade do
it { is_expected.to be_valid } it { is_expected.to be_valid }
it do
is_expected.to have_one(:selection).
with_foreign_key(:selected_provisional_grade_id).
class_name('ModeratedGrading::Selection')
end
it { is_expected.to belong_to(:submission) }
it { is_expected.to belong_to(:scorer).class_name('User') }
it { is_expected.to have_many(:rubric_assessments) }
it { is_expected.to validate_presence_of(:scorer) }
it { is_expected.to validate_presence_of(:submission) }
describe 'grade_attributes' do describe 'grade_attributes' do
it "returns the proper format" do it "returns the proper format" do
json = provisional_grade.grade_attributes json = provisional_grade.grade_attributes

View File

@ -0,0 +1,29 @@
require 'spec_helper'
describe ModeratedGrading::Selection do
it { is_expected.to belong_to(:assignment) }
it do
is_expected.to belong_to(:provisional_grade).
with_foreign_key(:selected_provisional_grade_id).
class_name('ModeratedGrading::ProvisionalGrade')
end
it do
is_expected.to belong_to(:student).
class_name('User')
end
it "is restricted to one selection per assignment/student pair" do
# Setup an existing record for shoulda-matcher's uniqueness validation since we have
# not-null constraints
course = Course.create!
assignment = course.assignments.create!
student = User.create!
assignment.moderated_grading_selections.create! do |sel|
sel.student_id = student.id
end
is_expected.to validate_uniqueness_of(:student_id).scoped_to(:assignment_id)
end
end

View File

@ -3151,4 +3151,11 @@ describe User do
expect(@user.submissions_folder(@course)).to eq f expect(@user.submissions_folder(@course)).to eq f
end end
end end
it { is_expected.to have_many(:submission_comment_participants) }
it do
is_expected.to have_many(:submission_comments).
conditions(-> { published }).
through(:submission_comment_participants)
end
end end

View File

@ -936,3 +936,18 @@ end
Dir[Rails.root+'{gems,vendor}/plugins/*/spec_canvas/spec_helper.rb'].each do |f| Dir[Rails.root+'{gems,vendor}/plugins/*/spec_canvas/spec_helper.rb'].each do |f|
require f require f
end end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
# Choose one or more libraries:
with.library :active_record
with.library :active_model
# Disable the action_controller matchers until shoulda-matchers supports new compound matchers
# with.library :action_controller
# Or, choose the following (which implies all of the above):
# with.library :rails
end
end