seed_helper 1.12.1 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/lib/seed_helper/bulk_create.rb +3 -2
- data/lib/seed_helper/version.rb +1 -1
- data/spec/lib/seed_helper/bulk_create_spec.rb +59 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae0b1795ee954109ba5e4af5df7e2e21fc232cb9
|
4
|
+
data.tar.gz: 6d9b60708a60de8ee5dd3b9fbd45c559a97726b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eee2d8e04423853ddd81a76e096a35a6e7a539dc78f89a1022e1554eca71da302e15549388f4c175c5e02399710ce0c0a1a3ec8eb1b1cd432477775a353613bc
|
7
|
+
data.tar.gz: 1eae4cad7d6f9c424454414c8c3e500ba7cd26ea5bcebd47e0d0a78da01809f7aa8ae8a2e0977ed3f3d4a47d3b222d4e704c7a967792e0f896905080fb2ea159
|
data/README.md
CHANGED
@@ -98,6 +98,21 @@ Client.all.each do |client|
|
|
98
98
|
FactoryGirl.create_list(:user, 5, client_attributes)
|
99
99
|
end
|
100
100
|
end
|
101
|
+
```
|
102
|
+
|
103
|
+
You can pass a custom message through:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
Client.all.each do |client|
|
107
|
+
SeedHelper.bulk_create(User, {client_id: client.id}, "Users for #{client.name}") do |client_attributes|
|
108
|
+
FactoryGirl.create_list(:user, 5, client_attributes)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Users for DeathCorp already exists
|
113
|
+
# Created Users for DeathCorp
|
114
|
+
# Failed to create Users for DeathCorp
|
115
|
+
```
|
101
116
|
|
102
117
|
## Example: Output
|
103
118
|
|
@@ -11,9 +11,10 @@ module SeedHelper::BulkCreate
|
|
11
11
|
# @param [Class] resource_class: The class to create the resource in. EG: User
|
12
12
|
# @param [Hash] identifiable_attributes: A hash of attributes and values that can be used to
|
13
13
|
# identify the given resource. EG: {email: "jordan@example.com"}
|
14
|
+
# @params [String] output_text: The text to output in the results
|
14
15
|
# @params [Proc] creation_block: A block that will create some objects
|
15
|
-
def bulk_create(klass, identifiable_attributes={}, &creation_block)
|
16
|
-
message_identifier = bulk_create_message_identifier(klass, identifiable_attributes)
|
16
|
+
def bulk_create(klass, identifiable_attributes={}, output_text=nil, &creation_block)
|
17
|
+
message_identifier = output_text || bulk_create_message_identifier(klass, identifiable_attributes)
|
17
18
|
|
18
19
|
if klass.where(identifiable_attributes).exists?
|
19
20
|
resource_already_exists(message_identifier)
|
data/lib/seed_helper/version.rb
CHANGED
@@ -3,9 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe SeedHelper::BulkCreate do
|
4
4
|
|
5
5
|
describe '#bulk_create' do
|
6
|
-
subject { SeedHelper.bulk_create(User, identifiable_attributes) { User.create(email: email)} }
|
6
|
+
subject { SeedHelper.bulk_create(User, identifiable_attributes, custom_message) { User.create(email: email)} }
|
7
7
|
|
8
|
-
let(:
|
8
|
+
let(:custom_message) { nil }
|
9
|
+
let(:email) { "jordan@example.com" }
|
9
10
|
|
10
11
|
context "with identifiable_attributes" do
|
11
12
|
let(:identifiable_attributes) { {email: email} }
|
@@ -13,9 +14,20 @@ describe SeedHelper::BulkCreate do
|
|
13
14
|
context "when a User with those attributes already exists" do
|
14
15
|
before { User.create!(email: email) }
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
context "with a custom message" do
|
18
|
+
let(:custom_message) { "Reps 4 Jesus" }
|
19
|
+
|
20
|
+
it "sends an 'already exists' message" do
|
21
|
+
expect(SeedHelper).to receive(:resource_already_exists).with("Reps 4 Jesus")
|
22
|
+
subject
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "without a custom message" do
|
27
|
+
it "sends an 'already exists' message" do
|
28
|
+
expect(SeedHelper).to receive(:resource_already_exists).with("Users ({:email=>\"jordan@example.com\"})")
|
29
|
+
subject
|
30
|
+
end
|
19
31
|
end
|
20
32
|
end
|
21
33
|
|
@@ -26,9 +38,20 @@ describe SeedHelper::BulkCreate do
|
|
26
38
|
expect { subject }.to change { User.count }.by(1)
|
27
39
|
end
|
28
40
|
|
29
|
-
|
30
|
-
|
31
|
-
|
41
|
+
context "with a custom message" do
|
42
|
+
let(:custom_message) { "Reps 4 Jesus" }
|
43
|
+
|
44
|
+
it "prints a success message" do
|
45
|
+
expect(SeedHelper).to receive(:success).with("Created Reps 4 Jesus")
|
46
|
+
subject
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "without a custom message" do
|
51
|
+
it "prints a success message" do
|
52
|
+
expect(SeedHelper).to receive(:success).with("Created Users ({:email=>\"jordan@example.com\"})")
|
53
|
+
subject
|
54
|
+
end
|
32
55
|
end
|
33
56
|
end
|
34
57
|
end
|
@@ -39,9 +62,20 @@ describe SeedHelper::BulkCreate do
|
|
39
62
|
context "when a User already exists" do
|
40
63
|
before { User.create! }
|
41
64
|
|
42
|
-
|
43
|
-
|
44
|
-
|
65
|
+
context "with a custom message" do
|
66
|
+
let(:custom_message) { "Reps 4 Jesus" }
|
67
|
+
|
68
|
+
it "sends an 'already exists' message" do
|
69
|
+
expect(SeedHelper).to receive(:resource_already_exists).with("Reps 4 Jesus")
|
70
|
+
subject
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "without a custom message" do
|
75
|
+
it "sends an 'already exists' message" do
|
76
|
+
expect(SeedHelper).to receive(:resource_already_exists).with("Users")
|
77
|
+
subject
|
78
|
+
end
|
45
79
|
end
|
46
80
|
end
|
47
81
|
|
@@ -50,9 +84,20 @@ describe SeedHelper::BulkCreate do
|
|
50
84
|
expect { subject }.to change { User.count }.to(1)
|
51
85
|
end
|
52
86
|
|
53
|
-
|
54
|
-
|
55
|
-
|
87
|
+
context "with a custom message" do
|
88
|
+
let(:custom_message) { "Reps 4 Jesus" }
|
89
|
+
|
90
|
+
it "prints a success message" do
|
91
|
+
expect(SeedHelper).to receive(:success).with("Created Reps 4 Jesus")
|
92
|
+
subject
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "without a custom message" do
|
97
|
+
it "prints a success message" do
|
98
|
+
expect(SeedHelper).to receive(:success).with("Created Users")
|
99
|
+
subject
|
100
|
+
end
|
56
101
|
end
|
57
102
|
end
|
58
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seed_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Maguire
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|