fixjour 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fixjour/builders.rb +2 -2
- data/lib/fixjour/definitions.rb +4 -6
- data/lib/fixjour/verify.rb +15 -11
- metadata +1 -1
data/lib/fixjour/builders.rb
CHANGED
data/lib/fixjour/definitions.rb
CHANGED
@@ -19,13 +19,11 @@ module Fixjour
|
|
19
19
|
# Defines the valid_*_attributes method
|
20
20
|
def define_valid_attributes(name)
|
21
21
|
define_method("valid_#{name}_attributes") do |*args|
|
22
|
-
valid_attributes = send("new_#{name}").attributes
|
22
|
+
valid_attributes = send("new_#{name}", *args).attributes
|
23
23
|
valid_attributes.delete_if { |key, value| value.nil? }
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
attrs.make_indifferent!
|
28
|
-
attrs
|
24
|
+
valid_attributes.stringify_keys!
|
25
|
+
valid_attributes.make_indifferent!
|
26
|
+
valid_attributes
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
data/lib/fixjour/verify.rb
CHANGED
@@ -21,18 +21,22 @@ module Fixjour
|
|
21
21
|
error(klass, WrongBuilderType, "must return an instance of #{klass}")
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
klass.transaction do
|
25
|
+
begin
|
26
|
+
result.save!
|
27
|
+
rescue => e
|
28
|
+
error(klass, UnsavableBuilder, "raises #{e.inspect} when saved to the database")
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
unless new_record(klass).valid?
|
32
|
+
msg = ""
|
33
|
+
msg << "returns invalid an invalid object after another object has been saved.\n"
|
34
|
+
msg << "This could be caused by a validates_uniqueness_of validation in your model.\n"
|
35
|
+
msg << "Use something like the faker gem to alleviate this issue."
|
36
|
+
error(klass, DangerousBuilder, msg)
|
37
|
+
end
|
38
|
+
|
39
|
+
raise ActiveRecord::Rollback
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|