From 120b052e7a84033a38bdac7e251fbc95e987a1ba Mon Sep 17 00:00:00 2001 From: Benjamin Porter Date: Thu, 29 Jan 2015 13:06:29 -0700 Subject: [PATCH] LearningOutcome model: Don't translate names of keys Fixes CNVS-18252 Test Plan: - Assess a student using an outcome - try to change the calculation_method and verify you get back a message that contains 'calculation_method' - repeat for 'calculation_int' Change-Id: I0f7a74911936a7cca8fa3e84cff96614c9c08a37 Reviewed-on: https://gerrit.instructure.com/47965 Tested-by: Jenkins Reviewed-by: Simon Williams QA-Review: Adam Stone Product-Review: Benjamin Porter --- app/models/learning_outcome.rb | 14 ++++++++++---- spec/apis/v1/outcome_groups_api_spec.rb | 4 ++-- spec/apis/v1/outcomes_api_spec.rb | 4 ++-- spec/models/learning_outcome_spec.rb | 14 +++++++------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/models/learning_outcome.rb b/app/models/learning_outcome.rb index a58da720cba..a767a4908ac 100644 --- a/app/models/learning_outcome.rb +++ b/app/models/learning_outcome.rb @@ -87,14 +87,16 @@ class LearningOutcome < ActiveRecord::Base # if we've been used to assess a student, refuse to accept any changes to our calculation options if calculation_method_changed? errors.add(:calculation_method, t( - "This outcome has been used to assess a student. Calculation method is fixed at %{old_value}", + "This outcome has been used to assess a student. '%{calc_int_method_name}' is fixed at %{old_value}", + :calc_int_method_name => "calculation_method", :old_value => calculation_method_was )) end if calculation_int_changed? errors.add(:calculation_int, t( - "This outcome has been used to assess a student. Calculation integer is fixed at %{old_value}", + "This outcome has been used to assess a student. '%{calc_int_key_name}' is fixed at %{old_value}", + :calc_int_key_name => "calculation_int", :old_value => calculation_int_was )) end @@ -104,13 +106,17 @@ class LearningOutcome < ActiveRecord::Base unless valid_calculation_int?(calculation_int, calculation_method) if valid_calculation_ints.to_a.empty? errors.add(:calculation_int, t( - "'calculation_int' is not used with calculation_method '%{calculation_method}'", + "'%{calc_int_key_name}' is not used with '%{calc_method_key_name}' '%{calculation_method}'", + :calc_int_key_name => "calculation_int", + :calc_method_key_name => "calculation_method", :calculation_method => calculation_method, )) else errors.add(:calculation_int, t( - "'%{calculation_int}' is not a valid calculation_int for calculation_method of '%{calculation_method}'. Valid range is '%{valid_calculation_ints}'", + "'%{calculation_int}' is not a valid '%{calc_int_key_name}' for '%{calc_method_key_name}' of '%{calculation_method}'. Valid range is '%{valid_calculation_ints}'", :calculation_int => calculation_int, + :calc_int_key_name => "calculation_int", + :calc_method_key_name => "calculation_method", :calculation_method => calculation_method, :valid_calculation_ints => valid_calculation_ints )) diff --git a/spec/apis/v1/outcome_groups_api_spec.rb b/spec/apis/v1/outcome_groups_api_spec.rb index d0d5ff623c2..529d9e0139e 100644 --- a/spec/apis/v1/outcome_groups_api_spec.rb +++ b/spec/apis/v1/outcome_groups_api_spec.rb @@ -1026,9 +1026,9 @@ describe "Outcome Groups API", type: :request do expect(json["errors"]["calculation_int"][0]).not_to be_nil expect(json["errors"]["calculation_int"][0]["message"]).not_to be_nil if %w[highest latest].include?(method) - expect(json["errors"]["calculation_int"][0]["message"]).to include("'calculation_int' is not used with calculation_method") + expect(json["errors"]["calculation_int"][0]["message"]).to include("'calculation_int' is not used with 'calculation_method'") else - expect(json["errors"]["calculation_int"][0]["message"]).to include("not a valid calculation_int") + expect(json["errors"]["calculation_int"][0]["message"]).to include("not a valid 'calculation_int'") end end end diff --git a/spec/apis/v1/outcomes_api_spec.rb b/spec/apis/v1/outcomes_api_spec.rb index b1318ce6095..e04b366308a 100644 --- a/spec/apis/v1/outcomes_api_spec.rb +++ b/spec/apis/v1/outcomes_api_spec.rb @@ -554,8 +554,8 @@ describe "Outcomes API", type: :request do "highest" => nil, "latest" => nil, } - norm_error_message = "not a valid calculation_int" - no_calc_int_error_message = "'calculation_int' is not used with calculation_method" + norm_error_message = "not a valid 'calculation_int'" + no_calc_int_error_message = "'calculation_int' is not used with 'calculation_method'" bad_calc_int = 1500 method_to_int.each do |method, int| diff --git a/spec/models/learning_outcome_spec.rb b/spec/models/learning_outcome_spec.rb index b9f402424e9..4cc877fa5d6 100644 --- a/spec/models/learning_outcome_spec.rb +++ b/spec/models/learning_outcome_spec.rb @@ -503,7 +503,7 @@ describe LearningOutcome do @outcome.save expect(@outcome).to have(1).error_on(:calculation_int) expect(@outcome).to have(1).errors - expect(outcome_errors(:calculation_int).first).to include("not a valid calculation_int") + expect(outcome_errors(:calculation_int).first).to include("not a valid 'calculation_int'") @outcome.reload expect(@outcome.calculation_method).to eq(method) expect(@outcome.calculation_int).to eq(4) @@ -581,9 +581,9 @@ describe LearningOutcome do expect(@outcome).to have(1).error expect(@outcome).to have(1).error_on(:calculation_int) if %w[highest latest].include?(method) - expect(outcome_errors(:calculation_int).first).to include("calculation_int' is not used with calculation_method") + expect(outcome_errors(:calculation_int).first).to include("'calculation_int' is not used with 'calculation_method'") else - expect(outcome_errors(:calculation_int).first).to include("not a valid calculation_int") + expect(outcome_errors(:calculation_int).first).to include("not a valid 'calculation_int'") end @outcome = LearningOutcome.new( @@ -595,9 +595,9 @@ describe LearningOutcome do expect(@outcome).to have(1).error expect(@outcome).to have(1).error_on(:calculation_int) if %w[highest latest].include?(method) - expect(outcome_errors(:calculation_int).first).to include("calculation_int' is not used with calculation_method") + expect(outcome_errors(:calculation_int).first).to include("'calculation_int' is not used with 'calculation_method'") else - expect(outcome_errors(:calculation_int).first).to include("not a valid calculation_int") + expect(outcome_errors(:calculation_int).first).to include("not a valid 'calculation_int'") end end end @@ -776,9 +776,9 @@ describe LearningOutcome do expect(@outcome).to have(1).error_on(:calculation_int) expect(@outcome).to have(1).errors if %w[highest latest].include? method - expect(outcome_errors(:calculation_int).first).to include("calculation_int' is not used with calculation_method") + expect(outcome_errors(:calculation_int).first).to include("'calculation_int' is not used with 'calculation_method'") else - expect(outcome_errors(:calculation_int).first).to include("not a valid calculation_int") + expect(outcome_errors(:calculation_int).first).to include("not a valid 'calculation_int'") end @outcome.reload expect(@outcome.calculation_method).to eq(method)