3 describe ComplexNumberArithmeticEditForm do
11 :fractional_mode => false,
13 :operators_plus => true,
14 :operators_minus => true,
15 :operators_times => true,
16 # :operators_div => true,
18 @klass = ComplexNumberArithmeticEditForm
19 @basic = @klass.new(@valid_attributes)
23 it{ @basic.should be_valid }
26 context "validation" do
29 context "is string" do
30 subject{ @basic.min = "a"; @basic }
31 it{ should_not be_valid }
34 subject{ @basic.min = nil; @basic }
35 it{ should_not be_valid }
38 subject{ @basic.min = ""; @basic }
39 it{ should_not be_valid }
42 subject{ @basic.min = 1.5; @basic }
43 it{ should_not be_valid }
46 subject{ @basic.min = -1; @basic }
47 it{ should_not be_valid }
50 subject{ @basic.min = 0; @basic }
56 context "is string" do
57 subject{ @basic.max = "a"; @basic }
58 it{ should_not be_valid }
61 subject{ @basic.max = nil; @basic }
62 it{ should_not be_valid }
65 subject{ @basic.max = ""; @basic }
66 it{ should_not be_valid }
69 subject{ @basic.max = 1.5; @basic }
70 it{ should_not be_valid }
73 subject{ @basic.max = -1; @basic }
74 it{ should_not be_valid }
77 subject{ @basic.max = 0; @basic }
83 context "min < max" do
88 it{ @basic.should_not be_valid }
89 it "have a correct message" do
91 @basic.errors.full_messages.first.should == "Min must be greater than Max."
94 context "min = max" do
100 it{ should be_valid }
104 context "operators" do
105 context "no operators specified" do
107 @basic.operators_plus = false
108 @basic.operators_minus = false
109 @basic.operators_times = false
110 # @basic.operators_div = false
113 it{ should_not be_valid }
118 context "options_hash" do
119 subject{ @basic.options_hash }
122 :min => 0, :max => 100,
123 :fractional_mode => false,
125 :operators => %w[+ - * /]
130 context "attributes_for_model" do
131 subject{ @basic.attributes_for_model }
137 :options => @basic.options_hash.to_json,
143 context "set_options" do
147 :min => 1, :max => 99,
148 :fractional_mode => true,
150 :operators => %w[+ - * div]
152 @basic.set_options(options.to_json)
155 its(:min){ should == 1 }
156 its(:max){ should == 99 }
157 its(:fractional_mode){ should be_true }
158 its(:term_number){ should == 3 }
159 its(:operators_plus){ should be_true }
160 its(:operators_minus){ should be_true }
161 its(:operators_times){ should be_true }
162 its(:operators_div){ should be_true }
164 context "set nothing" do
165 it "should not raise Exception" do
166 lambda{ @basic.set_options({}.to_json) }.should_not raise_exception