OSDN Git Service

日付の範囲をチェックするように修正
authorTaro Matsuzawa aka. btm <btm@tech.email.ne.jp>
Tue, 23 Aug 2011 08:46:26 +0000 (17:46 +0900)
committerTaro Matsuzawa aka. btm <btm@tech.email.ne.jp>
Tue, 23 Aug 2011 08:46:26 +0000 (17:46 +0900)
app/models/search_form.rb
spec/controllers/admin/products_controller_spec.rb
spec/models/search_form_spec.rb
spec/spec_helper.rb

index 3fbbbdf..f9192cd 100755 (executable)
@@ -99,6 +99,18 @@ class SearchForm < ActiveForm
       selected_time = true
     end
 
+    if not year.blank? and year.to_i <= 0
+      return
+    end
+
+    if not month.blank? and (month.to_i < 1 or month.to_i > 12)
+      return
+    end
+
+    if not day.blank? and (day.to_i < 1 or day.to_i > 31)
+      return
+    end
+
     now = DateTime.now
     if selected_date
       if year.blank?
index 9dfa96b..efadd1e 100644 (file)
@@ -106,6 +106,34 @@ describe Admin::ProductsController do
     end
   end
 
+  describe "GET 'search' でエラーになるケース" do
+    before do
+      @minus_value_start = ["-2000", "3", "24"]
+      @minus_value_end = ["-1999", "3", "24"]
+      @old_value_start = ["1800", "3", "24"]
+      @old_value_end = ["1801", "3", "24"]
+    end
+
+    it "sale_start_atにマイナスの日付" do
+      search = {}
+      search.merge! array_to_time(@minus_value_start, 'sale_start_at_start')
+      search.merge! array_to_time(@minus_value_end, 'sale_start_at_end')
+      get "search", :search => search
+    end
+    it "sale_start_atに古すぎる日付" do
+      search = {}
+      search.merge! array_to_time(@old_value_start, 'sale_start_at_start')
+      search.merge! array_to_time(@old_value_end, 'sale_start_at_end')
+      get "search", :search => search
+    end
+    
+    after do
+      response.should be_success
+    end
+
+  end
+
+
   describe "GET 'new'" do
     it "normal" do
       get 'new'
index 54b0100..45ee66f 100644 (file)
@@ -43,6 +43,11 @@ describe SearchForm do
       search_form.month.should_not be_nil
       search_form.month.should == Time.parse("2009-01-01 00:00:00")
     end
+    it "データセット(検索用年月日) 空文字でも正常に対応できるか確認" do
+      search_form = SearchForm.new({"month(1i)"=>"2009", "month(2i)" => ""})
+      search_form.month.should_not be_nil
+      search_form.month.should == Time.parse("2009-01-01 00:00:00")
+    end
     it "その他" do
       TestForm.human_attribute_name("customer_id").should == "顧客コード"
       TestForm.field_names.should == {"customer_id" => "顧客コード","customer_name" => "顧客名"}
index a438ab9..79a1a7f 100644 (file)
@@ -79,4 +79,11 @@ def datetime_to_select datetime, name
   }
 end
 
+def array_to_time array, name
+  {
+    name+'(1i)' => array[0],
+    name+'(2i)' => array[1],
+    name+'(3i)' => array[2]
+  }
+end