usine 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03d1e6d91e2856f9104d7a7c7b6907988674cdf8
4
- data.tar.gz: 7573d835285b97a7243304ab437bd43ae425e150
3
+ metadata.gz: eaad719cc82acb28815b5fa2c44d87090e0da112
4
+ data.tar.gz: 830b358673b045e8cdab22ec8a3d41d8336267c7
5
5
  SHA512:
6
- metadata.gz: fcc0c03dff27f57b4a1d63eda0c11803ee7bb8fee770b8eb9fa2378fe0851b65fa6eddee7003741d89a8a15351b49585fe1ba013603e9332eb26387fc4537028
7
- data.tar.gz: df77515eb45fe2bec61f553fa20c7e696beb544ca93a753895bbf28f4772bd17fec5fa7ae59219d03d30e710648017ca0480eef1343dc3288705e2a73f21436e
6
+ metadata.gz: 89def5419457b5f8540c6c25827857d9dd4490dfea2479f5a5da243a2dcd40ee8ed96c37b1086ebdb000938d3488d46f13ee2142053e910c602c7be8180674f4
7
+ data.tar.gz: fae70b6f13e72fc8a90ff42c206ab6964774caa4922f7ef277e5f84da82a3465ab19c8e6e1b2d088391a4fdb898e2becfd1426dbdfc30c70cbf214e1415b8a7f
data/README.md CHANGED
@@ -77,7 +77,7 @@ end
77
77
 
78
78
  ### Writing a test with Usine
79
79
 
80
- ```
80
+ ```ruby
81
81
  # Without Usine
82
82
  let(:item) {
83
83
  Item::Create.({
@@ -99,12 +99,20 @@ FactoryGirl.define do
99
99
  end
100
100
  end
101
101
 
102
+ Usine.operation(User::Create) do
103
+ user
104
+ end
105
+
102
106
  Usine.operation(Item::Create) do
103
107
  item
104
- current_user :user
108
+ current_user User::Create #operation used as factory, will return its model
105
109
  end
106
110
 
107
111
  let(:item) { Usine.(Item::Create).model }
112
+
113
+ # note that you can also give attributes when an Operation is used as factory
114
+ # this will assign User::Create.(email: "my_mail@example.com").model to current_user key
115
+ let(:item) { Usine.(Item::Create, current_user: {email: "my_email@example.com"}).model }
108
116
  ```
109
117
 
110
118
  The second example might look more verbose, but you only have to define factories/operations one time.
@@ -1,31 +1,11 @@
1
1
  module Usine
2
2
  class OperationFactory
3
3
  attr_reader :operation_class
4
+ attr_reader :block
4
5
 
5
6
  def initialize(operation_class, &block)
6
7
  @operation_class = operation_class
7
8
  @block = block
8
- @attributes = {}
9
- end
10
-
11
- def process
12
- self.instance_eval(&@block)
13
- @attributes
14
- end
15
-
16
- def method_missing(method_symbol, factory_name = nil, &block)
17
- if factory_name
18
- @attributes[method_symbol] = attributes_for_factory_name(factory_name)
19
- else
20
- @attributes[method_symbol] = attributes_for_factory_name(method_symbol)
21
- end
22
- end
23
-
24
- protected
25
-
26
- def attributes_for_factory_name(name)
27
- factory = FactoryGirl.factory_by_name(name)
28
- factory.run(FactoryGirl::Strategy::AttributesFor, {})
29
9
  end
30
10
  end
31
11
  end
@@ -5,6 +5,7 @@ module Usine
5
5
  @operation = operation
6
6
  @operation_factory = find_operation_factory(operation)
7
7
  @attributes = attributes
8
+ @factory_attributes = {}
8
9
  end
9
10
 
10
11
  def operations=(operations)
@@ -21,13 +22,32 @@ module Usine
21
22
  end
22
23
 
23
24
  def process
24
- factory_attributes = @operation_factory.process
25
- merged_attributes = Utils.merge_hashes(factory_attributes, @attributes)
25
+ self.instance_eval(&@operation_factory.block)
26
+ merged_attributes = Utils.merge_hashes(@factory_attributes, @attributes)
26
27
  @operation.send(@mode, merged_attributes)
27
28
  end
28
29
 
30
+ def method_missing(method_symbol, factory_name = nil, attributes = {}, &block)
31
+ if factory_name
32
+ case factory_name
33
+ when Symbol, String
34
+ @factory_attributes[method_symbol] = attributes_for_factory_name(factory_name)
35
+ else
36
+ merged_attributes = Utils.merge_hashes(attributes, @attributes)
37
+ @factory_attributes[method_symbol] = factory_name.call(merged_attributes).model
38
+ end
39
+ else
40
+ @factory_attributes[method_symbol] = attributes_for_factory_name(method_symbol)
41
+ end
42
+ end
43
+
29
44
  protected
30
45
 
46
+ def attributes_for_factory_name(name)
47
+ factory = FactoryGirl.factory_by_name(name)
48
+ factory.run(FactoryGirl::Strategy::AttributesFor, {})
49
+ end
50
+
31
51
  def find_operation_factory(operation_class)
32
52
  operation_factory = operations.detect do |op|
33
53
  op.operation_class == operation_class
@@ -40,7 +60,7 @@ Couldn’t find an operation factory for: #{operation_class}
40
60
  Please define it with:
41
61
  Usine.operation(#{operation_class}) {}
42
62
  MSG
43
- raise(ArgumentError, message)
63
+ raise(ArgumentError::NotFoundOperationFactory, message)
44
64
  end
45
65
 
46
66
  operation_factory
@@ -4,6 +4,10 @@ module Usine
4
4
  b.each_pair do |current_key, other_value|
5
5
  this_value = a[current_key]
6
6
 
7
+ next if !this_value.nil? &&
8
+ !other_value.nil? &&
9
+ other_value.class != this_value.class
10
+
7
11
  a[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
8
12
  Usine::Utils.merge_hashes(this_value, other_value)
9
13
  else
@@ -1,3 +1,3 @@
1
1
  module Usine
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["j.jaffeux@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Factories for Trailblazer’s operations}
13
- spec.description = %q{Usine (french word for factory) is a small gem aiming to bring a limited feature set of factory_girl when using Trailblazer’s operations.}
13
+ spec.description = %q{Usine (french word for factory) is a wrapper around factory_girl for Trailblazer’s operations.}
14
14
  spec.homepage = "https://github.com/jjaffeux/usine"
15
15
  spec.license = "MIT"
16
16
 
@@ -22,8 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "uber"
23
23
  spec.add_dependency "factory_girl"
24
24
 
25
+ spec.add_development_dependency "trailblazer", "~> 1.1"
26
+ spec.add_development_dependency "reform"
27
+ spec.add_development_dependency "activemodel"
25
28
  spec.add_development_dependency "bundler", "~> 1.12"
26
29
  spec.add_development_dependency "rake", "~> 10.0"
27
30
  spec.add_development_dependency "minitest", "~> 5.0"
28
- spec.add_development_dependency "trailblazer", "~> 1.1"
29
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joffrey JAFFEUX
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-23 00:00:00.000000000 Z
11
+ date: 2016-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
@@ -39,63 +39,91 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: trailblazer
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.12'
47
+ version: '1.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.12'
54
+ version: '1.1'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: reform
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activemodel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: '10.0'
89
+ version: '1.12'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '10.0'
96
+ version: '1.12'
69
97
  - !ruby/object:Gem::Dependency
70
- name: minitest
98
+ name: rake
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - "~>"
74
102
  - !ruby/object:Gem::Version
75
- version: '5.0'
103
+ version: '10.0'
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: '5.0'
110
+ version: '10.0'
83
111
  - !ruby/object:Gem::Dependency
84
- name: trailblazer
112
+ name: minitest
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - "~>"
88
116
  - !ruby/object:Gem::Version
89
- version: '1.1'
117
+ version: '5.0'
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
122
  - - "~>"
95
123
  - !ruby/object:Gem::Version
96
- version: '1.1'
97
- description: Usine (french word for factory) is a small gem aiming to bring a limited
98
- feature set of factory_girl when using Trailblazer’s operations.
124
+ version: '5.0'
125
+ description: Usine (french word for factory) is a wrapper around factory_girl for
126
+ Trailblazer’s operations.
99
127
  email:
100
128
  - j.jaffeux@gmail.com
101
129
  executables: []