ski_binding_calculator 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -18,27 +18,11 @@ class SkiBinding::Calculator
|
|
18
18
|
def self.validate_attrs(attrs)
|
19
19
|
attrs = attrs.with_indifferent_access
|
20
20
|
error = SkiBinding::Error.new
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
error.add_message(*[:height, "height is blank"])
|
27
|
-
end
|
28
|
-
if attrs[:sole_length].blank?
|
29
|
-
error.add_message(*[:sole_length, "sole length is blank"])
|
30
|
-
end
|
31
|
-
if attrs[:birthday_year].blank?
|
32
|
-
error.add_message(*[:birthday_year, "birthday year is blank"])
|
33
|
-
end
|
34
|
-
if attrs[:birthday_month].blank?
|
35
|
-
error.add_message(*[:birthday_month, "birthday month is blank"])
|
36
|
-
end
|
37
|
-
if attrs[:birthday_day].blank?
|
38
|
-
error.add_message(*[:birthday_day, "birthday day is blank"])
|
39
|
-
end
|
40
|
-
if attrs[:type].blank?
|
41
|
-
error.add_message(*[:type, "type is blank"])
|
21
|
+
attributes = [:weight, :height, :birthday_year, :birthday_month, :birthday_day,
|
22
|
+
:sole_length, :type]
|
23
|
+
|
24
|
+
attributes.each do |attr|
|
25
|
+
error.add_message(*[attr, "is blank"]) if attrs[attr].blank?
|
42
26
|
end
|
43
27
|
|
44
28
|
raise error unless error.messages.empty?
|
@@ -49,7 +33,7 @@ class SkiBinding::Calculator
|
|
49
33
|
hashy = {}
|
50
34
|
hashy[:weight] = attrs[:weight].to_f
|
51
35
|
if hashy[:weight] < 10.0
|
52
|
-
raise
|
36
|
+
raise SkiBinding::Error.new(*[:weight, "is less than 10kg"])
|
53
37
|
end
|
54
38
|
hashy[:height] = attrs[:height].to_f
|
55
39
|
hashy[:sole_length] = attrs[:sole_length].to_f
|
@@ -81,7 +65,7 @@ class SkiBinding::Calculator
|
|
81
65
|
if keys.include?(type_string)
|
82
66
|
attrs[:type] = types[type_string]
|
83
67
|
else
|
84
|
-
raise
|
68
|
+
raise SkiBinding::Error.new(*[:type, "You have entered an invalid type."])
|
85
69
|
end
|
86
70
|
attrs
|
87
71
|
end
|
@@ -102,7 +86,7 @@ class SkiBinding::Calculator
|
|
102
86
|
end
|
103
87
|
end
|
104
88
|
if code == -1
|
105
|
-
raise
|
89
|
+
raise SkiBinding::Error.new(*[:base, "You have entered invalid weight and/or height"])
|
106
90
|
end
|
107
91
|
unless attrs[:weight] < 13
|
108
92
|
code += attrs[:type]
|
@@ -120,7 +104,7 @@ class SkiBinding::Calculator
|
|
120
104
|
unless s.z_value.nil?
|
121
105
|
return {:z_value => s.z_value}
|
122
106
|
else
|
123
|
-
raise
|
107
|
+
raise SkiBinding::Error.new(*[:base, "Please calculate z-index by hand."])
|
124
108
|
end
|
125
109
|
end
|
126
110
|
end
|
data/spec/lib/calculator_spec.rb
CHANGED
@@ -71,7 +71,7 @@ describe SkiBinding::Calculator do
|
|
71
71
|
|
72
72
|
it "raise error with two messages" do
|
73
73
|
expect { calculated_attr_validation }.to raise_error(SkiBinding::Error) { |e|
|
74
|
-
e.messages.should == {:weight => "
|
74
|
+
e.messages.should == { :weight => "is blank", :height => "is blank" } }
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
@@ -91,8 +91,10 @@ describe SkiBinding::Calculator do
|
|
91
91
|
skiers_parameters[:weight] = 9
|
92
92
|
skiers_parameters
|
93
93
|
end
|
94
|
-
it
|
95
|
-
|
94
|
+
it "raise error" do
|
95
|
+
expect { calculated_preped }.to raise_error(SkiBinding::Error) { |e|
|
96
|
+
e.messages.should == { :weight => "is less than 10kg" } }
|
97
|
+
end
|
96
98
|
end
|
97
99
|
end
|
98
100
|
|
@@ -117,8 +119,10 @@ describe SkiBinding::Calculator do
|
|
117
119
|
expected_aged
|
118
120
|
end
|
119
121
|
|
120
|
-
it
|
121
|
-
|
122
|
+
it "raise error" do
|
123
|
+
expect { calculated_validated }.to raise_error(SkiBinding::Error) { |e|
|
124
|
+
e.messages.should == { :type => "You have entered an invalid type." } }
|
125
|
+
end
|
122
126
|
end
|
123
127
|
end
|
124
128
|
|
@@ -144,8 +148,10 @@ describe SkiBinding::Calculator do
|
|
144
148
|
expected_validated
|
145
149
|
end
|
146
150
|
|
147
|
-
it
|
148
|
-
|
151
|
+
it "raises error" do
|
152
|
+
expect { calculated_code }.to raise_error(SkiBinding::Error) { |e|
|
153
|
+
e.messages.should == { :base => "You have entered invalid weight and/or height" } }
|
154
|
+
end
|
149
155
|
end
|
150
156
|
|
151
157
|
context "when age >= 50 || age < 10" do
|
@@ -187,8 +193,10 @@ describe SkiBinding::Calculator do
|
|
187
193
|
|
188
194
|
context "when no setting found" do
|
189
195
|
let(:binding_code) { 0 }
|
190
|
-
it
|
191
|
-
|
196
|
+
it "raise error" do
|
197
|
+
expect { calculated_setting }.to raise_error(SkiBinding::Error) { |e|
|
198
|
+
e.messages.should == { :base => "Please calculate z-index by hand." } }
|
199
|
+
end
|
192
200
|
end
|
193
201
|
end
|
194
202
|
|