acts_as_problem
column :answer_type
+ column :r_min, :type => :integer
column :r_max, :type => :integer
+ column :p_min, :type => :integer
column :p_max, :type => :integer
+ column :q_min, :type => :integer
column :q_max, :type => :integer
validates_presence_of :answer_type
validates_inclusion_of :answer_type, :in => %w[rational irrational imaginary]
+ validates_presence_of :r_min
validates_presence_of :r_max
+ validates_presence_of :p_min
validates_presence_of :p_max
+ validates_presence_of :q_min
validates_presence_of :q_max
with_options :only_integer => true, :allow_blank => true do |problem|
+ problem.validates_numericality_of :r_min, :greater_than_or_equal_to => 1
problem.validates_numericality_of :r_max, :greater_than_or_equal_to => 1
+ problem.validates_numericality_of :p_min, :greater_than_or_equal_to => 0
problem.validates_numericality_of :p_max, :greater_than_or_equal_to => 0
+ problem.validates_numericality_of :q_min, :greater_than_or_equal_to => 0
problem.validates_numericality_of :q_max, :greater_than_or_equal_to => 0
end
def options_hash
{
:answer_type => answer_type,
+ :r_min => r_min,
:r_max => r_max,
+ :p_min => p_min,
:p_max => p_max,
+ :q_min => q_min,
:q_max => q_max,
}
end
def set_options(options)
hash = ActiveSupport::JSON.decode(options)
self.answer_type = hash["answer_type"]
+ self.r_min = hash["r_min"]
self.r_max = hash["r_max"]
+ self.p_min = hash["p_min"]
self.p_max = hash["p_max"]
+ self.q_min = hash["q_min"]
self.q_max = hash["q_max"]
end
:level => 1,
:amount => 2,
:answer_type => "rational",
+ :r_min => 1,
:r_max => 10,
+ :p_min => 0,
:p_max => 20,
+ :q_min => 0,
:q_max => 30,
}
@klass = QuadraticEquationEditForm
end
[
+ [:p_min, -1, 0],
[:p_max, -1, 0],
+ [:q_min, -1, 0],
[:q_max, -1, 0],
+ [:r_min, 0, 1],
[:r_max, 0, 1],
].each do |target, ng, ok|
context target do
it{
should == {
:answer_type => "rational",
+ :r_min => 1,
:r_max => 10,
+ :p_min => 0,
:p_max => 20,
+ :q_min => 0,
:q_max => 30,
}
}
subject{
options = {
:answer_type => "irrational",
+ :r_min => 1,
:r_max => 11,
+ :p_min => 2,
:p_max => 21,
+ :q_min => 2,
:q_max => 31,
}
@basic.set_options(options.to_json)
@basic
}
its(:answer_type){ should == "irrational" }
+ its(:r_min){ should == 1 }
its(:r_max){ should == 11 }
+ its(:p_min){ should == 2 }
its(:p_max){ should == 21 }
+ its(:q_min){ should == 2 }
its(:q_max){ should == 31 }
end
context "set nothing" do