makers 0.2.0 → 4.0.0.0

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.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +40 -29
  3. data/lib/generators/makers/{install_generator.rb → install/install_generator.rb} +1 -1
  4. data/lib/generators/makers/{templates → install/templates}/definitions.rb +0 -0
  5. data/lib/makers.rb +0 -1
  6. data/lib/makers/dsl/maker.rb +2 -2
  7. data/lib/makers/extensions/active_support/test_case.rb +1 -0
  8. data/lib/makers/proxy.rb +1 -1
  9. data/lib/makers/railtie.rb +10 -2
  10. data/lib/makers/version.rb +1 -1
  11. data/test/dummy/app/assets/javascripts/application.js +2 -2
  12. data/test/dummy/app/assets/stylesheets/application.css +1 -1
  13. data/test/dummy/app/models/post.rb +2 -0
  14. data/test/dummy/app/models/user.rb +2 -0
  15. data/test/dummy/bin/bundle +0 -0
  16. data/test/dummy/bin/rails +1 -1
  17. data/test/dummy/bin/rake +0 -0
  18. data/test/dummy/bin/setup +1 -1
  19. data/test/dummy/config.ru +1 -1
  20. data/test/dummy/config/initializers/cookies_serializer.rb +1 -1
  21. data/test/dummy/config/initializers/mime_types.rb +1 -1
  22. data/test/dummy/config/initializers/session_store.rb +1 -1
  23. data/test/dummy/config/secrets.yml +2 -2
  24. data/test/dummy/db/migrate/20140613221835_create_users.rb +2 -0
  25. data/test/dummy/db/migrate/20140615180954_create_posts.rb +2 -0
  26. data/test/dummy/public/404.html +57 -63
  27. data/test/dummy/public/422.html +57 -63
  28. data/test/dummy/public/500.html +56 -62
  29. data/test/generator_test.rb +1 -1
  30. data/test/{makers_test.rb → maker_test.rb} +1 -1
  31. metadata +6 -14
  32. data/test/dummy/app/models/group.rb +0 -2
  33. data/test/dummy/db/schema.rb +0 -57
  34. data/test/dummy/log/development.log +0 -176
  35. data/test/dummy/log/test.log +0 -1529
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1755d396dc8957e00c67a9444667654b0b4664aa
4
- data.tar.gz: 8be1fb5dd093e611a339b498c7167566775efd01
3
+ metadata.gz: e78fc8b34311d64cff23b79b1232d24cf4d230e6
4
+ data.tar.gz: 11ade66cbe89b1cf259c6f27e750b2f099ed7d3c
5
5
  SHA512:
6
- metadata.gz: d750ffd12a45749f57e39cc9d05f8caac89bea2f3ce481bbd676a73c9339a4022273985dbeac99507d74fbe6cd6cca76abb1f876246607791a8b16f299caad94
7
- data.tar.gz: ba20ae75fc27e14830c1ff4613183f6b5bf6dfd99bf4a489a000a095726dbc3353659ee283345edda24553d4e424295369ea35d25971419962d28d244c28cd7b
6
+ metadata.gz: 4482615e34ef62932354bf9d665705705ed5411b84bfe143c23edf724cd98476640906e083ab16327ba6813351e098d69b83ee19f941b237515f6554513d1e70
7
+ data.tar.gz: a60586dea2e74e1a30853d5dbb1c3e7982e3c7a60ad178578a5cca1fe8eb91211c1ec86b081d73fd097c251697ad5fec1a25db1fb050d10ba194e30665a3a584
data/README.md CHANGED
@@ -9,10 +9,10 @@ Minimalistic factories to replace fixtures in rails.
9
9
 
10
10
  ## Why
11
11
 
12
- I did this gem to add some enhancements to my projects:
12
+ I did this gem to:
13
13
 
14
14
  - Enforce better practices removing unnecessary options.
15
- - Avoid the need to use another method to create lists.
15
+ - Avoid the need to use another method to build/create lists.
16
16
  - Quicker syntax to handle associations.
17
17
 
18
18
  ## Install
@@ -29,53 +29,33 @@ $ bundle
29
29
 
30
30
  ## Configuration
31
31
 
32
- Generate the configuration file:
32
+ Generate de definitions file:
33
33
  ```
34
- bundle exec rails g makers:install
34
+ $ bundle exec rails g makers:install
35
35
  ```
36
36
 
37
- Define makers in test/makers.rb or spec/makers.rb:
37
+ The file will be put in test/makers.rb or spec/makers.rb depending on your test framework:
38
38
  ```ruby
39
39
  Makers.define do
40
- maker :user do
41
- name 'example'
42
- end
43
40
  end
44
41
  ```
45
42
 
46
43
  ## Usage
47
44
 
48
- ### Methods
49
-
50
- There are two methods available:
51
- ```ruby
52
- build
53
- create
54
- ```
55
-
56
- Is possible to override the defaults passing a hash:
57
- ```ruby
58
- build :user, name: 'other'
59
- create :category, title: 'other'
60
- ```
61
-
62
- To create lists just pass the desired size as second parameter:
63
- ```ruby
64
- build :user, 2, name: 'other'
65
- create :category, 5, title: 'other'
66
- ```
67
-
68
45
  ### Inheritance
69
46
 
70
47
  Just concatenate makers:
71
48
  ```ruby
72
49
  Makers.define do
50
+
73
51
  maker :user do
74
52
  name 'example'
53
+
75
54
  maker :user_with_email do
76
55
  email 'example@mail.com'
77
56
  end
78
57
  end
58
+
79
59
  end
80
60
  ```
81
61
 
@@ -84,10 +64,12 @@ end
84
64
  Generates an unique sequence of numbers for an attribute:
85
65
  ```ruby
86
66
  Makers.define do
67
+
87
68
  maker :user do
88
69
  sequence(:email) { |n| "example#{n}@mail.com" }
89
70
  sequence(:phone)
90
71
  end
72
+
91
73
  end
92
74
  ```
93
75
 
@@ -96,16 +78,20 @@ end
96
78
  Associations are defined by name or by the association method:
97
79
  ```ruby
98
80
  Makers.define do
81
+
99
82
  maker :user do
100
83
  posts
101
84
  comments 4, strategy: :create
102
85
  end
86
+
103
87
  maker :comment do
104
88
  association :user
105
89
  end
90
+
106
91
  maker :post do
107
92
  user
108
93
  end
94
+
109
95
  end
110
96
  ```
111
97
 
@@ -114,13 +100,16 @@ end
114
100
  Aliases can be assigned in the initialization:
115
101
  ```ruby
116
102
  Makers.define do
103
+
117
104
  maker :user, aliases: :author do
118
105
  comments
119
106
  end
120
- maker :post, aliases: :comment do
107
+
108
+ maker :post, aliases: %i(comment article) do
121
109
  title
122
110
  author
123
111
  end
112
+
124
113
  end
125
114
  ```
126
115
 
@@ -129,14 +118,36 @@ end
129
118
  If you need to use some logic that depends of another attribute you can use a block:
130
119
  ```ruby
131
120
  Makers.define do
121
+
132
122
  maker :user do
133
123
  name 'example'
134
124
  email { "#{name}@mail.com" }
135
125
  sequence(:username) { |n| "#{name}-#{n}" }
136
126
  end
127
+
137
128
  end
138
129
  ```
139
130
 
131
+ ### Methods
132
+
133
+ There are two new methods available in tests:
134
+ ```ruby
135
+ build
136
+ create
137
+ ```
138
+
139
+ Is possible to override the defaults passing a hash:
140
+ ```ruby
141
+ build :user, name: 'other'
142
+ create :category, title: 'other'
143
+ ```
144
+
145
+ To create lists just pass the desired size as second parameter:
146
+ ```ruby
147
+ build :user, 2, name: 'other'
148
+ create :category, 5, title: 'other'
149
+ ```
150
+
140
151
  ## Credits
141
152
 
142
153
  This gem is maintained and funded by [mmontossi](https://github.com/mmontossi).
@@ -2,7 +2,7 @@ require 'rails/generators'
2
2
 
3
3
  module Makers
4
4
  module Generators
5
- class InstallGenerator < Rails::Generators::Base
5
+ class InstallGenerator < ::Rails::Generators::Base
6
6
 
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
 
@@ -1,4 +1,3 @@
1
- require 'generators/makers/install_generator'
2
1
  require 'makers/dsl/maker'
3
2
  require 'makers/extensions/active_support/test_case'
4
3
  require 'makers/definitions'
@@ -1,5 +1,5 @@
1
1
  module Makers
2
- module DSL
2
+ module Dsl
3
3
  class Maker
4
4
 
5
5
  def initialize(name, options={}, &block)
@@ -22,7 +22,7 @@ module Makers
22
22
  options.delete :aliases
23
23
  options.merge! overrides
24
24
  options.merge! parent: @name
25
- DSL::Maker.new name, options, &block
25
+ Dsl::Maker.new name, options, &block
26
26
  end
27
27
 
28
28
  def sequence(name, &block)
@@ -2,6 +2,7 @@ module Makers
2
2
  module Extensions
3
3
  module ActiveSupport
4
4
  module TestCase
5
+ extend ::ActiveSupport::Concern
5
6
 
6
7
  %w(build create).each do |method|
7
8
  define_method method do |name, *args|
@@ -6,7 +6,7 @@ module Makers
6
6
  end
7
7
 
8
8
  def maker(*args, &block)
9
- DSL::Maker.new *args, &block
9
+ Dsl::Maker.new *args, &block
10
10
  end
11
11
 
12
12
  end
@@ -1,11 +1,20 @@
1
1
  module Makers
2
2
  class Railtie < Rails::Railtie
3
3
 
4
- initializer :makers do
4
+ initializer 'makers.extensions' do
5
+ ActiveSupport::TestCase.include(
6
+ Makers::Extensions::ActiveSupport::TestCase
7
+ )
8
+ end
9
+
10
+ initializer 'makers.replace_fixtures' do
5
11
  config.app_generators.test_framework(
6
12
  config.app_generators.options[:rails][:test_framework],
7
13
  fixture: false
8
14
  )
15
+ end
16
+
17
+ config.after_initialize do
9
18
  if Dir.exist?(Rails.root.join('spec'))
10
19
  directory = 'spec'
11
20
  else
@@ -15,7 +24,6 @@ module Makers
15
24
  if File.exist?(path)
16
25
  load path
17
26
  end
18
- ActiveSupport::TestCase.include Makers::Extensions::ActiveSupport::TestCase
19
27
  end
20
28
 
21
29
  end
@@ -1,5 +1,5 @@
1
1
  module Makers
2
2
 
3
- VERSION = '0.2.0'
3
+ VERSION = '4.0.0.0'
4
4
 
5
5
  end
@@ -2,12 +2,12 @@
2
2
  // listed below.
3
3
  //
4
4
  // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
6
  //
7
7
  // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
8
  // compiled file.
9
9
  //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
13
  //= require_tree .
@@ -3,7 +3,7 @@
3
3
  * listed below.
4
4
  *
5
5
  * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
7
  *
8
8
  * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
9
  * compiled file so the styles you add here take precedence over styles defined in any styles
@@ -1,3 +1,5 @@
1
1
  class Post < ActiveRecord::Base
2
+
2
3
  belongs_to :user
4
+
3
5
  end
@@ -1,3 +1,5 @@
1
1
  class User < ActiveRecord::Base
2
+
2
3
  has_many :posts
4
+
3
5
  end
File without changes
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
4
4
  require_relative '../config/boot'
5
5
  require 'rails/commands'
File without changes
@@ -9,7 +9,7 @@ Dir.chdir APP_ROOT do
9
9
  # This script is a starting point to setup your application.
10
10
  # Add necessary setup steps to this file:
11
11
 
12
- puts "== Installing dependencies =="
12
+ puts '== Installing dependencies =='
13
13
  system 'gem install bundler --conservative'
14
14
  system 'bundle check || bundle install'
15
15
 
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run Rails.application
@@ -1,3 +1,3 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.action_dispatch.cookies_serializer = :json
3
+ Rails.application.config.action_dispatch.cookies_serializer = :json
@@ -1,4 +1,4 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf
4
+ # Mime::Type.register 'text/richtext', :rtf
@@ -1,3 +1,3 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
3
+ Rails.application.config.session_store :cookie_store, key: '_dummy_session'
@@ -11,10 +11,10 @@
11
11
  # if you're sharing your code publicly.
12
12
 
13
13
  development:
14
- secret_key_base: 90ea71642909e9ebb32455c4c2a5b5c211df2ee750161c6506ed5ef3bfb1783f3a2be8f24b7280dc69eb0cc17083f267829b7565418f900b51a3df90a2c633ad
14
+ secret_key_base: 2c1c8d4cbaa726b21aa6483b7d556125f4897508e2b94f8b3ddaec675168382c9b3b6eb5a9359d2fade03f539c16ac1ef905891c2410f2fd00b83b76c1666feb
15
15
 
16
16
  test:
17
- secret_key_base: 49329fb6a8a6e4384aad00333f828e8d6ca75273cbc5ca7d4f37cfd2f1aa7c47eea29d467960e690cdee06a8996bccb39c21019fc76464f914dc77288f85a7e8
17
+ secret_key_base: 9dd531171128e7c3d11dd2c5c18c84ba43d29b677043002634a6f4d58bf2687a283b7b6dc6af741d63c3824f11fa1f858010d7c2509a932023f2ece0d3bfe6cf
18
18
 
19
19
  # Do not keep production secrets in the repository,
20
20
  # instead read values from the environment.
@@ -6,6 +6,8 @@ class CreateUsers < ActiveRecord::Migration
6
6
  t.string :email
7
7
  t.integer :age
8
8
  t.integer :phone
9
+
10
+ t.timestamps null: false
9
11
  end
10
12
  end
11
13
  end
@@ -2,6 +2,8 @@ class CreatePosts < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :posts do |t|
4
4
  t.integer :user_id
5
+
6
+ t.timestamps null: false
5
7
  end
6
8
  end
7
9
  end
@@ -1,67 +1,61 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>The page you were looking for doesn't exist (404)</title>
5
- <meta name="viewport" content="width=device-width,initial-scale=1">
6
- <style>
7
- body {
8
- background-color: #EFEFEF;
9
- color: #2E2F30;
10
- text-align: center;
11
- font-family: arial, sans-serif;
12
- margin: 0;
13
- }
14
-
15
- div.dialog {
16
- width: 95%;
17
- max-width: 33em;
18
- margin: 4em auto 0;
19
- }
20
-
21
- div.dialog > div {
22
- border: 1px solid #CCC;
23
- border-right-color: #999;
24
- border-left-color: #999;
25
- border-bottom-color: #BBB;
26
- border-top: #B00100 solid 4px;
27
- border-top-left-radius: 9px;
28
- border-top-right-radius: 9px;
29
- background-color: white;
30
- padding: 7px 12% 0;
31
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
- }
33
-
34
- h1 {
35
- font-size: 100%;
36
- color: #730E15;
37
- line-height: 1.5em;
38
- }
39
-
40
- div.dialog > p {
41
- margin: 0 0 1em;
42
- padding: 1em;
43
- background-color: #F7F7F7;
44
- border: 1px solid #CCC;
45
- border-right-color: #999;
46
- border-left-color: #999;
47
- border-bottom-color: #999;
48
- border-bottom-left-radius: 4px;
49
- border-bottom-right-radius: 4px;
50
- border-top-color: #DADADA;
51
- color: #666;
52
- box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
- }
54
- </style>
55
- </head>
56
-
57
- <body>
58
- <!-- This file lives in public/404.html -->
59
- <div class="dialog">
60
- <div>
61
- <h1>The page you were looking for doesn't exist.</h1>
62
- <p>You may have mistyped the address or the page may have moved.</p>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+ div.dialog {
15
+ width: 95%;
16
+ max-width: 33em;
17
+ margin: 4em auto 0;
18
+ }
19
+ div.dialog > div {
20
+ border: 1px solid #CCC;
21
+ border-right-color: #999;
22
+ border-left-color: #999;
23
+ border-bottom-color: #BBB;
24
+ border-top: #B00100 solid 4px;
25
+ border-top-left-radius: 9px;
26
+ border-top-right-radius: 9px;
27
+ background-color: white;
28
+ padding: 7px 12% 0;
29
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
30
+ }
31
+ h1 {
32
+ font-size: 100%;
33
+ color: #730E15;
34
+ line-height: 1.5em;
35
+ }
36
+ div.dialog > p {
37
+ margin: 0 0 1em;
38
+ padding: 1em;
39
+ background-color: #F7F7F7;
40
+ border: 1px solid #CCC;
41
+ border-right-color: #999;
42
+ border-left-color: #999;
43
+ border-bottom-color: #999;
44
+ border-bottom-left-radius: 4px;
45
+ border-bottom-right-radius: 4px;
46
+ border-top-color: #DADADA;
47
+ color: #666;
48
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <div class="dialog">
54
+ <div>
55
+ <h1>The page you were looking for doesn't exist.</h1>
56
+ <p>You may have mistyped the address or the page may have moved.</p>
57
+ </div>
58
+ <p>If you are the application owner check the logs for more information.</p>
63
59
  </div>
64
- <p>If you are the application owner check the logs for more information.</p>
65
- </div>
66
- </body>
60
+ </body>
67
61
  </html>