spec/riveter/attributes_spec.rb in riveter-0.0.6 vs spec/riveter/attributes_spec.rb in riveter-0.0.7

- old
+ new

@@ -58,10 +58,47 @@ it { instance.should validate_timeliness_of(:an_attribute) } end end + it_should_behave_like "an attribute", :date_range, Date.new(2010, 1, 12)..Date.new(2012, 1, 11) do + describe "additional" do + before do + subject.attr_date_range :an_attribute + end + let(:instance) { subject.new() } + + it { instance.should validate_date_range_of(:an_attribute) } + it { instance.should validate_timeliness_of(:an_attribute_from) } + it { instance.should validate_timeliness_of(:an_attribute_to) } + + it { instance.should respond_to(:an_attribute_from?) } + + it { + instance.an_attribute = nil + instance.an_attribute_from?.should be_false + } + + it { + instance.an_attribute_from = Date.today + instance.an_attribute_from?.should be_true + } + + it { instance.should respond_to(:an_attribute_to?) } + + it { + instance.an_attribute = nil + instance.an_attribute_to?.should be_false + } + + it { + instance.an_attribute_to = Date.today + instance.an_attribute_to?.should be_true + } + end + end + it_should_behave_like "an attribute", :time, Time.new(2010, 1, 12, 8, 4, 45) do let(:assigned_value) { '2010-01-12 08:04:12' } let(:expected_value) { Time.new(2010, 1, 12, 8, 4, 12) } describe "additional" do @@ -75,19 +112,10 @@ end it_should_behave_like "an attribute", :boolean, true do let(:assigned_value) { '0' } let(:expected_value) { false } - - describe "additional" do - before do - subject.attr_boolean :an_attribute - end - let(:instance) { subject.new() } - - it { instance.should validate_booleaness_of(:an_attribute) } - end end it_should_behave_like "an attribute", :enum, TestEnum::Member1, TestEnum do let(:assigned_value) { 'Member2' } let(:expected_value) { TestEnum::Member2 } @@ -96,11 +124,11 @@ before do subject.attr_enum :product_type, TestEnum, :required => true end let(:instance) { subject.new() } - it { instance.should ensure_inclusion_of(:product_type).in_array(TestEnum.all) } + it { instance.should ensure_inclusion_of(:product_type).in_array(TestEnum.values) } it { should respond_to(:product_type_enum)} it { subject.product_type_enum.should eq(TestEnum) } it { should respond_to(:product_types)} it { subject.product_types.should eq(TestEnum.collection)} @@ -165,10 +193,13 @@ subject.string.should eq('A') subject.text.should eq('b') subject.integer.should eq(1) subject.decimal.should eq(9.998) subject.date.should eq(Date.new(2010, 1, 12)) + subject.date_range.should eq(Date.new(2010, 1, 12)..Date.new(2011, 1, 12)) + subject.date_range_from.should eq(Date.new(2010, 1, 12)) + subject.date_range_to.should eq(Date.new(2011, 1, 12)) subject.time.should eq(Time.new(2010, 1, 12, 14, 56)) subject.boolean.should eq(true) subject.enum.should eq(TestEnum::Member1) subject.array.should eq([1, 2, 3]) subject.hash.should eq({:a => :b}) @@ -185,9 +216,12 @@ 'string' => 'A', 'text' => 'b', 'integer' => 1, 'decimal' => 9.998, 'date' => Date.new(2010, 1, 12), + 'date_range' => Date.new(2010, 1, 12)..Date.new(2011, 1, 12), + 'date_range_from' => Date.new(2010, 1, 12), + 'date_range_to' => Date.new(2011, 1, 12), 'time' => Time.new(2010, 1, 12, 14, 56), 'boolean' => true, 'enum' => TestEnum::Member1, 'array' => [1, 2, 3], 'hash' => {:a => :b},