factory_girl_mongo_syntax 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in factory_girl_mongo_syntax.gemspec
4
+ gemspec
5
+
6
+ gem "factory_girl"
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+
3
+ require "bundler/gem_tasks"
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Default: run specs.'
7
+ task :default => :spec
8
+
9
+ desc 'Run all the specs for the gem.'
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "factory_girl_mongo_syntax/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "factory_girl_mongo_syntax"
7
+ s.version = FactoryGirlMongoSyntax::VERSION
8
+ s.authors = ["Adnan Ali"]
9
+ s.email = ["adnan.ali@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = "Adds factory girl alternate (Machinist) syntax to MongoMapper"
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "factory_girl_mongo_syntax"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "mongo"
24
+ s.add_development_dependency "mongo_mapper"
25
+ s.add_development_dependency "rake"
26
+ s.add_runtime_dependency "factory_girl"
27
+ end
@@ -0,0 +1,42 @@
1
+ module FactoryGirl
2
+ module Syntax
3
+
4
+ # Extends ActiveRecord::Base to provide a make class method, which is an
5
+ # alternate syntax for defining factories.
6
+ #
7
+ # Usage:
8
+ #
9
+ # require 'factory_girl/syntax/blueprint'
10
+ #
11
+ # User.blueprint do
12
+ # name { 'Billy Bob' }
13
+ # email { 'billy@bob.example.com' }
14
+ # end
15
+ #
16
+ # FactoryGirl.create(:user, :name => 'Johnny')
17
+ #
18
+ # This syntax was derived from Pete Yandell's machinist.
19
+ module Blueprint
20
+ module ActiveRecord #:nodoc:
21
+
22
+ def self.included(base) # :nodoc:
23
+ base.extend ClassMethods
24
+ end
25
+
26
+ module ClassMethods #:nodoc:
27
+
28
+ def blueprint(&block)
29
+ instance = Factory.new(name.underscore, :class => self)
30
+ proxy = FactoryGirl::DefinitionProxy.new(instance)
31
+ proxy.instance_eval(&block)
32
+ FactoryGirl.register_factory(instance)
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ ActiveRecord::Base.send(:include, FactoryGirl::Syntax::Blueprint::ActiveRecord)
@@ -0,0 +1,45 @@
1
+ module FactoryGirl
2
+ module Syntax
3
+
4
+ # Extends ActiveRecord::Base to provide a make class method, which is a
5
+ # shortcut for FactoryGirl.create.
6
+ #
7
+ # Usage:
8
+ #
9
+ # require 'factory_girl/syntax/make'
10
+ #
11
+ # FactoryGirl.define do
12
+ # factory :user do
13
+ # name 'Billy Bob'
14
+ # email 'billy@bob.example.com'
15
+ # end
16
+ # end
17
+ #
18
+ # User.make(:name => 'Johnny')
19
+ #
20
+ # This syntax was derived from Pete Yandell's machinist.
21
+ module Make
22
+ module ActiveRecord #:nodoc:
23
+
24
+ def self.included(base) # :nodoc:
25
+ base.extend ClassMethods
26
+ end
27
+
28
+ module ClassMethods #:nodoc:
29
+
30
+ def make(overrides = {})
31
+ FactoryGirl.factory_by_name(name.underscore).run(Proxy::Build, overrides)
32
+ end
33
+
34
+ def make!(overrides = {})
35
+ FactoryGirl.factory_by_name(name.underscore).run(Proxy::Create, overrides)
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ ActiveRecord::Base.send(:include, FactoryGirl::Syntax::Make::ActiveRecord)
@@ -0,0 +1,77 @@
1
+ # This code was taken from https://github.com/thoughtbot/factory_girl/tree/master/lib/factory_girl/syntax
2
+ # (blueprint and make) and modified for MongoMapper
3
+
4
+ module FactoryGirl
5
+ module Syntax
6
+
7
+ # Extends MongoMapper::Document to provide a make class method, which is an
8
+ # alternate syntax for defining factories.
9
+ #
10
+ # Usage:
11
+ #
12
+ # require 'factory_girl/syntax/mongo_mapper'
13
+ #
14
+ # User.blueprint do
15
+ # name { 'Billy Bob' }
16
+ # email { 'billy@bob.example.com' }
17
+ # end
18
+ #
19
+ # FactoryGirl.create(:user, :name => 'Johnny')
20
+ #
21
+ # This syntax was derived from Pete Yandell's machinist.
22
+ module Blueprint
23
+ module MongoMapper extend ActiveSupport::Concern #:nodoc:
24
+
25
+ module ClassMethods #:nodoc:
26
+
27
+ def blueprint(&block)
28
+ instance = Factory.new(name.underscore, :class => self)
29
+ proxy = FactoryGirl::DefinitionProxy.new(instance)
30
+ proxy.instance_eval(&block)
31
+ FactoryGirl.register_factory(instance)
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
38
+
39
+ # Extends MongoMapper::Document to provide a make class method, which is a
40
+ # shortcut for FactoryGirl.create.
41
+ #
42
+ # Usage:
43
+ #
44
+ # require 'factory_girl/syntax/mongo_mapper'
45
+ #
46
+ # FactoryGirl.define do
47
+ # factory :user do
48
+ # name 'Billy Bob'
49
+ # email 'billy@bob.example.com'
50
+ # end
51
+ # end
52
+ #
53
+ # User.make(:name => 'Johnny')
54
+ #
55
+ # This syntax was derived from Pete Yandell's machinist.
56
+ module Make
57
+ module MongoMapper extend ActiveSupport::Concern #:nodoc:
58
+
59
+ module ClassMethods #:nodoc:
60
+
61
+ def make(overrides = {})
62
+ FactoryGirl.factory_by_name(name.underscore).run(Proxy::Build, overrides)
63
+ end
64
+
65
+ def make!(overrides = {})
66
+ FactoryGirl.factory_by_name(name.underscore).run(Proxy::Create, overrides)
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ MongoMapper::Document.plugin(FactoryGirl::Syntax::Blueprint::MongoMapper)
77
+ MongoMapper::Document.plugin(FactoryGirl::Syntax::Make::MongoMapper)
@@ -0,0 +1,3 @@
1
+ module FactoryGirlMongoSyntax
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ if defined?(MongoMapper)
4
+ require 'factory_girl/syntax/mongo_mapper/make'
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 "should use attributes from the factory" do
23
+ @instance.first_name.should == 'Bill'
24
+ end
25
+
26
+ it "should use attributes passed to make" do
27
+ @instance.last_name.should == 'Rye'
28
+ end
29
+
30
+ it "should build 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 "should use attributes from the factory" do
41
+ @instance.first_name.should == 'Bill'
42
+ end
43
+
44
+ it "should use attributes passed to make" do
45
+ @instance.last_name.should == 'Rye'
46
+ end
47
+
48
+ it "should save the record" do
49
+ @instance.should_not be_new_record
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,79 @@
1
+ require "spec_helper"
2
+
3
+ require 'mongo_mapper'
4
+ require "factory_girl/syntax/mongo_mapper"
5
+
6
+ RSpec.configure do |config|
7
+ MongoMapper.database = "factory_girl_mongomapper"
8
+ end
9
+
10
+ class User
11
+ include MongoMapper::Document
12
+
13
+ key :first_name, String
14
+ key :last_name, String
15
+ key :email, String
16
+ end
17
+
18
+ Factory.sequence(:email) { |n| "somebody#{n}@example.com" }
19
+ User.blueprint do
20
+ first_name { 'Bill' }
21
+ last_name { 'Nye' }
22
+ email { FactoryGirl.generate(:email) }
23
+ end
24
+
25
+ describe "a mongo_mapper blueprint" do
26
+ describe "after making an instance" do
27
+ before do
28
+ @instance = FactoryGirl.create(:user, :last_name => 'Rye')
29
+ end
30
+
31
+ it "should use attributes from the blueprint" do
32
+ @instance.first_name.should == 'Bill'
33
+ end
34
+
35
+ it "should evaluate attribute blocks for each instance" do
36
+ @instance.email.should =~ /somebody\d+@example.com/
37
+ FactoryGirl.create(:user).email.should_not == @instance.email
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "a factory using make syntax" do
43
+
44
+ describe "after make" do
45
+ before do
46
+ @instance = User.make(:last_name => 'Rye')
47
+ end
48
+
49
+ it "should use attributes from the factory" do
50
+ @instance.first_name.should == 'Bill'
51
+ end
52
+
53
+ it "should use attributes passed to make" do
54
+ @instance.last_name.should == 'Rye'
55
+ end
56
+
57
+ it "should build the record" do
58
+ @instance.should be_new_record
59
+ end
60
+ end
61
+
62
+ describe "after make!" do
63
+ before do
64
+ @instance = User.make!(:last_name => 'Rye')
65
+ end
66
+
67
+ it "should use attributes from the factory" do
68
+ @instance.first_name.should == 'Bill'
69
+ end
70
+
71
+ it "should use attributes passed to make" do
72
+ @instance.last_name.should == 'Rye'
73
+ end
74
+
75
+ it "should save the record" do
76
+ @instance.should_not be_new_record
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
2
+ require "rubygems"
3
+ require "rspec"
4
+ require "factory_girl"
5
+
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: factory_girl_mongo_syntax
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Adnan Ali
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-05 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: mongo
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: mongo_mapper
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: factory_girl
61
+ requirement: &id005 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ type: :runtime
68
+ prerelease: false
69
+ version_requirements: *id005
70
+ description: Adds factory girl alternate (Machinist) syntax to MongoMapper
71
+ email:
72
+ - adnan.ali@gmail.com
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files: []
78
+
79
+ files:
80
+ - .gitignore
81
+ - .rspec
82
+ - Gemfile
83
+ - Rakefile
84
+ - factory_girl_mongo_syntax.gemspec
85
+ - lib/factory_girl/syntax/blueprint.rb
86
+ - lib/factory_girl/syntax/make.rb
87
+ - lib/factory_girl/syntax/mongo_mapper.rb
88
+ - lib/factory_girl_mongo_syntax/version.rb
89
+ - spec/make_spec.rb
90
+ - spec/mongo_mapper_spec.rb
91
+ - spec/spec_helper.rb
92
+ homepage: ""
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 460626798423007665
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 460626798423007665
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project: factory_girl_mongo_syntax
121
+ rubygems_version: 1.8.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Adds factory girl alternate (Machinist) syntax to MongoMapper
125
+ test_files:
126
+ - spec/make_spec.rb
127
+ - spec/mongo_mapper_spec.rb
128
+ - spec/spec_helper.rb