fixture_replacement 4.0.0 → 4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9639be9a13dc9d214ce4bec09d30d6db2fb474da7da46a9cfb1e342d634dbc9d
4
- data.tar.gz: 05bbb4be36f092820dfabbef75df7f6e08dc9bc944ba42de8d7e4bb73eaa5cdf
3
+ metadata.gz: 70ad8e924533702d5954ff854992ca3d215090e5e97e7f4e47221d51f04aebf4
4
+ data.tar.gz: 69ffca95d0436db069bcf3e536d87704414702db8ed3f037bb313372e443d871
5
5
  SHA512:
6
- metadata.gz: 1d571d591cc6db036d8832ab0833bb2738e95cb4677584c6de56d04136b72ca52c2b9f30d90b11820435e89bfae82e8a311e05346fc10b4ea9d08b5ff3f8442e
7
- data.tar.gz: ada4710268617f3654d5ee829005df56c9606a412e5b0905aa4203cded58bdbacb13eb9145c3e64b1099d35abdd87dc752e34d9bce0f78a1650785d8dc7a1597
6
+ metadata.gz: d66a2d0b581d785c5ff26144cbea3b2e724454ed151d1de19f35aacba3582d87df7fdcda2d0e43c400933fd18cbe494d3c043244577156c1230669fb9dc6fc43
7
+ data.tar.gz: 2261fdb8e7b312e73162b9d10c0e761cae31f00448827238904d6785c5827d04f72d5e0a73b72b6dda11461d814a2ff59b53896d541c2fe18b796ce85f3dbacd
data/CHANGELOG.rdoc CHANGED
@@ -1,7 +1,25 @@
1
+ == 4.1.0
2
+
3
+ * add more helpers:
4
+ * random_incrementing_number
5
+ * random_email
6
+ * random_first_name
7
+ * random_last_name
8
+ * random_name
9
+
10
+ Most of these call faker; so you'll need that library for most of these methods.
11
+ * rename FixtureReplacement.load_example_data => FixtureReplacement.load!
12
+ * bug fixes pertaining to module_method
13
+ * remove default_* methods, which were deprecated
14
+
15
+ == 4.0.1
16
+
17
+ - Minor release fixes
18
+
1
19
  == 4.0.0
2
20
 
3
- - Update for most recent rails / rspec (rails 7+).
4
- - This gem hasn't been updated for over 10+ years. So this is a welcome change!
21
+ - Update for most recent rails / rspec (rails 7+).
22
+ - This gem hasn't been updated for over 10+ years. So this is a needed change!
5
23
 
6
24
  == 3.0.1
7
25
 
data/README.rdoc CHANGED
@@ -1,12 +1,16 @@
1
- = FixtureReplacement (version 3.0.1)
1
+ = FixtureReplacement
2
2
 
3
- == What is FixtureReplacement
3
+ == What is FixtureReplacement?
4
4
 
5
- FixtureReplacement is a Rails[http://rubyonrails.org/] plugin that provides a simple way to
5
+ FixtureReplacement is a Rails gem that provides a simple way to
6
6
  quickly populate your test database with model objects without having to manage multiple,
7
7
  brittle fixture files. You can easily set up complex object graphs (with models which
8
8
  reference other models) and add new objects on the fly.
9
9
 
10
+ (If you've ever used FactoryGirl / FactoryBot, you're probably already quite familiar with
11
+ fixture_replacement, as it proceeded FactoryGirl. Also, FR is much more opinionated, and
12
+ much less PC!)
13
+
10
14
  Not only can FixtureReplacement make your test data easier to maintain, it can also help
11
15
  to make your tests and specs much more readable and intention-revealing by allowing you
12
16
  to omit extraneous details and focus only on the attributes that are important for a
@@ -22,9 +26,11 @@ See CHANGELOG.rdoc + test suite for further changes.
22
26
 
23
27
  == Installation
24
28
 
25
- Install the plugin:
29
+ Add it to your Gemfile:
26
30
 
27
- git://github.com/smtlaissezfaire/fixturereplacement.git
31
+ group :development, :test do
32
+ gem "fixture_replacement", "~> 4.0"
33
+ end
28
34
 
29
35
  === Using it with RSpec
30
36
 
@@ -139,4 +145,4 @@ See contributions.rdoc
139
145
 
140
146
  This software is dual licensed under the MIT and the GPLv3 Licenses (it's your pick).
141
147
 
142
- Copyright 2007-2009 Scott Taylor / smtlaissezfaire[http://github.com/smtlaissezfaire] (scott@railsnewbie.com)
148
+ Copyright 2007-2022 Scott Taylor / smtlaissezfaire[http://github.com/smtlaissezfaire] (scott@railsnewbie.com)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.0
1
+ 4.1.0
@@ -1,7 +1,9 @@
1
1
  module FixtureReplacement
2
2
  module ClassMethods
3
+ include FixtureReplacement::RandomDataGenerators
4
+
3
5
  def included(_other_mod)
4
- FixtureReplacement.load_example_data
6
+ FixtureReplacement.load!
5
7
  end
6
8
 
7
9
  def attributes_for(fixture_name, options={}, &block)
@@ -13,17 +15,8 @@ module FixtureReplacement
13
15
  AttributeBuilder.validate_instances!
14
16
  end
15
17
 
16
- def random_string(length=10)
17
- chars = ("a".."z").to_a
18
- string = ""
19
- 1.upto(length) { |i| string << chars[rand(chars.size-1)]}
20
- string
21
- end
22
-
23
- def load_example_data
18
+ def load!
24
19
  load "#{rails_root}/db/example_data.rb"
25
- # rescue NameError
26
- # load "./db/example_data.rb"
27
20
  rescue LoadError, NameError
28
21
  # no-op. If the file is not found, don't panic
29
22
  end
@@ -38,16 +31,5 @@ module FixtureReplacement
38
31
  AttributeBuilder.clear_out_instances!
39
32
  load File.expand_path(File.dirname(__FILE__) + "/../fixture_replacement.rb")
40
33
  end
41
-
42
- private
43
-
44
- # Any user defined instance methods need the module's class scope to be
45
- # accessible inside the block given to attributes_for
46
- #
47
- # Addresses bug #16858 (see CHANGELOG)
48
- def method_added(method)
49
- module_function method if method != :method_added
50
- public method
51
- end
52
34
  end
53
35
  end
@@ -24,14 +24,6 @@ module FixtureReplacement
24
24
  define_method("new_#{builder_name}") do |*args|
25
25
  new_object = builder.instantiate(*args)
26
26
  end
27
-
28
- define_method("default_#{builder_name}") do |*args|
29
- warning = "default_#{builder_name} has been deprecated. "
30
- warning << "Please replace instances of default_#{builder_name} with the new_#{builder_name} method"
31
- Kernel.warn(warning)
32
-
33
- __send__ "new_#{builder_name}"
34
- end
35
27
  end
36
28
  end
37
29
  end
@@ -0,0 +1,36 @@
1
+ module FixtureReplacement
2
+ module RandomDataGenerators
3
+ def random_string(length=10)
4
+ chars = ("a".."z").to_a
5
+ string = ""
6
+ 1.upto(length) { |i| string << chars[rand(chars.size-1)]}
7
+ string
8
+ end
9
+
10
+ def random_incrementing_number
11
+ @increment ||= 0
12
+ @increment += 1
13
+ @increment
14
+ end
15
+
16
+ def random_email(*args)
17
+ require 'faker'
18
+ Faker::Internet.email(*args)
19
+ end
20
+
21
+ def random_first_name
22
+ require 'faker'
23
+ Faker::Name.first_name
24
+ end
25
+
26
+ def random_last_name
27
+ require 'faker'
28
+ Faker::Name.last_name
29
+ end
30
+
31
+ def random_name
32
+ require 'faker'
33
+ Faker::Name.name
34
+ end
35
+ end
36
+ end
@@ -2,7 +2,7 @@ module FixtureReplacement
2
2
  module Version
3
3
  unless defined?(FixtureReplacement::VERSION)
4
4
  MAJOR = 4
5
- MINOR = 0
5
+ MINOR = 1
6
6
  TINY = 0
7
7
 
8
8
  version_string = "#{MAJOR}.#{MINOR}.#{TINY}"
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "."))
2
2
  load "fixture_replacement/version.rb"
3
+ load "fixture_replacement/random_data_generators.rb"
3
4
  load "fixture_replacement/class_methods.rb"
4
5
  load "fixture_replacement/attribute_builder.rb"
5
6
  load "fixture_replacement/method_generator.rb"
@@ -9,6 +10,7 @@ module FixtureReplacement
9
10
 
10
11
  include FixtureReplacement::Version
11
12
  extend FixtureReplacement::ClassMethods
13
+ extend self
12
14
  end
13
15
 
14
16
  load "fr.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_replacement
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Taylor
@@ -32,6 +32,7 @@ files:
32
32
  - lib/fixture_replacement/attribute_builder.rb
33
33
  - lib/fixture_replacement/class_methods.rb
34
34
  - lib/fixture_replacement/method_generator.rb
35
+ - lib/fixture_replacement/random_data_generators.rb
35
36
  - lib/fixture_replacement/version.rb
36
37
  - lib/fr.rb
37
38
  - philosophy_and_bugs.rdoc