fixjour 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,8 +17,8 @@ module Fixjour
17
17
  if block_given?
18
18
  define_new(klass, &block)
19
19
  else
20
- define_new(klass) do |overrides|
21
- klass.new(options.merge(overrides))
20
+ define_new(klass) do |proxy, overrides|
21
+ proxy.new(options.merge(overrides))
22
22
  end
23
23
  end
24
24
 
@@ -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
- overrides = args.extract_options!
25
- attrs = valid_attributes.merge(overrides)
26
- attrs.stringify_keys!
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
@@ -21,18 +21,22 @@ module Fixjour
21
21
  error(klass, WrongBuilderType, "must return an instance of #{klass}")
22
22
  end
23
23
 
24
- begin
25
- result.save!
26
- rescue => e
27
- error(klass, UnsavableBuilder, "raises #{e.inspect} when saved to the database")
28
- end
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
- unless new_record(klass).valid?
31
- msg = ""
32
- msg << "returns invalid an invalid object after another object has been saved.\n"
33
- msg << "This could be caused by a validates_uniqueness_of validation in your model.\n"
34
- msg << "Use something like the faker gem to alleviate this issue."
35
- error(klass, DangerousBuilder, msg)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixjour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Nakajima