OSDN Git Service

add p_minus for quadratic equation and some validations
authorokimoto <okimoto@good-day.co.jp>
Thu, 18 Mar 2010 06:11:40 +0000 (15:11 +0900)
committerokimoto <okimoto@good-day.co.jp>
Thu, 18 Mar 2010 06:11:40 +0000 (15:11 +0900)
app/models/quadratic_equation_edit_form.rb
app/views/admin/problems/_quadratic_equation.html.erb
app/views/admin/problems/_quadratic_equation_edit_form.html.erb
spec/models/quadratic_equation_edit_form_spec.rb

index 3095927..92f5c52 100644 (file)
@@ -19,6 +19,7 @@ class QuadraticEquationEditForm < ActiveForm
   column :answer_type
   column :r_min, :type => :integer
   column :r_max, :type => :integer
+  column :p_minus, :type => :boolean
   column :p_min, :type => :integer
   column :p_max, :type => :integer
   column :q_min, :type => :integer
@@ -48,6 +49,7 @@ class QuadraticEquationEditForm < ActiveForm
       :answer_type => answer_type,
       :r_min       => r_min,
       :r_max       => r_max,
+      :p_minus     => p_minus,
       :p_min       => p_min,
       :p_max       => p_max,
       :q_min       => q_min,
@@ -60,6 +62,7 @@ class QuadraticEquationEditForm < ActiveForm
     self.answer_type = hash["answer_type"]
     self.r_min       = hash["r_min"]
     self.r_max       = hash["r_max"]
+    self.p_minus     = hash["p_minus"]
     self.p_min       = hash["p_min"]
     self.p_max       = hash["p_max"]
     self.q_min       = hash["q_min"]
@@ -67,5 +70,8 @@ class QuadraticEquationEditForm < ActiveForm
   end
 
   def validate
+    check_min_max(:p_min, :p_max)
+    check_min_max(:q_min, :q_max)
+    check_min_max(:r_min, :r_max)
   end
 end
index eb8fbc2..844830c 100644 (file)
@@ -1,6 +1,6 @@
 <table class="problem">
   <%= render :partial => "common" %>
   <%= render :partial => "minus_min_max", :locals => { :prefix => "r_", :minus => false } %>
-  <%= render :partial => "minus_min_max", :locals => { :prefix => "p_", :minus => false } %>
+  <%= render :partial => "minus_min_max", :locals => { :prefix => "p_", :minus => true } %>
   <%= render :partial => "minus_min_max", :locals => { :prefix => "q_", :minus => false } %>
 </table>
index 2162d82..adec6ca 100644 (file)
@@ -1,6 +1,6 @@
 <table class="problem">
   <%= render :partial => "common_edit_form", :locals => { :f => f } %>
   <%= render :partial => "minus_min_max_edit_form", :locals => { :f => f, :prefix => "r_", :minus => false } %>
-  <%= render :partial => "minus_min_max_edit_form", :locals => { :f => f, :prefix => "p_", :minus => false } %>
+  <%= render :partial => "minus_min_max_edit_form", :locals => { :f => f, :prefix => "p_", :minus => true } %>
   <%= render :partial => "minus_min_max_edit_form", :locals => { :f => f, :prefix => "q_", :minus => false } %>
 </table>
index 764bc5a..edad9bf 100644 (file)
@@ -9,6 +9,7 @@ describe QuadraticEquationEditForm do
       :answer_type => "rational",
       :r_min       => 1,
       :r_max       => 10,
+      :p_minus     => true,
       :p_min       => 0,
       :p_max       => 20,
       :q_min       => 0,
@@ -58,6 +59,34 @@ describe QuadraticEquationEditForm do
       end
     end
 
+    context "relation" do
+      context "p" do
+        before do
+          @target_left = :p_min
+          @target_right = :p_max
+          @message = "P min must be greater than P max."
+        end
+        it_should_behave_like "check_min_max"
+      end
+
+      context "q" do
+        before do
+          @target_left = :q_min
+          @target_right = :q_max
+          @message = "Q min must be greater than Q max."
+        end
+        it_should_behave_like "check_min_max"
+      end
+
+      context "r" do
+        before do
+          @target_left = :r_min
+          @target_right = :r_max
+          @message = "R min must be greater than R max."
+        end
+        it_should_behave_like "check_min_max"
+      end
+    end
   end
 
   context "options_hash" do
@@ -67,6 +96,7 @@ describe QuadraticEquationEditForm do
         :answer_type => "rational",
         :r_min       => 1,
         :r_max       => 10,
+        :p_minus     => true,
         :p_min       => 0,
         :p_max       => 20,
         :q_min       => 0,
@@ -82,6 +112,7 @@ describe QuadraticEquationEditForm do
           :answer_type => "irrational",
           :r_min       => 1,
           :r_max       => 11,
+          :p_minus     => true,
           :p_min       => 2,
           :p_max       => 21,
           :q_min       => 2,
@@ -93,6 +124,7 @@ describe QuadraticEquationEditForm do
       its(:answer_type){ should == "irrational" }
       its(:r_min){ should == 1  }
       its(:r_max){ should == 11 }
+      its(:p_minus){ should be_true }
       its(:p_min){ should == 2  }
       its(:p_max){ should == 21 }
       its(:q_min){ should == 2  }