challah 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -2
- data/README.md +18 -18
- data/lib/challah/test.rb +22 -5
- data/lib/challah/version.rb +1 -1
- data/test/audit_test.rb +32 -32
- data/test/controller_test.rb +9 -9
- data/test/cookie_store_test.rb +25 -25
- data/test/factories.rb +7 -7
- data/test/helper.rb +14 -12
- data/test/permission_test.rb +14 -14
- data/test/restrictions_controller_test.rb +29 -30
- data/test/role_test.rb +26 -26
- data/test/session_test.rb +65 -65
- data/test/sessions_controller_test.rb +13 -13
- data/test/simple_cookie_store_test.rb +25 -25
- data/test/user_test.rb +79 -79
- data/vendor/bundle/cache/factory_girl-3.0.0.gem +0 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Appraisals +11 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/CONTRIBUTION_GUIDELINES.md +10 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Changelog +168 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/GETTING_STARTED.md +735 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile +5 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Gemfile.lock +95 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/LICENSE +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/README.md +70 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/Rakefile +38 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/cucumber.yml +1 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/factory_girl.gemspec +38 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/factory_girl_steps.feature +237 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/find_definitions.feature +75 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/database_steps.rb +42 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/step_definitions/factory_girl_steps.rb +43 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/support/env.rb +11 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/features/support/factories.rb +119 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/2.3.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.0.gemfile.lock +86 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.1.gemfile.lock +95 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/gemfiles/3.2.gemfile.lock +93 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl.rb +69 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/aliases.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute.rb +40 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/association.rb +23 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/dynamic.rb +20 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/sequence.rb +17 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute/static.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_assigner.rb +73 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/attribute_list.rb +54 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/callback.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration.rb +22 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/association.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/dynamic.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/implicit.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration/static.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/declaration_list.rb +48 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition.rb +76 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/definition_proxy.rb +159 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/errors.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator.rb +76 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/evaluator_class_definer.rb +34 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory.rb +145 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/factory_runner.rb +24 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/find_definitions.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_factory.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/null_object.rb +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/registry.rb +46 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/reload.rb +8 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/sequence.rb +24 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/step_definitions.rb +130 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/attributes_for.rb +12 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/build.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/create.rb +17 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy/stub.rb +61 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/strategy_calculator.rb +29 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/blueprint.rb +42 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/default.rb +56 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/generate.rb +70 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/make.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/methods.rb +136 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/sham.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/syntax/vintage.rb +130 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/trait.rb +29 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/lib/factory_girl/version.rb +4 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/aliases_spec.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_aliases_spec.rb +45 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attribute_existing_on_object_spec.rb +68 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_for_spec.rb +89 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_from_instance_spec.rb +53 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/attributes_ordered_spec.rb +51 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_list_spec.rb +41 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_spec.rb +89 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/build_stubbed_spec.rb +104 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/callbacks_spec.rb +47 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_list_spec.rb +82 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/create_spec.rb +117 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/define_child_before_parent_spec.rb +21 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_spec.rb +26 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/definition_without_block_spec.rb +15 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/initialize_with_spec.rb +147 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_factories_spec.rb +184 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/modify_inherited_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/nested_attributes_spec.rb +32 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/overrides_spec.rb +61 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/parent_spec.rb +90 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/sequence_spec.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/stub_spec.rb +62 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/blueprint_spec.rb +34 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/generate_spec.rb +59 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/make_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/sham_spec.rb +43 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/syntax/vintage_spec.rb +217 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/traits_spec.rb +421 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/acceptance/transient_attributes_spec.rb +124 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/aliases_spec.rb +31 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/association_spec.rb +28 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/dynamic_spec.rb +52 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/sequence_spec.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute/static_spec.rb +19 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_list_spec.rb +78 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/attribute_spec.rb +16 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/callback_spec.rb +41 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration/implicit_spec.rb +25 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/declaration_list_spec.rb +71 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_proxy_spec.rb +197 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/definition_spec.rb +104 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/evaluator_class_definer_spec.rb +54 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/factory_spec.rb +279 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/find_definitions_spec.rb +110 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_factory_spec.rb +13 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/null_object_spec.rb +8 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/registry_spec.rb +81 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/sequence_spec.rb +47 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/attributes_for_spec.rb +18 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/build_spec.rb +7 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/create_spec.rb +13 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy/stub_spec.rb +40 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_calculator_spec.rb +33 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl/strategy_spec.rb +21 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/factory_girl_spec.rb +22 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/spec_helper.rb +26 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/macros/define_constant.rb +86 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/callback.rb +9 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/declaration.rb +71 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/delegate.rb +44 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/matchers/trait.rb +9 -0
- data/vendor/bundle/gems/factory_girl-3.0.0/spec/support/shared_examples/strategy.rb +104 -0
- data/vendor/bundle/specifications/factory_girl-3.0.0.gemspec +62 -0
- metadata +147 -12
@@ -0,0 +1,32 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "association assignment from nested attributes" do
|
4
|
+
before do
|
5
|
+
define_model("Post", title: :string) do
|
6
|
+
has_many :comments
|
7
|
+
accepts_nested_attributes_for :comments
|
8
|
+
end
|
9
|
+
|
10
|
+
define_model("Comment", post_id: :integer, body: :text) do
|
11
|
+
belongs_to :post
|
12
|
+
end
|
13
|
+
|
14
|
+
FactoryGirl.define do
|
15
|
+
factory :post do
|
16
|
+
comments_attributes { [FactoryGirl.attributes_for(:comment), FactoryGirl.attributes_for(:comment)] }
|
17
|
+
end
|
18
|
+
|
19
|
+
factory :comment do
|
20
|
+
sequence(:body) {|n| "Body #{n}" }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it "assigns the correct amount of comments" do
|
26
|
+
FactoryGirl.create(:post).comments.count.should == 2
|
27
|
+
end
|
28
|
+
|
29
|
+
it "assigns the correct amount of comments when overridden" do
|
30
|
+
FactoryGirl.create(:post, :comments_attributes => [FactoryGirl.attributes_for(:comment)]).comments.count.should == 1
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "attribute overrides" do
|
4
|
+
before do
|
5
|
+
define_model('User', admin: :boolean)
|
6
|
+
define_model('Post', title: :string,
|
7
|
+
secure: :boolean,
|
8
|
+
user_id: :integer) do
|
9
|
+
belongs_to :user
|
10
|
+
|
11
|
+
def secure=(value)
|
12
|
+
return unless user && user.admin?
|
13
|
+
write_attribute(:secure, value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
FactoryGirl.define do
|
18
|
+
factory :user do
|
19
|
+
factory :admin do
|
20
|
+
admin true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
factory :post do
|
25
|
+
user
|
26
|
+
title "default title"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
let(:admin) { FactoryGirl.create(:admin) }
|
32
|
+
|
33
|
+
let(:post_attributes) do
|
34
|
+
{ secure: false }
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:non_admin_post_attributes) do
|
38
|
+
post_attributes[:user] = FactoryGirl.create(:user)
|
39
|
+
post_attributes
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:admin_post_attributes) do
|
43
|
+
post_attributes[:user] = admin
|
44
|
+
post_attributes
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with an admin posting" do
|
48
|
+
subject { FactoryGirl.create(:post, admin_post_attributes) }
|
49
|
+
its(:secure) { should == false }
|
50
|
+
end
|
51
|
+
|
52
|
+
context "with a non-admin posting" do
|
53
|
+
subject { FactoryGirl.create(:post, non_admin_post_attributes) }
|
54
|
+
its(:secure) { should be_nil }
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with no user posting" do
|
58
|
+
subject { FactoryGirl.create(:post, post_attributes) }
|
59
|
+
its(:secure) { should be_nil }
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "an instance generated by a factory that inherits from another factory" do
|
4
|
+
before do
|
5
|
+
define_model("User", name: :string, admin: :boolean, email: :string, upper_email: :string, login: :string)
|
6
|
+
|
7
|
+
FactoryGirl.define do
|
8
|
+
factory :user do
|
9
|
+
name "John"
|
10
|
+
email { "#{name.downcase}@example.com" }
|
11
|
+
login { email }
|
12
|
+
|
13
|
+
factory :admin do
|
14
|
+
name "admin"
|
15
|
+
admin true
|
16
|
+
upper_email { email.upcase }
|
17
|
+
end
|
18
|
+
|
19
|
+
factory :guest do
|
20
|
+
email { "#{name}-guest@example.com" }
|
21
|
+
end
|
22
|
+
|
23
|
+
factory :no_email do
|
24
|
+
email ""
|
25
|
+
end
|
26
|
+
|
27
|
+
factory :bill do
|
28
|
+
name { "Bill" } #block to make attribute dynamic
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "the parent class" do
|
35
|
+
subject { FactoryGirl.create(:user) }
|
36
|
+
it { should_not be_admin }
|
37
|
+
its(:email) { should == "john@example.com" }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "the child class redefining parent's static method used by a dynamic method" do
|
41
|
+
subject { FactoryGirl.create(:admin) }
|
42
|
+
it { should be_kind_of(User) }
|
43
|
+
it { should be_admin }
|
44
|
+
its(:name) { should == "admin" }
|
45
|
+
its(:email) { should == "admin@example.com" }
|
46
|
+
its(:upper_email) { should == "ADMIN@EXAMPLE.COM"}
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "the child class redefining parent's dynamic method" do
|
50
|
+
subject { FactoryGirl.create(:guest) }
|
51
|
+
it { should_not be_admin }
|
52
|
+
its(:name) { should == "John" }
|
53
|
+
its(:email) { should eql "John-guest@example.com" }
|
54
|
+
its(:login) { should == "John-guest@example.com" }
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "the child class redefining parent's dynamic attribute with static attribute" do
|
58
|
+
subject { FactoryGirl.create(:no_email) }
|
59
|
+
its(:email) { should == "" }
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "the child class redefining parent's static attribute with dynamic attribute" do
|
63
|
+
subject { FactoryGirl.create(:bill) }
|
64
|
+
its(:name) { should == "Bill" }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "nested factories with different parents" do
|
69
|
+
before do
|
70
|
+
define_model("User", name: :string)
|
71
|
+
|
72
|
+
FactoryGirl.define do
|
73
|
+
factory :user do
|
74
|
+
name "Basic User"
|
75
|
+
|
76
|
+
factory :male_user do
|
77
|
+
name "John Doe"
|
78
|
+
end
|
79
|
+
|
80
|
+
factory :uppercase_male_user, parent: :male_user do
|
81
|
+
after_build {|user| user.name = user.name.upcase }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "honors :parent over the factory block nesting" do
|
88
|
+
FactoryGirl.build(:uppercase_male_user).name.should == "JOHN DOE"
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "sequences" do
|
4
|
+
include FactoryGirl::Syntax::Methods
|
5
|
+
|
6
|
+
it "generates several values in the correct format" do
|
7
|
+
FactoryGirl.define do
|
8
|
+
sequence :email do |n|
|
9
|
+
"somebody#{n}@example.com"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
first_value = generate(:email)
|
14
|
+
another_value = generate(:email)
|
15
|
+
|
16
|
+
first_value.should =~ /^somebody\d+@example\.com$/
|
17
|
+
another_value.should =~ /^somebody\d+@example\.com$/
|
18
|
+
first_value.should_not == another_value
|
19
|
+
end
|
20
|
+
|
21
|
+
it "generates sequential numbers if no block is given" do
|
22
|
+
FactoryGirl.define do
|
23
|
+
sequence :order
|
24
|
+
end
|
25
|
+
|
26
|
+
first_value = generate(:order)
|
27
|
+
another_value = generate(:order)
|
28
|
+
|
29
|
+
first_value.should == 1
|
30
|
+
another_value.should == 2
|
31
|
+
first_value.should_not == another_value
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "a stubbed instance" do
|
4
|
+
include FactoryGirl::Syntax::Methods
|
5
|
+
|
6
|
+
before do
|
7
|
+
define_model('User')
|
8
|
+
|
9
|
+
define_model('Post', user_id: :integer) do
|
10
|
+
belongs_to :user
|
11
|
+
end
|
12
|
+
|
13
|
+
FactoryGirl.define do
|
14
|
+
factory :user
|
15
|
+
|
16
|
+
factory :post do
|
17
|
+
user
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
subject { build_stubbed(:post) }
|
23
|
+
|
24
|
+
it "acts as if it came from the database" do
|
25
|
+
should_not be_new_record
|
26
|
+
end
|
27
|
+
|
28
|
+
it "assigns associations and acts as if it is saved" do
|
29
|
+
subject.user.should be_kind_of(User)
|
30
|
+
subject.user.should_not be_new_record
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "a stubbed instance overriding strategy" do
|
35
|
+
include FactoryGirl::Syntax::Methods
|
36
|
+
|
37
|
+
before do
|
38
|
+
define_model('User')
|
39
|
+
define_model('Post', user_id: :integer) do
|
40
|
+
belongs_to :user
|
41
|
+
end
|
42
|
+
|
43
|
+
FactoryGirl.define do
|
44
|
+
factory :user
|
45
|
+
|
46
|
+
factory :post do
|
47
|
+
association(:user, strategy: :build)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
subject { build_stubbed(:post) }
|
53
|
+
|
54
|
+
it "acts as if it is saved in the database" do
|
55
|
+
should_not be_new_record
|
56
|
+
end
|
57
|
+
|
58
|
+
it "assigns associations and acts as if it is saved" do
|
59
|
+
subject.user.should be_kind_of(User)
|
60
|
+
subject.user.should_not be_new_record
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'factory_girl/syntax/blueprint'
|
4
|
+
|
5
|
+
describe "a blueprint" do
|
6
|
+
before do
|
7
|
+
define_model('User', first_name: :string, last_name: :string, email: :string)
|
8
|
+
|
9
|
+
FactoryGirl.define do
|
10
|
+
sequence(:email) { |n| "somebody#{n}@example.com" }
|
11
|
+
end
|
12
|
+
|
13
|
+
User.blueprint do
|
14
|
+
first_name { 'Bill' }
|
15
|
+
last_name { 'Nye' }
|
16
|
+
email { FactoryGirl.generate(:email) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "after making an instance" do
|
21
|
+
before do
|
22
|
+
@instance = FactoryGirl.create(:user, last_name: 'Rye')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "uses attributes from the blueprint" do
|
26
|
+
@instance.first_name.should == 'Bill'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "evaluates attribute blocks for each instance" do
|
30
|
+
@instance.email.should =~ /somebody\d+@example.com/
|
31
|
+
FactoryGirl.create(:user).email.should_not == @instance.email
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'factory_girl/syntax/generate'
|
4
|
+
|
5
|
+
describe "a factory using generate syntax" do
|
6
|
+
before do
|
7
|
+
define_model('User', first_name: :string, last_name: :string, email: :string) do
|
8
|
+
validates_presence_of :first_name
|
9
|
+
end
|
10
|
+
|
11
|
+
FactoryGirl.define do
|
12
|
+
factory :user do
|
13
|
+
first_name 'Bill'
|
14
|
+
last_name 'Nye'
|
15
|
+
email 'science@guys.net'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does not raise an error when generating an invalid instance" do
|
21
|
+
expect { User.generate(first_name: nil) }.to_not raise_error
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises an error when forcefully generating an invalid instance" do
|
25
|
+
expect { User.generate!(first_name: nil) }.to raise_error(ActiveRecord::RecordInvalid)
|
26
|
+
end
|
27
|
+
|
28
|
+
%w(generate generate! spawn).each do |method|
|
29
|
+
it "yields a generated instance when using #{method} with a block" do
|
30
|
+
saved_instance = nil
|
31
|
+
User.send(method) {|instance| saved_instance = instance }
|
32
|
+
saved_instance.should be_kind_of(User)
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "after generating an instance using #{method}" do
|
36
|
+
before do
|
37
|
+
@instance = User.send(method, last_name: 'Rye')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "uses attributes from the factory" do
|
41
|
+
@instance.first_name.should == 'Bill'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "uses attributes passed to generate" do
|
45
|
+
@instance.last_name.should == 'Rye'
|
46
|
+
end
|
47
|
+
|
48
|
+
if method == 'spawn'
|
49
|
+
it "does not save the record" do
|
50
|
+
@instance.should be_new_record
|
51
|
+
end
|
52
|
+
else
|
53
|
+
it "does save the record" do
|
54
|
+
@instance.should_not be_new_record
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'factory_girl/syntax/make'
|
4
|
+
|
5
|
+
describe "a factory using make syntax" do
|
6
|
+
before do
|
7
|
+
define_model('User', first_name: :string, last_name: :string)
|
8
|
+
|
9
|
+
FactoryGirl.define do
|
10
|
+
factory :user do
|
11
|
+
first_name 'Bill'
|
12
|
+
last_name 'Nye'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "after make" do
|
18
|
+
before do
|
19
|
+
@instance = User.make(last_name: 'Rye')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "uses attributes from the factory" do
|
23
|
+
@instance.first_name.should == 'Bill'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "uses attributes passed to make" do
|
27
|
+
@instance.last_name.should == 'Rye'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "builds the record" do
|
31
|
+
@instance.should be_new_record
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "after make!" do
|
36
|
+
before do
|
37
|
+
@instance = User.make!(last_name: 'Rye')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "uses attributes from the factory" do
|
41
|
+
@instance.first_name.should == 'Bill'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "uses attributes passed to make" do
|
45
|
+
@instance.last_name.should == 'Rye'
|
46
|
+
end
|
47
|
+
|
48
|
+
it "saves the record" do
|
49
|
+
@instance.should_not be_new_record
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'factory_girl/syntax/sham'
|
4
|
+
|
5
|
+
describe "a factory using sham syntax" do
|
6
|
+
before do
|
7
|
+
define_model('User', first_name: :string,
|
8
|
+
last_name: :string,
|
9
|
+
email: :string,
|
10
|
+
username: :string)
|
11
|
+
|
12
|
+
Sham.name { "Name" }
|
13
|
+
Sham.email { "somebody#{rand(5)}@example.com" }
|
14
|
+
Sham.username("FOO") { |c| "User-#{c}" }
|
15
|
+
|
16
|
+
FactoryGirl.define do
|
17
|
+
factory :user do
|
18
|
+
first_name { Sham.name }
|
19
|
+
last_name { Sham.name }
|
20
|
+
email { Sham.email }
|
21
|
+
username { Sham.username }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "after making an instance" do
|
27
|
+
before do
|
28
|
+
@instance = FactoryGirl.create(:user, last_name: 'Rye')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "supports a sham called 'name'" do
|
32
|
+
@instance.first_name.should == 'Name'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "supports shams with starting values" do
|
36
|
+
@instance.username.should == 'User-FOO'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "uses the sham for the email" do
|
40
|
+
@instance.email.should =~ /somebody\d@example.com/
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|