makers 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +64 -70
- data/Rakefile +1 -14
- data/lib/generators/makers/install_generator.rb +20 -0
- data/lib/generators/makers/templates/definitions.rb +2 -0
- data/lib/makers.rb +8 -35
- data/lib/makers/definitions.rb +18 -27
- data/lib/makers/dsl/maker.rb +74 -0
- data/lib/makers/extensions/active_support/test_case.rb +15 -0
- data/lib/makers/maker.rb +32 -81
- data/lib/makers/proxy.rb +3 -42
- data/lib/makers/railtie.rb +10 -21
- data/lib/makers/version.rb +1 -1
- data/test/dummy/Rakefile +0 -1
- data/test/dummy/app/views/layouts/application.html.erb +9 -11
- data/test/dummy/bin/bundle +1 -0
- data/test/dummy/bin/rails +1 -0
- data/test/dummy/bin/rake +1 -0
- data/test/dummy/bin/setup +30 -0
- data/test/dummy/config/application.rb +3 -0
- data/test/dummy/config/database.yml +4 -22
- data/test/dummy/config/database.yml.travis +3 -0
- data/test/dummy/config/environments/development.rb +6 -2
- data/test/dummy/config/environments/production.rb +16 -24
- data/test/dummy/config/environments/test.rb +7 -12
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/secrets.yml +1 -1
- data/test/dummy/db/migrate/20140613221835_create_users.rb +0 -2
- data/test/dummy/db/migrate/20140615180954_create_posts.rb +0 -3
- data/test/dummy/db/schema.rb +38 -14
- data/test/dummy/log/development.log +176 -0
- data/test/dummy/log/test.log +1529 -0
- data/test/dummy/test/makers.rb +20 -0
- data/test/generator_test.rb +18 -0
- data/test/makers_test.rb +66 -0
- data/test/test_helper.rb +5 -18
- metadata +31 -48
- data/lib/generators/makers/model/model_generator.rb +0 -15
- data/lib/generators/makers/model/templates/maker.rb +0 -2
- data/lib/makers/callbacks.rb +0 -23
- data/lib/makers/configuration.rb +0 -10
- data/lib/makers/fetcher.rb +0 -18
- data/lib/makers/methods.rb +0 -11
- data/lib/makers/sequence.rb +0 -19
- data/test/aliases_test.rb +0 -20
- data/test/associations_test.rb +0 -50
- data/test/attributes_test.rb +0 -26
- data/test/callbacks_test.rb +0 -38
- data/test/clean_test.rb +0 -18
- data/test/dependent_test.rb +0 -30
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/test/makers/people.rb +0 -2
- data/test/dummy/test/makers/users.rb +0 -3
- data/test/fabricators_test.rb +0 -33
- data/test/generators_test.rb +0 -13
- data/test/inheritance_test.rb +0 -49
- data/test/lists_test.rb +0 -33
- data/test/load_test.rb +0 -13
- data/test/merges_test.rb +0 -31
data/test/aliases_test.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class AliasesTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.define do
|
7
|
-
maker :user, aliases: [:owner, :author] do
|
8
|
-
name 'name'
|
9
|
-
phone
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'aliases' do
|
15
|
-
assert_kind_of Makers::Maker, Makers.definitions.find(:user)
|
16
|
-
assert_kind_of Makers::Maker, Makers.definitions.find(:owner)
|
17
|
-
assert_kind_of Makers::Maker, Makers.definitions.find(:author)
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/test/associations_test.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class AssociationsTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.define do
|
7
|
-
maker :user do
|
8
|
-
maker :user_with_built_posts do
|
9
|
-
posts
|
10
|
-
end
|
11
|
-
maker :user_with_created_posts do
|
12
|
-
posts 2, strategy: :create
|
13
|
-
end
|
14
|
-
end
|
15
|
-
maker :post do
|
16
|
-
maker :post_with_built_user do
|
17
|
-
user
|
18
|
-
end
|
19
|
-
maker :post_with_created_user do
|
20
|
-
user strategy: :create
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'belongs to association' do
|
27
|
-
user = build(:post_with_built_user).user
|
28
|
-
assert_kind_of User, user
|
29
|
-
assert user.new_record?
|
30
|
-
|
31
|
-
user = build(:post_with_created_user).user
|
32
|
-
assert_kind_of User, user
|
33
|
-
assert user.persisted?
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'has many association' do
|
37
|
-
posts = build(:user_with_built_posts).posts
|
38
|
-
assert_equal 1, posts.size
|
39
|
-
post = posts.first
|
40
|
-
assert_kind_of Post, post
|
41
|
-
assert post.new_record?
|
42
|
-
|
43
|
-
posts = build(:user_with_created_posts).posts
|
44
|
-
assert_equal 2, posts.size
|
45
|
-
post = posts.first
|
46
|
-
assert_kind_of Post, post
|
47
|
-
assert post.persisted?
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
data/test/attributes_test.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class AttributesTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.define do
|
7
|
-
maker :user do
|
8
|
-
sequence(:email) { |n| "mail#{n}@example.com" }
|
9
|
-
sequence(:age)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'block sequence' do
|
15
|
-
assert_equal 'mail1@example.com', attributes_for(:user)[:email]
|
16
|
-
assert_equal 'mail2@example.com', build(:user).email
|
17
|
-
assert_equal 'mail3@example.com', create(:user).email
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'numeric sequence' do
|
21
|
-
assert_equal 1, attributes_for(:user)[:age]
|
22
|
-
assert_equal 2, build(:user).age
|
23
|
-
assert_equal 3, create(:user).age
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
data/test/callbacks_test.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CallbacksTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.configure do
|
7
|
-
before(:build) { |u| u.email = 'build@example.com' }
|
8
|
-
after(:build) { |u| u.phone = 1 }
|
9
|
-
before(:create) { |u| u.email = 'create@example.com' }
|
10
|
-
after(:create) { |u| u.phone = 2 }
|
11
|
-
end
|
12
|
-
Makers.define do
|
13
|
-
maker :user do
|
14
|
-
before(:build) { |u| u.name = 'build' }
|
15
|
-
after(:build) { |u| u.age = 1 }
|
16
|
-
before(:create) { |u| u.name = 'create' }
|
17
|
-
after(:create) { |u| u.age = 2 }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'build callbacks' do
|
23
|
-
user = build(:user)
|
24
|
-
assert_equal 'build@example.com', user.email
|
25
|
-
assert_equal 1, user.phone
|
26
|
-
assert_equal 'build', user.name
|
27
|
-
assert_equal 1, user.age
|
28
|
-
end
|
29
|
-
|
30
|
-
test 'create callbacks' do
|
31
|
-
user = create(:user)
|
32
|
-
assert_equal 'create@example.com', user.email
|
33
|
-
assert_equal 2, user.phone
|
34
|
-
assert_equal 'create', user.name
|
35
|
-
assert_equal 2, user.age
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/test/clean_test.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CleanTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.define do
|
7
|
-
maker :user do
|
8
|
-
end
|
9
|
-
end
|
10
|
-
create :user, 5
|
11
|
-
Makers.clean
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'clean records' do
|
15
|
-
assert_equal 0, User.count
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
data/test/dependent_test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class DependentTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.define do
|
7
|
-
maker :user do
|
8
|
-
email { "#{name}@example.com" }
|
9
|
-
sequence(:username) { |n| "#{name}-#{n}" }
|
10
|
-
name 'name'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
test 'return attributes' do
|
16
|
-
assert_equal 'name-1', attributes_for(:user)[:username]
|
17
|
-
assert_equal 'name@example.com', attributes_for(:user)[:email]
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'build instance' do
|
21
|
-
assert_equal 'name-1', build(:user).username
|
22
|
-
assert_equal 'name@example.com', build(:user).email
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'create instance' do
|
26
|
-
assert_equal 'name-1', create(:user).username
|
27
|
-
assert_equal 'name@example.com', create(:user).email
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
data/test/dummy/README.rdoc
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
== README
|
2
|
-
|
3
|
-
This README would normally document whatever steps are necessary to get the
|
4
|
-
application up and running.
|
5
|
-
|
6
|
-
Things you may want to cover:
|
7
|
-
|
8
|
-
* Ruby version
|
9
|
-
|
10
|
-
* System dependencies
|
11
|
-
|
12
|
-
* Configuration
|
13
|
-
|
14
|
-
* Database creation
|
15
|
-
|
16
|
-
* Database initialization
|
17
|
-
|
18
|
-
* How to run the test suite
|
19
|
-
|
20
|
-
* Services (job queues, cache servers, search engines, etc.)
|
21
|
-
|
22
|
-
* Deployment instructions
|
23
|
-
|
24
|
-
* ...
|
25
|
-
|
26
|
-
|
27
|
-
Please feel free to use a different markup language if you do not plan to run
|
28
|
-
<tt>rake doc:app</tt>.
|
data/test/fabricators_test.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MakersTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.define do
|
7
|
-
maker :user do
|
8
|
-
name 'name'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'return attributes' do
|
14
|
-
hash = attributes_for(:user)
|
15
|
-
assert_kind_of Hash, hash
|
16
|
-
assert_equal 'name', hash[:name]
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'build instance' do
|
20
|
-
record = build(:user)
|
21
|
-
assert_kind_of User, record
|
22
|
-
assert record.new_record?
|
23
|
-
assert_equal 'name', record.name
|
24
|
-
end
|
25
|
-
|
26
|
-
test 'create instance' do
|
27
|
-
record = create(:user)
|
28
|
-
assert_kind_of User, record
|
29
|
-
assert record.persisted?
|
30
|
-
assert_equal 'name', record.name
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
data/test/generators_test.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'rails/generators'
|
3
|
-
require 'generators/makers/model/model_generator'
|
4
|
-
|
5
|
-
class GeneratorsTest < Rails::Generators::TestCase
|
6
|
-
tests Makers::Generators::ModelGenerator
|
7
|
-
destination File.expand_path('../tmp', File.dirname(__FILE__))
|
8
|
-
|
9
|
-
test 'file generation' do
|
10
|
-
run_generator %w(person)
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
data/test/inheritance_test.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class InheritanceTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.define do
|
7
|
-
maker :user do
|
8
|
-
name 'name'
|
9
|
-
maker :user_with_age do
|
10
|
-
age 9
|
11
|
-
end
|
12
|
-
end
|
13
|
-
maker :user_with_email, parent: :user do
|
14
|
-
email 'mail@example.com'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'return attributes' do
|
20
|
-
user_with_age = attributes_for(:user_with_age)
|
21
|
-
assert_equal 'name', user_with_age[:name]
|
22
|
-
assert_equal 9, user_with_age[:age]
|
23
|
-
|
24
|
-
user_with_email = attributes_for(:user_with_email)
|
25
|
-
assert_equal 'name', user_with_email[:name]
|
26
|
-
assert_equal 'mail@example.com', user_with_email[:email]
|
27
|
-
end
|
28
|
-
|
29
|
-
test 'build instance' do
|
30
|
-
user_with_age = build(:user_with_age)
|
31
|
-
assert_equal 'name', user_with_age.name
|
32
|
-
assert_equal 9, user_with_age.age
|
33
|
-
|
34
|
-
user_with_email = build(:user_with_email)
|
35
|
-
assert_equal 'name', user_with_email.name
|
36
|
-
assert_equal 'mail@example.com', user_with_email.email
|
37
|
-
end
|
38
|
-
|
39
|
-
test 'create instance' do
|
40
|
-
user_with_age = create(:user_with_age)
|
41
|
-
assert_equal 'name', user_with_age.name
|
42
|
-
assert_equal 9, user_with_age.age
|
43
|
-
|
44
|
-
user_with_email = create(:user_with_email)
|
45
|
-
assert_equal 'name', user_with_email.name
|
46
|
-
assert_equal 'mail@example.com', user_with_email.email
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
data/test/lists_test.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ListsTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.define do
|
7
|
-
maker :user do
|
8
|
-
name 'name'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'build list' do
|
14
|
-
list = build(:user, 3)
|
15
|
-
assert_equal 3, list.size
|
16
|
-
list.each do |user|
|
17
|
-
assert_kind_of User, user
|
18
|
-
assert user.new_record?
|
19
|
-
assert_equal 'name', user.name
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'create list' do
|
24
|
-
list = create(:user, 3)
|
25
|
-
assert_equal 3, list.size
|
26
|
-
list.each do |user|
|
27
|
-
assert_kind_of User, user
|
28
|
-
assert user.persisted?
|
29
|
-
assert_equal 'name', user.name
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
data/test/load_test.rb
DELETED
data/test/merges_test.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MergesTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Makers.define do
|
7
|
-
maker :user do
|
8
|
-
name 'name'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'return attributes' do
|
14
|
-
assert_equal 'other', attributes_for(:user, name: 'other')[:name]
|
15
|
-
end
|
16
|
-
|
17
|
-
test 'build instance' do
|
18
|
-
assert_equal 'other', build(:user, name: 'other').name
|
19
|
-
build(:user, 3, name: 'other').each do |user|
|
20
|
-
assert_equal 'other', user.name
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'create instance' do
|
25
|
-
assert_equal 'other', create(:user, name: 'other').name
|
26
|
-
create(:user, 3, name: 'other').each do |user|
|
27
|
-
assert_equal 'other', user.name
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|