replace association with association_object in models

having an "association" attribute causes problems in rails 3

Change-Id: I3249a25cd2a6162ff33f548a2e9f4f51a2940ece
Reviewed-on: https://gerrit.instructure.com/29058
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
QA-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2014-01-22 10:54:27 -07:00
parent 6213161926
commit 0cedba19f8
18 changed files with 59 additions and 59 deletions

View File

@ -74,7 +74,7 @@ class RubricAssessmentsController < ApplicationController
def update
@association = @context.rubric_associations.find(params[:rubric_association_id])
@assessment = @association.rubric_assessments.find_by_id(params[:id])
@association_object = @association.association
@association_object = @association.association_object
# only check if there's no @assessment object, since that's the only time
# this param matters (assessing_user_id and arg find_asset_for_assessment)

View File

@ -36,8 +36,8 @@ class RubricAssociationsController < ApplicationController
if params[:rubric] && @rubric.grants_rights?(@current_user, session, :update)[:update]
@rubric.update_criteria(params[:rubric])
end
params[:rubric_association][:association] = @association.association if @association
params[:rubric_association][:association] ||= @association_object
params[:rubric_association][:association_object] = @association.association_object if @association
params[:rubric_association][:association_object] ||= @association_object
params[:rubric_association][:id] = @association.id if @association
@association = RubricAssociation.generate(@current_user, @rubric, @context, params[:rubric_association])
json_res = {

View File

@ -59,8 +59,8 @@ class RubricsController < ApplicationController
params[:rubric][:user] = @current_user if params[:rubric]
if (!@association_object || authorized_action(@association_object, @current_user, :read)) && authorized_action(@context, @current_user, :manage_rubrics)
@association = @context.rubric_associations.find_by_id(params[:rubric_association_id]) if params[:rubric_association_id].present?
@association_object ||= @association.association if @association
params[:rubric_association][:association] = @association_object
@association_object ||= @association.association_object if @association
params[:rubric_association][:association_object] = @association_object
params[:rubric_association][:update_if_existing] = params[:action] == 'update'
skip_points_update = !!(params[:skip_updating_points_possible] =~ /true/i)
params[:rubric_association][:skip_updating_points_possible] = skip_points_update

View File

@ -24,14 +24,14 @@ class LearningOutcomeResult < ActiveRecord::Base
belongs_to :user
belongs_to :learning_outcome
belongs_to :alignment, :class_name => 'ContentTag', :foreign_key => :content_tag_id
belongs_to :association, :polymorphic => true
belongs_to :association_object, :polymorphic => true, :foreign_type => :association_type, :foreign_key => :association_id
belongs_to :artifact, :polymorphic => true
belongs_to :associated_asset, :polymorphic => true
belongs_to :context, :polymorphic => true
simply_versioned
before_save :infer_defaults
attr_accessible :learning_outcome, :user, :association, :alignment, :associated_asset
attr_accessible :learning_outcome, :user, :association_object, :alignment, :associated_asset
def infer_defaults
self.learning_outcome_id = self.alignment.learning_outcome_id
@ -45,10 +45,10 @@ class LearningOutcomeResult < ActiveRecord::Base
end
def assignment
if self.association.is_a?(Assignment)
self.association
if self.association_object.is_a?(Assignment)
self.association_object
elsif self.artifact.is_a?(RubricAssessment)
self.artifact.rubric_association.association
self.artifact.rubric_association.association_object
else
nil
end

View File

@ -162,7 +162,7 @@ class Rubric < ActiveRecord::Base
return res if res
end
purpose = opts[:purpose] || "unknown"
self.rubric_associations.create(:association => association, :context => context, :use_for_grading => !!opts[:use_for_grading], :purpose => purpose)
self.rubric_associations.create(:association_object => association, :context => context, :use_for_grading => !!opts[:use_for_grading], :purpose => purpose)
end
def update_with_association(current_user, rubric_params, context, association_params)
@ -170,7 +170,7 @@ class Rubric < ActiveRecord::Base
self.user ||= current_user
rubric_params[:hide_score_total] ||= association_params[:hide_score_total]
self.update_criteria(rubric_params)
RubricAssociation.generate(current_user, self, context, association_params) if association_params[:association] || association_params[:url]
RubricAssociation.generate(current_user, self, context, association_params) if association_params[:association_object] || association_params[:url]
end
def unique_item_id(id=nil)

View File

@ -48,7 +48,7 @@ class RubricAssessment < ActiveRecord::Base
def update_outcomes_for_assessment(outcome_ids=[])
return if outcome_ids.empty?
alignments = self.rubric_association.association.learning_outcome_alignments.find_all_by_learning_outcome_id(outcome_ids)
alignments = self.rubric_association.association_object.learning_outcome_alignments.find_all_by_learning_outcome_id(outcome_ids)
(self.data || []).each do |rating|
if rating[:learning_outcome_id]
alignments.each do |alignment|
@ -134,7 +134,7 @@ class RubricAssessment < ActiveRecord::Base
if self.artifact_type == 'Submission' && self.artifact
Submission.where(:id => self.artifact).update_all(:has_rubric_assessment => true)
if self.rubric_association && self.rubric_association.use_for_grading && self.artifact.score != self.score
if self.rubric_association.association.grants_right?(self.assessor, nil, :grade)
if self.rubric_association.association_object.grants_right?(self.assessor, nil, :grade)
# TODO: this should go through assignment.grade_student to
# handle group assignments.
self.artifact.workflow_state = 'graded'
@ -161,7 +161,7 @@ class RubricAssessment < ActiveRecord::Base
given {|user, session|
self.rubric_association &&
self.rubric_association.grants_rights?(user, session, :manage)[:manage] &&
(self.rubric_association.association.context.grants_right?(self.assessor, nil, :manage_rubrics) rescue false)
(self.rubric_association.association_object.context.grants_right?(self.assessor, nil, :manage_rubrics) rescue false)
}
can :update
end
@ -189,10 +189,10 @@ class RubricAssessment < ActiveRecord::Base
end
def related_group_submissions_and_assessments
if self.rubric_association && self.rubric_association.association.is_a?(Assignment) && !self.rubric_association.association.grade_group_students_individually
students = self.rubric_association.association.group_students(self.user).last
if self.rubric_association && self.rubric_association.association_object.is_a?(Assignment) && !self.rubric_association.association_object.grade_group_students_individually
students = self.rubric_association.association_object.group_students(self.user).last
submissions = students.map do |student|
submission = self.rubric_association.association.find_asset_for_assessment(self.rubric_association, student.id).first
submission = self.rubric_association.association_object.find_asset_for_assessment(self.rubric_association, student.id).first
{:submission => submission, :rubric_assessments => submission.rubric_assessments.map{|ra| ra.as_json(:methods => :assessor_name)}}
end
else

View File

@ -22,9 +22,9 @@
# The other purpose of this class is just to make rubrics reusable.
class RubricAssociation < ActiveRecord::Base
attr_accessor :skip_updating_points_possible
attr_accessible :rubric, :association, :context, :use_for_grading, :title, :description, :summary_data, :purpose, :url, :hide_score_total, :bookmarked
attr_accessible :rubric, :association_object, :context, :use_for_grading, :title, :description, :summary_data, :purpose, :url, :hide_score_total, :bookmarked
belongs_to :rubric
belongs_to :association, :polymorphic => true
belongs_to :association_object, :polymorphic => true, :foreign_type => :association_type, :foreign_key => :association_id
belongs_to :context, :polymorphic => true
has_many :rubric_assessments, :dependent => :nullify
@ -90,8 +90,8 @@ class RubricAssociation < ActiveRecord::Base
end
def assignment
if self.association.is_a?(Assignment)
self.association
if self.association_object.is_a?(Assignment)
self.association_object
else
nil
end
@ -123,7 +123,7 @@ class RubricAssociation < ActiveRecord::Base
def update_values
self.bookmarked = true if self.purpose == 'bookmark' || self.bookmarked.nil?
self.context_code ||= "#{self.context_type.underscore}_#{self.context_id}" rescue nil
self.title ||= (self.association.title rescue self.association.name) rescue nil
self.title ||= (self.association_object.title rescue self.association_object.name) rescue nil
end
protected :update_values
@ -141,8 +141,8 @@ class RubricAssociation < ActiveRecord::Base
end
def update_assignment_points
if self.use_for_grading && !self.skip_updating_points_possible && self.association && self.association.respond_to?(:points_possible=) && self.rubric && self.rubric.points_possible && self.association.points_possible != self.rubric.points_possible
self.association.update_attribute(:points_possible, self.rubric.points_possible)
if self.use_for_grading && !self.skip_updating_points_possible && self.association_object && self.association_object.respond_to?(:points_possible=) && self.rubric && self.rubric.points_possible && self.association_object.points_possible != self.rubric.points_possible
self.association_object.update_attribute(:points_possible, self.rubric.points_possible)
end
end
protected :update_assignment_points
@ -176,7 +176,7 @@ class RubricAssociation < ActiveRecord::Base
# Update each submission's assessment_requests with a link to this rubric association
# but only if not already associated and the assessment is incomplete.
if self.association_id && self.association_type == 'Assignment'
self.association.submissions.each do |sub|
self.association_object.submissions.each do |sub|
sub.assessment_requests.incomplete.where(:rubric_association_id => nil).
update_all(:rubric_association_id => self)
end
@ -190,11 +190,11 @@ class RubricAssociation < ActiveRecord::Base
def self.generate(current_user, rubric, context, params)
raise "context required" unless context
association_object = params.delete :association
association_object = params.delete :association_object
if (association_id = params.delete(:id)) && association_id.present?
association = RubricAssociation.find_by_id(association_id)
end
association = nil unless association && association.context == context && association.association == association_object
association = nil unless association && association.context == context && association.association_object == association_object
raise "association required" unless association || association_object
# Update/create the association -- this is what ties the rubric to an entity
update_if_existing = params.delete(:update_if_existing)
@ -203,12 +203,12 @@ class RubricAssociation < ActiveRecord::Base
association.context = context
association.skip_updating_points_possible = params.delete :skip_updating_points_possible
association.update_attributes(params)
association.association = association_object
association.association_object = association_object
association
end
def assessments_unique_per_asset?(assessment_type)
self.association.is_a?(Assignment) && self.purpose == "grading" && assessment_type == "grading"
self.association_object.is_a?(Assignment) && self.purpose == "grading" && assessment_type == "grading"
end
def assess(opts={})
@ -222,10 +222,10 @@ class RubricAssociation < ActiveRecord::Base
raise "Artifact required for assessing" unless opts[:artifact]
raise "Assessment type required for assessing" unless params[:assessment_type]
if self.association.is_a?(Assignment) && !self.association.grade_group_students_individually
students_to_assess = self.association.group_students(opts[:artifact].user).last
if self.association_object.is_a?(Assignment) && !self.association_object.grade_group_students_individually
students_to_assess = self.association_object.group_students(opts[:artifact].user).last
artifacts_to_assess = students_to_assess.map do |student|
self.association.find_asset_for_assessment(self, student).first
self.association_object.find_asset_for_assessment(self, student).first
end
else
artifacts_to_assess = [opts[:artifact]]

View File

@ -42,7 +42,7 @@ module CC
rubric = assoc.rubric
next if rubric.nil? || !rubric.active? || imported_rubrics[rubric.id]
if !export_object?(rubric)
if assoc.association_type != "Assignment" || !export_object?(assoc.association)
if assoc.association_type != "Assignment" || !export_object?(assoc.association_object)
next
end
end

View File

@ -103,8 +103,8 @@ describe RubricAssessmentsController do
rubric_association_model(:user => @user, :context => @course)
assessor = User.create!
@course.enroll_student(assessor)
assessor_asset = @rubric_association.association.find_or_create_submission(assessor)
user_asset = @rubric_association.association.find_or_create_submission(assessor)
assessor_asset = @rubric_association.association_object.find_or_create_submission(assessor)
user_asset = @rubric_association.association_object.find_or_create_submission(assessor)
@assessment_request = @rubric_association.assessment_requests.create!(user: @user, asset: user_asset, assessor: assessor, assessor_asset: assessor_asset)
end
@ -228,7 +228,7 @@ def setup_course_assessment
@course.enroll_student(@student3).accept!
@course.enroll_teacher(@teacher2).accept!
@assignment = @course.assignments.create!(:title => "Some Assignment")
rubric_assessment_model(:user => @user, :context => @course, :association => @assignment, :purpose => 'grading')
rubric_assessment_model(:user => @user, :context => @course, :association_object => @assignment, :purpose => 'grading')
student1_asset = @assignment.find_or_create_submission(@student1)
student2_asset = @assignment.find_or_create_submission(@student2)
student3_asset = @assignment.find_or_create_submission(@student3)

View File

@ -29,7 +29,7 @@ describe RubricAssociationsController do
it "should assign variables" do
course_with_teacher_logged_in(:active_all => true)
rubric_association_model(:user => @user, :context => @course)
post 'create', :course_id => @course.id, :rubric_association => {:rubric_id => @rubric.id, :title => "some association", :association_type => @rubric_association.association.class.name, :association_id => @rubric_association.association.id}
post 'create', :course_id => @course.id, :rubric_association => {:rubric_id => @rubric.id, :title => "some association", :association_type => @rubric_association.association_object.class.name, :association_id => @rubric_association.association_object.id}
assigns[:association].should_not be_nil
assigns[:association].title.should eql("some association")
response.should be_success

View File

@ -195,7 +195,7 @@ describe RubricsController do
it "should not update the rubric if not updateable (should make a new one instead)" do
course_with_teacher_logged_in(:active_all => true)
rubric_association_model(:user => @user, :context => @course, :purpose => 'grading')
@rubric.rubric_associations.create!(:purpose => 'grading', :context => @course, :association => @course)
@rubric.rubric_associations.create!(:purpose => 'grading', :context => @course, :association_object => @course)
put 'update', :course_id => @course.id, :id => @rubric.id, :rubric => {:title => "new title"}, :rubric_association_id => @rubric_association.id
assigns[:rubric].should_not eql(@rubric)
assigns[:rubric].should_not be_new_record
@ -233,7 +233,7 @@ describe RubricsController do
}
@rubric.update_criteria(params)
@rubric.save!
@rubric.rubric_associations.create!(:purpose => 'grading', :context => @course, :association => @course)
@rubric.rubric_associations.create!(:purpose => 'grading', :context => @course, :association_object => @course)
criteria = @rubric.criteria
put 'update', :course_id => @course.id, :id => @rubric.id, :rubric => params, :rubric_association_id => @rubric_association.id
assigns[:rubric].should eql(@rubric)
@ -264,7 +264,7 @@ describe RubricsController do
it "should update the association if specified" do
course_with_teacher_logged_in(:active_all => true)
rubric_association_model(:user => @user, :context => @course)
put 'update', :course_id => @course.id, :id => @rubric.id, :rubric => {:title => "new title"}, :rubric_association => {:association_type => @rubric_association.association.class.to_s, :association_id => @rubric_association.association.id, :title => "some title", :id => @rubric_association.id}
put 'update', :course_id => @course.id, :id => @rubric.id, :rubric => {:title => "new title"}, :rubric_association => {:association_type => @rubric_association.association_object.class.to_s, :association_id => @rubric_association.association_object.id, :title => "some title", :id => @rubric_association.id}
assigns[:rubric].should eql(@rubric)
assigns[:rubric].title.should eql("new title")
assigns[:association].should eql(@rubric_association)
@ -481,7 +481,7 @@ describe RubricsController do
Account.default.add_user(@user, 'AccountAdmin')
@rubric = Rubric.create!(:user => @user, :context => @course)
RubricAssociation.create!(:rubric => @rubric, :context => @course, :purpose => :bookmark, :association => @course)
RubricAssociation.create!(:rubric => @rubric, :context => @course, :purpose => :bookmark, :association_object => @course)
@course.rubric_associations.bookmarked.include_rubric.to_a.select(&:rubric_id).once_per(&:rubric_id).sort_by{|a| a.rubric.title }.map(&:rubric).should == [@rubric]
delete 'destroy', :course_id => @course.id, :id => @rubric.id
@ -497,8 +497,8 @@ describe RubricsController do
@user.reload
@rubric = Rubric.create!(:user => @user, :context => Account.default)
RubricAssociation.create!(:rubric => @rubric, :context => @course, :purpose => :bookmark, :association => @course)
RubricAssociation.create!(:rubric => @rubric, :context => Account.default, :purpose => :bookmark, :association => @course)
RubricAssociation.create!(:rubric => @rubric, :context => @course, :purpose => :bookmark, :association_object => @course)
RubricAssociation.create!(:rubric => @rubric, :context => Account.default, :purpose => :bookmark, :association_object => @course)
@course.rubric_associations.bookmarked.include_rubric.to_a.select(&:rubric_id).once_per(&:rubric_id).sort_by{|a| a.rubric.title }.map(&:rubric).should == [@rubric]
delete 'destroy', :course_id => @course.id, :id => @rubric.id
@ -528,7 +528,7 @@ describe RubricsController do
it "works" do
r = Rubric.create! user: @teacher, context: Account.default
ra = RubricAssociation.create! rubric: r, context: @course,
purpose: :bookmark, association: @course
purpose: :bookmark, association_object: @course
get 'show', id: r.id, course_id: @course.id
response.should be_success
end

View File

@ -18,7 +18,7 @@
def rubric_assessment_model(opts={})
rubric_association_model(opts)
@rubric_assessment = @rubric_association.rubric_assessments.create!(:user => opts[:user], :assessor => opts[:user], :rubric => @rubric, :artifact => @rubric_association.association, :assessment_type => opts[:assessment_type] || 'no_reason')
@rubric_assessment = @rubric_association.rubric_assessments.create!(:user => opts[:user], :assessor => opts[:user], :rubric => @rubric, :artifact => @rubric_association.association_object, :assessment_type => opts[:assessment_type] || 'no_reason')
end
def valid_rubric_assessment_attributes

View File

@ -20,7 +20,7 @@ def rubric_association_model(opts={})
course_model(:reusable => true) unless @course || opts[:context]
@rubric = opts[:rubric] || rubric_model(:context => opts[:context] || @course)
@rubric_association_object = @course.assignments.first || @course.assignments.create!(assignment_valid_attributes)
@rubric_association = @rubric.rubric_associations.create!(valid_rubric_assessment_attributes.merge(:association => opts[:association] || @rubric_association_object, :context => opts[:context] || @course, :purpose => opts[:purpose] || "none"))
@rubric_association = @rubric.rubric_associations.create!(valid_rubric_assessment_attributes.merge(:association_object => opts[:association_object] || @rubric_association_object, :context => opts[:context] || @course, :purpose => opts[:purpose] || "none"))
end
def valid_rubric_assessment_attributes

View File

@ -418,7 +418,7 @@ describe "Canvas Cartridge importing" do
rubric2.data = [{:ratings=>[{:criterion_id=>"309_6312", :points=>5, :description=>"Full Marks", :id=>"blank", :long_description=>""}, {:criterion_id=>"309_6312", :points=>0, :description=>"No Marks", :id=>"blank_2", :long_description=>""}], :points=>5, :description=>"Description of criterion", :id=>"309_6312", :long_description=>""}, {:ignore_for_scoring=>false, :mastery_points=>3, :learning_outcome_id=>lo.id, :ratings=>[{:criterion_id=>"309_343", :points=>5, :description=>"Exceeds Expectations", :id=>"309_6516", :long_description=>""}, {:criterion_id=>"309_343", :points=>0, :description=>"Does Not Meet Expectations", :id=>"309_9962", :long_description=>""}], :points=>5, :description=>"Learning Outcome", :id=>"309_343", :long_description=>"<p>Outcome</p>"}]
rubric2.save!
assoc = RubricAssociation.create!(:context => @copy_from, :rubric => rubric2, :association => @copy_from, :title => rubric2.title, :purpose => 'bookmark')
assoc = RubricAssociation.create!(:context => @copy_from, :rubric => rubric2, :association_object => @copy_from, :title => rubric2.title, :purpose => 'bookmark')
#export to xml
builder = Builder::XmlMarkup.new(:indent=>2)

View File

@ -24,7 +24,7 @@ describe DataFixup::FixOutOfSyncOutcomeAlignments do
outcome_with_rubric
@rubric_association_object = @course.assignments.create!(:title => 'blah')
@rubric_association = @rubric.rubric_associations.create!({
:association => @rubric_association_object,
:association_object => @rubric_association_object,
:context => @course,
:purpose => 'grading'
})

View File

@ -24,7 +24,7 @@ describe DataFixup::UndeleteSomeOutcomeAlignments do
outcome_with_rubric
@rubric_association_object = @course.assignments.create!(:title => 'blah')
@rubric_association = @rubric.rubric_associations.create!({
:association => @rubric_association_object,
:association_object => @rubric_association_object,
:context => @course,
:purpose => 'grading'
})

View File

@ -28,7 +28,7 @@ describe RubricAssociation do
skip_updating_points_possible: false,
update_if_existing: true,
use_for_grading: "1",
association: assign
association_object: assign
})
end
@ -106,7 +106,7 @@ describe RubricAssociation do
rubric = @course.rubrics.create!
ra = RubricAssociation.create!(
:rubric => rubric,
:association => @course,
:association_object => @course,
:context => @course,
:purpose => 'bookmark'
)
@ -122,7 +122,7 @@ describe RubricAssociation do
)
outcome_with_rubric
ra = @rubric.rubric_associations.create!(
:association => assignment,
:association_object => assignment,
:context => @course,
:purpose => 'grading'
)
@ -141,7 +141,7 @@ describe RubricAssociation do
)
outcome_with_rubric
ra = @rubric.rubric_associations.create!(
:association => assignment,
:association_object => assignment,
:context => @course,
:purpose => 'grading'
)
@ -170,7 +170,7 @@ describe RubricAssociation do
@account = @user.account
@rubric = @account.rubrics.build
rubric_params = HashWithIndifferentAccess.new({"title"=>"Some Rubric", "criteria"=>{"0"=>{"learning_outcome_id"=>"", "ratings"=>{"0"=>{"points"=>"5", "id"=>"blank", "description"=>"Full Marks"}, "1"=>{"points"=>"0", "id"=>"blank_2", "description"=>"No Marks"}}, "points"=>"5", "long_description"=>"", "id"=>"", "description"=>"Description of criterion"}}, "points_possible"=>"5", "free_form_criterion_comments"=>"0"})
rubric_association_params = HashWithIndifferentAccess.new({:association=>@account, :hide_score_total=>"0", :use_for_grading=>"0", :purpose=>"bookmark"})
rubric_association_params = HashWithIndifferentAccess.new({:association_object=>@account, :hide_score_total=>"0", :use_for_grading=>"0", :purpose=>"bookmark"})
#8864: the below raised a MethodNotFound error by trying to call @account.submissions
lambda { @rubric.update_with_association(@user, rubric_params, @account, rubric_association_params) }.should_not raise_error
end
@ -181,7 +181,7 @@ describe RubricAssociation do
course_with_teacher(:active_all => true)
@rubric = @course.rubrics.build
rubric_params = HashWithIndifferentAccess.new({"title"=>"Some Rubric", "criteria"=>{"0"=>{"learning_outcome_id"=>"", "ratings"=>{"0"=>{"points"=>"5", "id"=>"blank", "description"=>"Full Marks"}, "1"=>{"points"=>"0", "id"=>"blank_2", "description"=>"No Marks"}}, "points"=>"5", "long_description"=>"", "id"=>"", "description"=>"Description of criterion"}}, "points_possible"=>"5", "free_form_criterion_comments"=>"0"})
rubric_association_params = HashWithIndifferentAccess.new({:association=>@course, :hide_score_total=>"0", :use_for_grading=>"0", :purpose=>"bookmark"})
rubric_association_params = HashWithIndifferentAccess.new({:association_object=>@course, :hide_score_total=>"0", :use_for_grading=>"0", :purpose=>"bookmark"})
@course.any_instantiation.expects(:submissions).never
@rubric.update_with_association(@user, rubric_params, @course, rubric_association_params)
end

View File

@ -37,7 +37,7 @@ describe "/discussion_topics/show" do
it "should render in a group context" do
assignment_model(:submission_types => 'discussion_topic')
rubric_association_model(:association => @assignment, :purpose => 'grading')
rubric_association_model(:association_object => @assignment, :purpose => 'grading')
group_model
view_context(@group, @user)
@topic = @assignment.discussion_topic