factory_data_preloader 0.5.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,13 @@
1
+ == 1.0.0.beta0 / 2010-12-21
2
+
3
+ * Added Gemfile and updated gemspec to list all dependencies
4
+ * Require all libraries needed (YAML and singleton)
5
+ * Updated tests to work with latest shoulda
6
+
7
+ == 1.0.0.beta0 / 2010-12-20
8
+
9
+ * Updating to Rails 3 compat
10
+
1
11
  == 0.5.2 / 2009-07-09
2
12
 
3
13
  * Improved backtrace output.
data/README.rdoc CHANGED
@@ -18,17 +18,15 @@ and re-use it in each test when rails rolls back the transaction.
18
18
 
19
19
  == Download
20
20
 
21
- Github: http://github.com/myronmarston/factory_data_preloader/tree/master
21
+ Github: http://github.com/myronmarston/factory_data_preloader
22
22
 
23
23
  Gem:
24
- gem install myronmarston-factory_data_preloader --source http://gems.github.com
24
+ gem install factory_data_preloader --source http://gemcutter.org
25
25
 
26
26
  == Usage
27
27
 
28
28
  Load the gem using Rails' 2.1+ gem support, in either config/environment.rb, or config/environments/test.rb:
29
- config.gem 'myronmarston-factory_data_preloader',
30
- :lib => 'factory_data_preloader',
31
- :source => 'http://gems.github.com'
29
+ config.gem 'factory_data_preloader', :source => 'http://gemcutter.org'
32
30
 
33
31
  Define your preloaded data. FactoryData will automatically require test/factory_data.rb or test/factory_data/*.rb.
34
32
  Define your data in these files like this:
@@ -91,7 +89,7 @@ at the start of each test run. If you want finer grain control over which prelo
91
89
 
92
90
  == Notes, etc.
93
91
 
94
- * This gem has been tested with Rails 2.2.2 and Rails 2.3.2.
92
+ * This gem has been tested with Rails 2.2.2, 2.3.2, 2.3.3 and 2.3.4.
95
93
  * You can create the data using any fixture replacement you want. In this contrived example, I just used ActiveRecord's
96
94
  built in methods for simplicity's sake.
97
95
  * FactoryData#preload does not actually preload the data. It simply defines the data that will be automatically preloaded
data/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
- ---
2
- :major: 0
3
- :minor: 5
4
- :patch: 2
1
+ ---
2
+ :major: 1
3
+ :minor: 0
4
+ :patch: 0
5
+ :build: 'beta0'
@@ -1,5 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
+ require 'singleton'
3
4
 
4
5
  if ENV['RAILS_VERSION']
5
6
  puts "loading Rails version #{ENV['RAILS_VERSION']}"
@@ -18,14 +19,5 @@ require 'factory_data_preloader/preloaded_data_hash'
18
19
  require 'factory_data_preloader/factory_data'
19
20
  require 'factory_data_preloader/rails_core_ext'
20
21
 
21
- if defined? Rails.configuration
22
- Rails.configuration.after_initialize do
23
- FactoryData.definition_file_paths = [
24
- File.join(RAILS_ROOT, 'test', 'factory_data'),
25
- File.join(RAILS_ROOT, 'spec', 'factory_data')
26
- ]
27
- FactoryData.find_definitions
28
- end
29
- else
30
- FactoryData.find_definitions
31
- end
22
+ require 'factory_data_preloader/railtie' if defined?(Rails)
23
+
@@ -1,5 +1,5 @@
1
1
  # TODO: add tests for this. I've manually tested this in a Rails 2.2 and 2.3 app, but haven't found a way to add
2
- # a test for this to our test suite. It's difficult to test this since it just modifies what happens before the
2
+ # a test for this to our test suite. It's difficult to test this since it just modifies what happens before the
3
3
  # tests are run.
4
4
 
5
5
  # Between Rails 2.2 and 2.3, the fixture loading code was moved from
@@ -13,7 +13,7 @@ patch_module.class_eval do
13
13
  FactoryData.preload_data!
14
14
  val
15
15
  end
16
-
16
+
17
17
  def teardown_fixtures_with_preloaded_factory_data
18
18
  FactoryData.reset_cache!
19
19
  teardown_fixtures_without_preloaded_factory_data
@@ -23,13 +23,17 @@ patch_module.class_eval do
23
23
  alias_method_chain :teardown_fixtures, :preloaded_factory_data
24
24
  end
25
25
 
26
- class Fixtures
27
- def delete_existing_fixtures_with_preloaded_factory_data
28
- delete_existing_fixtures_without_preloaded_factory_data
29
- FactoryData.delete_preload_data!
26
+ # Fixtures#delete_existing_fixtures was removed in Rails 3.1
27
+ # see: https://github.com/rails/rails/commit/f9ea47736e270152c264bb5f8fdbfaa1d04fe82f
28
+ if ActiveRecord::Fixtures.instance_methods(false).include?(:delete_existing_fixtures)
29
+ class Fixtures
30
+ def delete_existing_fixtures_with_preloaded_factory_data
31
+ delete_existing_fixtures_without_preloaded_factory_data
32
+ FactoryData.delete_preload_data!
33
+ end
34
+
35
+ alias_method_chain :delete_existing_fixtures, :preloaded_factory_data
30
36
  end
31
-
32
- alias_method_chain :delete_existing_fixtures, :preloaded_factory_data
33
37
  end
34
38
 
35
39
  class ActiveSupport::TestCase
@@ -0,0 +1,27 @@
1
+ module FactoryDataPreloader
2
+
3
+ if defined? Rails::Railtie
4
+ # Rails 3.x init
5
+ class Railtie < Rails::Railtie
6
+ config.after_initialize do
7
+ FactoryData.definition_file_paths = [
8
+ File.join(File.join(Rails.root.to_s, 'test', 'factory_data')),
9
+ File.join(File.join(Rails.root.to_s, 'spec', 'factory_data')),
10
+ ]
11
+
12
+ FactoryData.find_definitions
13
+ end
14
+ end
15
+ else
16
+ # Rails 2.x init
17
+ Rails.configuration.after_initialize do
18
+ FactoryData.definition_file_paths = [
19
+ File.join(RAILS_ROOT, 'test', 'factory_data'),
20
+ File.join(RAILS_ROOT, 'spec', 'factory_data')
21
+ ]
22
+
23
+ FactoryData.find_definitions
24
+ end
25
+ end
26
+
27
+ end
@@ -7,50 +7,68 @@ class FactoryDataTest < Test::Unit::TestCase
7
7
 
8
8
  context 'Calling FactoryData.preload(:users)' do
9
9
  setup do
10
+ @user_count = User.count
10
11
  FactoryData.preload(:users) do |data|
11
12
  data.add(:thom) { User.create(:first_name => 'Thom', :last_name => 'York') }
12
13
  end
13
14
  end
14
15
 
15
- should_not_change 'User.count'
16
- should_change "FactoryData.methods.include?('users')", :from => false, :to => true
16
+ should "not change User.count" do
17
+ assert_equal(@user_count, User.count)
18
+ end
19
+
20
+ should "change FactoryData.methods.include?('users') to true" do
21
+ assert_equal(true, FactoryData.methods.include?('users'))
22
+ end
17
23
 
18
24
  context 'when there was a previous user record in the database' do
19
25
  setup { User.create(:first_name => 'Barack', :last_name => 'Obama') }
20
26
 
21
27
  context 'and calling FactoryData.delete_preload_data!' do
22
28
  setup { FactoryData.delete_preload_data! }
23
- should_change 'User.count', :to => 0
29
+
30
+ should "change User.count to 0" do
31
+ assert_equal(0, User.count)
32
+ end
24
33
  end
25
34
  end
26
35
 
27
36
  context 'and later calling FactoryData.preload_data!' do
28
37
  setup do
38
+ @user_count = User.count
29
39
  @out, @err = OutputCapturer.capture do
30
40
  FactoryData.preload_data!
31
41
  end
32
42
  end
33
43
 
34
- should_change 'User.count', :by => 1
44
+ should "change User.count by 1" do
45
+ assert_equal(@user_count + 1, User.count)
46
+ end
35
47
 
36
48
  context 'and later re-defining the preloaders' do
37
49
  setup do
50
+ @user_count = User.count
38
51
  FactoryData.preload(:users) do |data|
39
52
  data.add(:thom) { User.create(:first_name => 'Thom', :last_name => 'York') }
40
53
  data.add(:john) { User.create(:first_name => 'John', :last_name => 'Doe') }
41
54
  end
42
55
  end
43
56
 
44
- should_change 'User.count', :by => -1
57
+ should "change User.count by - 1" do
58
+ assert_equal(@user_count - 1, User.count)
59
+ end
45
60
 
46
61
  context 'and preloading the re-defined preloader' do
47
62
  setup do
63
+ @user_count = User.count
48
64
  @out, @err = OutputCapturer.capture do
49
65
  FactoryData.preload_data!
50
66
  end
51
67
  end
52
68
 
53
- should_change 'User.count', :by => 2
69
+ should "create 2 users" do
70
+ assert_equal(@user_count + 2, User.count)
71
+ end
54
72
  end
55
73
  end
56
74
 
@@ -76,10 +94,12 @@ class FactoryDataTest < Test::Unit::TestCase
76
94
  end
77
95
 
78
96
  context 'and later calling FactoryData.reset_cache!' do
79
- setup { FactoryData.reset_cache! }
97
+ setup do
98
+ FactoryData.reset_cache!
99
+ end
80
100
 
81
101
  should 'reload the record from the database the next time FactoryData.users(key) is called' do
82
- User.expects(:find).once.returns(@user)
102
+ User.expects(:find_by_id).once.returns(@user)
83
103
  FactoryData.users(:thom)
84
104
  end
85
105
  end
@@ -20,12 +20,15 @@ class PreloaderTest < Test::Unit::TestCase
20
20
 
21
21
  context 'when preloaded' do
22
22
  setup do
23
+ @user_count = User.count
23
24
  @out, @err = OutputCapturer.capture do
24
25
  @preloader.preload!
25
26
  end
26
27
  end
27
28
 
28
- should_change 'User.count', :by => 2
29
+ should 'change User.count by 2' do
30
+ assert_equal(@user_count + 2, User.count)
31
+ end
29
32
 
30
33
  should 'return the preloaded data when #get_record is called' do
31
34
  assert_equal 'York', @preloader.get_record(:thom).last_name
@@ -39,6 +42,7 @@ class PreloaderTest < Test::Unit::TestCase
39
42
 
40
43
  context 'when preloaded again' do
41
44
  setup do
45
+ @user_count = User.count
42
46
  @out, @err = OutputCapturer.capture do
43
47
  @preloader.preload!
44
48
  end
@@ -49,7 +53,9 @@ class PreloaderTest < Test::Unit::TestCase
49
53
  assert_equal '', @out
50
54
  end
51
55
 
52
- should_not_change 'User.count'
56
+ should 'not change User.count' do
57
+ assert_equal(@user_count, User.count)
58
+ end
53
59
  end
54
60
 
55
61
  should 'issue a delete statement if #delete_table_data! is called' do
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'sqlite3'
4
5
 
5
6
  begin
6
7
  require 'ruby-debug'
metadata CHANGED
@@ -1,92 +1,147 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factory_data_preloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ prerelease:
5
+ version: 1.0.1
5
6
  platform: ruby
6
7
  authors:
7
- - Myron Marston
8
+ - Kyle J. Ginavan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-07-09 00:00:00 -07:00
13
- default_executable:
13
+ date: 2009-07-09 00:00:00 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: Shoulda
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: mocha
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: "0"
34
- version:
15
+ - !ruby/object:Gem::Dependency
16
+ name: shoulda
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.11.3
24
+ - - <
25
+ - !ruby/object:Gem::Version
26
+ version: 2.12.0
27
+ type: :development
28
+ version_requirements: *id001
29
+ - !ruby/object:Gem::Dependency
30
+ name: mocha
31
+ prerelease: false
32
+ requirement: &id002 !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.10
38
+ - - <
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.0
41
+ type: :development
42
+ version_requirements: *id002
43
+ - !ruby/object:Gem::Dependency
44
+ name: activerecord
45
+ prerelease: false
46
+ requirement: &id003 !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.3.0
52
+ type: :development
53
+ version_requirements: *id003
54
+ - !ruby/object:Gem::Dependency
55
+ name: activesupport
56
+ prerelease: false
57
+ requirement: &id004 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.3.0
63
+ type: :development
64
+ version_requirements: *id004
65
+ - !ruby/object:Gem::Dependency
66
+ name: jeweler
67
+ prerelease: false
68
+ requirement: &id005 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ type: :development
75
+ version_requirements: *id005
76
+ - !ruby/object:Gem::Dependency
77
+ name: sqlite3-ruby
78
+ prerelease: false
79
+ requirement: &id006 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.3.2
85
+ - - <
86
+ - !ruby/object:Gem::Version
87
+ version: 1.4.0
88
+ type: :development
89
+ version_requirements: *id006
35
90
  description:
36
- email: myron.marston@gmail.com
91
+ email: kylejginavan@gmail.com
37
92
  executables: []
38
93
 
39
94
  extensions: []
40
95
 
41
96
  extra_rdoc_files:
42
- - README.rdoc
43
- - LICENSE
97
+ - README.rdoc
98
+ - LICENSE
44
99
  files:
45
- - CHANGELOG.rdoc
46
- - README.rdoc
47
- - VERSION.yml
48
- - lib/factory_data_preloader/core_ext.rb
49
- - lib/factory_data_preloader/factory_data.rb
50
- - lib/factory_data_preloader/preloaded_data_hash.rb
51
- - lib/factory_data_preloader/preloader.rb
52
- - lib/factory_data_preloader/preloader_collection.rb
53
- - lib/factory_data_preloader/rails_core_ext.rb
54
- - lib/factory_data_preloader.rb
55
- - test/factory_data_test.rb
56
- - test/lib/models.rb
57
- - test/lib/schema.rb
58
- - test/preloaded_data_hash_test.rb
59
- - test/preloader_test.rb
60
- - test/test_helper.rb
61
- - LICENSE
62
- has_rdoc: true
63
- homepage: http://github.com/myronmarston/factory_data_preloader
100
+ - CHANGELOG.rdoc
101
+ - README.rdoc
102
+ - VERSION.yml
103
+ - lib/factory_data_preloader/core_ext.rb
104
+ - lib/factory_data_preloader/factory_data.rb
105
+ - lib/factory_data_preloader/preloaded_data_hash.rb
106
+ - lib/factory_data_preloader/preloader.rb
107
+ - lib/factory_data_preloader/preloader_collection.rb
108
+ - lib/factory_data_preloader/rails_core_ext.rb
109
+ - lib/factory_data_preloader/railtie.rb
110
+ - lib/factory_data_preloader.rb
111
+ - test/factory_data_test.rb
112
+ - test/lib/models.rb
113
+ - test/lib/schema.rb
114
+ - test/preloaded_data_hash_test.rb
115
+ - test/preloader_test.rb
116
+ - test/test_helper.rb
117
+ - LICENSE
118
+ homepage: http://github.com/kylejginavan/factory_data_preloader
64
119
  licenses: []
65
120
 
66
121
  post_install_message:
67
122
  rdoc_options:
68
- - --inline-source
69
- - --charset=UTF-8
123
+ - --inline-source
124
+ - --charset=UTF-8
70
125
  require_paths:
71
- - lib
126
+ - lib
72
127
  required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
73
129
  requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
77
- version:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: "0"
78
133
  required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
79
135
  requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: "0"
83
- version:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: "0"
84
139
  requirements: []
85
140
 
86
141
  rubyforge_project:
87
- rubygems_version: 1.3.5
142
+ rubygems_version: 1.8.15
88
143
  signing_key:
89
- specification_version: 2
144
+ specification_version: 3
90
145
  summary: A library for preloading test data in rails applications.
91
146
  test_files: []
92
147