active_factory 0.1.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.
@@ -0,0 +1,14 @@
1
+ require "#{File.dirname(__FILE__)}/spec_helper"
2
+ require 'support/active_record_environment'
3
+
4
+ describe User do
5
+ include ActiveRecordEnvironment
6
+
7
+ before(:each) do
8
+ empty_database!
9
+ end
10
+
11
+ it "can create user" do
12
+ User.create!
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ class ActiveFactory::Define
2
+ # model class will be inferred from factory name: User
3
+ # i - refers to an index of the instance
4
+ factory :user do
5
+ email { "user#{i}@tut.by" }
6
+ password { "password#{i}#{i}" }
7
+ end
8
+
9
+ factory :post, :class => Post do
10
+ text { "Content #{index}" }
11
+ end
12
+
13
+ factory :simple_user, :class => User do
14
+ email "simple_user@gmail.com"
15
+ password "simple_password"
16
+ end
17
+
18
+ factory :post_with_after_build, :class => Post do
19
+ text "Post with after_build"
20
+ after_build { model.text = "After Build #{i}" }
21
+ end
22
+
23
+ factory :post_with_before_save, :class => Post do
24
+ text "Post with before_save"
25
+ before_save { model.text = "Before Save #{i}" }
26
+ end
27
+
28
+ factory :post_overrides_method, :class => Post do
29
+ text "Post overrides a method"
30
+ end
31
+
32
+ factory :follower, :class => User do
33
+ prefer_associations :following
34
+ end
35
+
36
+ factory :user_with_parent, :parent => :user do
37
+ password { "overriden" }
38
+ end
39
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'rspec'
@@ -0,0 +1,46 @@
1
+ require 'active_record'
2
+
3
+ ActiveRecord::Base.establish_connection(
4
+ :adapter => "sqlite3",
5
+ :database => ":memory:"
6
+ )
7
+
8
+ ActiveRecord::Schema.define(:version => 0) do
9
+ create_table "posts", :force => true do |t|
10
+ t.text "text"
11
+ t.integer "user_id"
12
+ end
13
+
14
+ create_table "users", :force => true do |t|
15
+ t.string "email", :default => "", :null => false
16
+ end
17
+
18
+ create_table "following", :force => true, :id => false do |t|
19
+ t.integer "following_id"
20
+ t.integer "follower_id"
21
+ end
22
+
23
+ end
24
+
25
+ class User < ActiveRecord::Base
26
+ has_many :posts
27
+ has_and_belongs_to_many :followers, :class_name => 'User', :join_table => 'following',
28
+ :foreign_key => 'following_id', :association_foreign_key => 'follower_id'
29
+ has_and_belongs_to_many :following, :class_name => 'User', :join_table => 'following',
30
+ :foreign_key => 'follower_id', :association_foreign_key => 'following_id'
31
+ attr_accessor :password
32
+ end
33
+
34
+ class Post < ActiveRecord::Base
35
+ belongs_to :user
36
+ end
37
+
38
+ module ActiveRecordEnvironment
39
+
40
+ def empty_database!
41
+ [User, Post].each do |klass|
42
+ klass.delete_all
43
+ end
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_factory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexey Tarasevich
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-04-21 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Fixtures replacement with sweet syntax
15
+ email: ''
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - README.rdoc
20
+ - lib/active_factory.rb
21
+ - lib/generators/active_factory/install/USAGE
22
+ - lib/generators/active_factory/install/install_generator.rb
23
+ - lib/generators/active_factory/install/templates/active_factory.rb
24
+ - lib/generators/active_factory/install/templates/define_factories.rb
25
+ - lib/hash_struct.rb
26
+ files:
27
+ - MIT-LICENSE
28
+ - README.rdoc
29
+ - Rakefile
30
+ - init.rb
31
+ - lib/active_factory.rb
32
+ - lib/generators/active_factory/install/USAGE
33
+ - lib/generators/active_factory/install/install_generator.rb
34
+ - lib/generators/active_factory/install/templates/active_factory.rb
35
+ - lib/generators/active_factory/install/templates/define_factories.rb
36
+ - lib/hash_struct.rb
37
+ - spec/active_factory_define_spec.rb
38
+ - spec/active_factory_spec.rb
39
+ - spec/active_record_environment_spec.rb
40
+ - spec/define_lib_factories.rb
41
+ - spec/spec_helper.rb
42
+ - spec/support/active_record_environment.rb
43
+ - Manifest
44
+ - active_factory.gemspec
45
+ homepage: http://github.com/tarasevich/active_factory
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --line-numbers
50
+ - --inline-source
51
+ - --title
52
+ - Active_factory
53
+ - --main
54
+ - README.rdoc
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ requirements: []
70
+ rubyforge_project: active_factory
71
+ rubygems_version: 1.7.2
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Fixtures replacement with sweet syntax
75
+ test_files: []