makers 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +64 -70
  4. data/Rakefile +1 -14
  5. data/lib/generators/makers/install_generator.rb +20 -0
  6. data/lib/generators/makers/templates/definitions.rb +2 -0
  7. data/lib/makers.rb +8 -35
  8. data/lib/makers/definitions.rb +18 -27
  9. data/lib/makers/dsl/maker.rb +74 -0
  10. data/lib/makers/extensions/active_support/test_case.rb +15 -0
  11. data/lib/makers/maker.rb +32 -81
  12. data/lib/makers/proxy.rb +3 -42
  13. data/lib/makers/railtie.rb +10 -21
  14. data/lib/makers/version.rb +1 -1
  15. data/test/dummy/Rakefile +0 -1
  16. data/test/dummy/app/views/layouts/application.html.erb +9 -11
  17. data/test/dummy/bin/bundle +1 -0
  18. data/test/dummy/bin/rails +1 -0
  19. data/test/dummy/bin/rake +1 -0
  20. data/test/dummy/bin/setup +30 -0
  21. data/test/dummy/config/application.rb +3 -0
  22. data/test/dummy/config/database.yml +4 -22
  23. data/test/dummy/config/database.yml.travis +3 -0
  24. data/test/dummy/config/environments/development.rb +6 -2
  25. data/test/dummy/config/environments/production.rb +16 -24
  26. data/test/dummy/config/environments/test.rb +7 -12
  27. data/test/dummy/config/initializers/assets.rb +11 -0
  28. data/test/dummy/config/secrets.yml +1 -1
  29. data/test/dummy/db/migrate/20140613221835_create_users.rb +0 -2
  30. data/test/dummy/db/migrate/20140615180954_create_posts.rb +0 -3
  31. data/test/dummy/db/schema.rb +38 -14
  32. data/test/dummy/log/development.log +176 -0
  33. data/test/dummy/log/test.log +1529 -0
  34. data/test/dummy/test/makers.rb +20 -0
  35. data/test/generator_test.rb +18 -0
  36. data/test/makers_test.rb +66 -0
  37. data/test/test_helper.rb +5 -18
  38. metadata +31 -48
  39. data/lib/generators/makers/model/model_generator.rb +0 -15
  40. data/lib/generators/makers/model/templates/maker.rb +0 -2
  41. data/lib/makers/callbacks.rb +0 -23
  42. data/lib/makers/configuration.rb +0 -10
  43. data/lib/makers/fetcher.rb +0 -18
  44. data/lib/makers/methods.rb +0 -11
  45. data/lib/makers/sequence.rb +0 -19
  46. data/test/aliases_test.rb +0 -20
  47. data/test/associations_test.rb +0 -50
  48. data/test/attributes_test.rb +0 -26
  49. data/test/callbacks_test.rb +0 -38
  50. data/test/clean_test.rb +0 -18
  51. data/test/dependent_test.rb +0 -30
  52. data/test/dummy/README.rdoc +0 -28
  53. data/test/dummy/test/makers/people.rb +0 -2
  54. data/test/dummy/test/makers/users.rb +0 -3
  55. data/test/fabricators_test.rb +0 -33
  56. data/test/generators_test.rb +0 -13
  57. data/test/inheritance_test.rb +0 -49
  58. data/test/lists_test.rb +0 -33
  59. data/test/load_test.rb +0 -13
  60. data/test/merges_test.rb +0 -31
@@ -0,0 +1,20 @@
1
+ Makers.define do
2
+
3
+ maker :user, aliases: :owner do
4
+ name 'name'
5
+ sequence(:username) { name }
6
+ sequence(:email) { |n| "mail#{n}@example.com" }
7
+ sequence(:phone)
8
+ posts
9
+
10
+ maker :user_with_age do
11
+ age 9
12
+ end
13
+ maker :user_with_posts do
14
+ posts 2, strategy: :create
15
+ end
16
+ end
17
+
18
+ maker :post
19
+
20
+ end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+ require 'rails/generators'
3
+ require 'generators/makers/install_generator'
4
+
5
+ class GeneratorTest < Rails::Generators::TestCase
6
+ destination Rails.root.join('tmp')
7
+
8
+ teardown do
9
+ FileUtils.rm_rf destination_root
10
+ end
11
+
12
+ test 'install' do
13
+ self.class.tests Makers::Generators::InstallGenerator
14
+ run_generator
15
+ assert_file 'test/makers.rb'
16
+ end
17
+
18
+ end
@@ -0,0 +1,66 @@
1
+ require 'test_helper'
2
+
3
+ class MakersTest < ActiveSupport::TestCase
4
+
5
+ test 'overrides' do
6
+ assert_equal 'other', build(:user, name: 'other').name
7
+ list = build(:user, 3, name: 'other')
8
+ 3.times do |index|
9
+ assert_equal 'other', list[index].name
10
+ end
11
+
12
+ assert_equal 'other', create(:user, name: 'other').name
13
+ list = create(:user, 3, name: 'other')
14
+ 3.times do |index|
15
+ assert_equal 'other', list[index].name
16
+ end
17
+ end
18
+
19
+ test 'inheritance' do
20
+ user = build(:user_with_age)
21
+ assert_equal 'name', user.name
22
+ assert_equal 9, user.age
23
+
24
+ user = create(:user_with_age)
25
+ assert_equal 'name', user.name
26
+ assert_equal 9, user.age
27
+ end
28
+
29
+ test 'dependent' do
30
+ assert_equal 'name', build(:user).username
31
+ assert_equal 'name', create(:user).username
32
+ end
33
+
34
+ test 'sequences' do
35
+ assert_operator build(:user).email, :<, create(:user).email
36
+ assert_operator build(:user).phone, :<, create(:user).phone
37
+ end
38
+
39
+ test 'aliases' do
40
+ user = Makers.definitions.find(:user)
41
+ assert_kind_of Makers::Maker, user
42
+ assert_equal user, Makers.definitions.find(:owner)
43
+ end
44
+
45
+ test 'associations' do
46
+ posts = build(:user).posts
47
+ assert_equal 1, posts.size
48
+ post = posts.first
49
+ assert post.new_record?
50
+
51
+ posts = build(:user_with_posts).posts
52
+ assert_equal 2, posts.size
53
+ post = posts.first
54
+ assert post.persisted?
55
+ end
56
+
57
+ test 'definitions' do
58
+ assert_raises do
59
+ Makers.find :wrong
60
+ end
61
+ assert_raises do
62
+ Makers.add :user
63
+ end
64
+ end
65
+
66
+ end
@@ -1,26 +1,13 @@
1
1
  # Configure Rails Environment
2
2
  ENV['RAILS_ENV'] = 'test'
3
3
 
4
- require File.expand_path('../dummy/config/environment.rb', __FILE__)
4
+ require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
5
+ ActiveRecord::Migrator.migrations_paths = [File.expand_path('../../test/dummy/db/migrate', __FILE__)]
5
6
  require 'rails/test_help'
6
7
 
7
- Rails.backtrace_cleaner.remove_silencers!
8
+ # Filter out Minitest backtrace while allowing backtrace from other libraries
9
+ # to be shown.
10
+ Minitest.backtrace_filter = Minitest::BacktraceFilter.new
8
11
 
9
12
  # Load support files
10
13
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
-
12
- # Load fixtures from the engine
13
- if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
- ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__)
15
- end
16
-
17
- # Load database
18
- config = YAML::load(File.read(File.expand_path('../dummy/config/database.yml', __FILE__)))
19
- config['test']['adapter'] = 'jdbcsqlite3' if RUBY_PLATFORM == 'java'
20
- ActiveRecord::Base.establish_connection(config['test'])
21
- load(File.expand_path('../dummy/db/schema.rb', __FILE__))
22
-
23
- # Include methods
24
- class ActiveSupport::TestCase
25
- setup { Makers.reset }
26
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: makers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mmontossi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
19
+ version: 4.2.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: 4.3.0
@@ -26,27 +26,27 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 4.0.0
29
+ version: 4.2.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: 4.3.0
33
33
  - !ruby/object:Gem::Dependency
34
- name: sqlite3
34
+ name: pg
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.3'
39
+ version: '0.18'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '1.3'
47
- description: Minimalistic factory inspired in factory_girl for rails.
46
+ version: '0.18'
47
+ description: Minimalistic factories to replace fixtures in rails.
48
48
  email:
49
- - mmontossi@buyin.io
49
+ - mmontossi@gmail.com
50
50
  executables: []
51
51
  extensions: []
52
52
  extra_rdoc_files: []
@@ -54,26 +54,16 @@ files:
54
54
  - MIT-LICENSE
55
55
  - README.md
56
56
  - Rakefile
57
- - lib/generators/makers/model/model_generator.rb
58
- - lib/generators/makers/model/templates/maker.rb
57
+ - lib/generators/makers/install_generator.rb
58
+ - lib/generators/makers/templates/definitions.rb
59
59
  - lib/makers.rb
60
- - lib/makers/callbacks.rb
61
- - lib/makers/configuration.rb
62
60
  - lib/makers/definitions.rb
63
- - lib/makers/fetcher.rb
61
+ - lib/makers/dsl/maker.rb
62
+ - lib/makers/extensions/active_support/test_case.rb
64
63
  - lib/makers/maker.rb
65
- - lib/makers/methods.rb
66
64
  - lib/makers/proxy.rb
67
65
  - lib/makers/railtie.rb
68
- - lib/makers/sequence.rb
69
66
  - lib/makers/version.rb
70
- - test/aliases_test.rb
71
- - test/associations_test.rb
72
- - test/attributes_test.rb
73
- - test/callbacks_test.rb
74
- - test/clean_test.rb
75
- - test/dependent_test.rb
76
- - test/dummy/README.rdoc
77
67
  - test/dummy/Rakefile
78
68
  - test/dummy/app/assets/javascripts/application.js
79
69
  - test/dummy/app/assets/stylesheets/application.css
@@ -86,14 +76,17 @@ files:
86
76
  - test/dummy/bin/bundle
87
77
  - test/dummy/bin/rails
88
78
  - test/dummy/bin/rake
79
+ - test/dummy/bin/setup
89
80
  - test/dummy/config.ru
90
81
  - test/dummy/config/application.rb
91
82
  - test/dummy/config/boot.rb
92
83
  - test/dummy/config/database.yml
84
+ - test/dummy/config/database.yml.travis
93
85
  - test/dummy/config/environment.rb
94
86
  - test/dummy/config/environments/development.rb
95
87
  - test/dummy/config/environments/production.rb
96
88
  - test/dummy/config/environments/test.rb
89
+ - test/dummy/config/initializers/assets.rb
97
90
  - test/dummy/config/initializers/backtrace_silencers.rb
98
91
  - test/dummy/config/initializers/cookies_serializer.rb
99
92
  - test/dummy/config/initializers/filter_parameter_logging.rb
@@ -107,18 +100,15 @@ files:
107
100
  - test/dummy/db/migrate/20140613221835_create_users.rb
108
101
  - test/dummy/db/migrate/20140615180954_create_posts.rb
109
102
  - test/dummy/db/schema.rb
103
+ - test/dummy/log/development.log
104
+ - test/dummy/log/test.log
110
105
  - test/dummy/public/404.html
111
106
  - test/dummy/public/422.html
112
107
  - test/dummy/public/500.html
113
108
  - test/dummy/public/favicon.ico
114
- - test/dummy/test/makers/people.rb
115
- - test/dummy/test/makers/users.rb
116
- - test/fabricators_test.rb
117
- - test/generators_test.rb
118
- - test/inheritance_test.rb
119
- - test/lists_test.rb
120
- - test/load_test.rb
121
- - test/merges_test.rb
109
+ - test/dummy/test/makers.rb
110
+ - test/generator_test.rb
111
+ - test/makers_test.rb
122
112
  - test/test_helper.rb
123
113
  homepage: https://github.com/mmontossi/makers
124
114
  licenses:
@@ -132,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
122
  requirements:
133
123
  - - ">="
134
124
  - !ruby/object:Gem::Version
135
- version: 1.9.3
125
+ version: 2.0.0
136
126
  required_rubygems_version: !ruby/object:Gem::Requirement
137
127
  requirements:
138
128
  - - ">="
@@ -140,17 +130,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
130
  version: '0'
141
131
  requirements: []
142
132
  rubyforge_project:
143
- rubygems_version: 2.4.5
133
+ rubygems_version: 2.5.1
144
134
  signing_key:
145
135
  specification_version: 4
146
136
  summary: Makers for Rails
147
137
  test_files:
148
- - test/aliases_test.rb
149
- - test/associations_test.rb
150
- - test/attributes_test.rb
151
- - test/callbacks_test.rb
152
- - test/clean_test.rb
153
- - test/dependent_test.rb
154
138
  - test/dummy/app/assets/javascripts/application.js
155
139
  - test/dummy/app/assets/stylesheets/application.css
156
140
  - test/dummy/app/controllers/application_controller.rb
@@ -162,13 +146,16 @@ test_files:
162
146
  - test/dummy/bin/bundle
163
147
  - test/dummy/bin/rails
164
148
  - test/dummy/bin/rake
149
+ - test/dummy/bin/setup
165
150
  - test/dummy/config/application.rb
166
151
  - test/dummy/config/boot.rb
167
152
  - test/dummy/config/database.yml
153
+ - test/dummy/config/database.yml.travis
168
154
  - test/dummy/config/environment.rb
169
155
  - test/dummy/config/environments/development.rb
170
156
  - test/dummy/config/environments/production.rb
171
157
  - test/dummy/config/environments/test.rb
158
+ - test/dummy/config/initializers/assets.rb
172
159
  - test/dummy/config/initializers/backtrace_silencers.rb
173
160
  - test/dummy/config/initializers/cookies_serializer.rb
174
161
  - test/dummy/config/initializers/filter_parameter_logging.rb
@@ -183,18 +170,14 @@ test_files:
183
170
  - test/dummy/db/migrate/20140613221835_create_users.rb
184
171
  - test/dummy/db/migrate/20140615180954_create_posts.rb
185
172
  - test/dummy/db/schema.rb
173
+ - test/dummy/log/development.log
174
+ - test/dummy/log/test.log
186
175
  - test/dummy/public/404.html
187
176
  - test/dummy/public/422.html
188
177
  - test/dummy/public/500.html
189
178
  - test/dummy/public/favicon.ico
190
179
  - test/dummy/Rakefile
191
- - test/dummy/README.rdoc
192
- - test/dummy/test/makers/people.rb
193
- - test/dummy/test/makers/users.rb
194
- - test/fabricators_test.rb
195
- - test/generators_test.rb
196
- - test/inheritance_test.rb
197
- - test/lists_test.rb
198
- - test/load_test.rb
199
- - test/merges_test.rb
180
+ - test/dummy/test/makers.rb
181
+ - test/generator_test.rb
182
+ - test/makers_test.rb
200
183
  - test/test_helper.rb
@@ -1,15 +0,0 @@
1
- require 'rails/generators/named_base'
2
-
3
- module Makers
4
- module Generators
5
- class ModelGenerator < Rails::Generators::NamedBase
6
-
7
- source_root File.expand_path('../templates', __FILE__)
8
-
9
- def create_fixture_file
10
- template 'maker.rb', Makers.path.join("#{table_name}.rb")
11
- end
12
-
13
- end
14
- end
15
- end
@@ -1,2 +0,0 @@
1
- maker :<%= singular_table_name %> do
2
- end
@@ -1,23 +0,0 @@
1
- module Makers
2
- module Callbacks
3
-
4
- def callbacks
5
- @callbacks ||= {}
6
- end
7
-
8
- %w(after before).each do |moment|
9
- define_method moment do |actions, &block|
10
- actions = [actions] unless actions.is_a? Array
11
- actions.each do |action|
12
- name = :"#{moment}_#{action}"
13
- if callbacks[name]
14
- callbacks[name] << block
15
- else
16
- callbacks[name] = [block]
17
- end
18
- end
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,10 +0,0 @@
1
- module Makers
2
- class Configuration
3
- include Callbacks
4
-
5
- def reset
6
- @callbacks = {}
7
- end
8
-
9
- end
10
- end
@@ -1,18 +0,0 @@
1
- module Makers
2
- class Fetcher
3
-
4
- def initialize(name, options, &block)
5
- @name = name
6
- @options = options
7
- instance_eval &block
8
- end
9
-
10
- def maker(name, options={}, &block)
11
- Makers.definitions.maker name, @options.merge(options.merge(parent: @name)), &block
12
- end
13
-
14
- def method_missing(name, *args, &block)
15
- end
16
-
17
- end
18
- end
@@ -1,11 +0,0 @@
1
- module Makers
2
- module Methods
3
-
4
- %w(build create attributes_for).each do |method|
5
- define_method method do |name, *args|
6
- Makers.definitions.find(name).send(method, *args)
7
- end
8
- end
9
-
10
- end
11
- end
@@ -1,19 +0,0 @@
1
- module Makers
2
- class Sequence
3
-
4
- def initialize(&block)
5
- @index = 0
6
- @block = block
7
- end
8
-
9
- def generate(context)
10
- @index += 1
11
- if @block
12
- context.instance_exec @index, &@block
13
- else
14
- @index
15
- end
16
- end
17
-
18
- end
19
- end