fixture_replacement 4.0.1 → 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: cae1408da614335f95fd86039eaf92ac8eb04b549faced2c92ebb217de83242b
4
- data.tar.gz: feccbd506f6b771219512711eca9d141f6eb021ff2ec073b5170d19f0efefe55
3
+ metadata.gz: 70ad8e924533702d5954ff854992ca3d215090e5e97e7f4e47221d51f04aebf4
4
+ data.tar.gz: 69ffca95d0436db069bcf3e536d87704414702db8ed3f037bb313372e443d871
5
5
  SHA512:
6
- metadata.gz: 9a5703bcc55fe6935115785ae62582b6bafd2e099508af734df96055e7d07d1729fe6aebea628e7062de0157d77e351c9ac3675864a0af737e10e299e04cccae
7
- data.tar.gz: 9953fbf276caeb951bb6e8d573126b3bd2ff396ef91eeceb20053f6a0679b3c05042a0750d65e9d67c628f4cb31840ed2d431685a5c8f6a70d063ebe410153e8
6
+ metadata.gz: d66a2d0b581d785c5ff26144cbea3b2e724454ed151d1de19f35aacba3582d87df7fdcda2d0e43c400933fd18cbe494d3c043244577156c1230669fb9dc6fc43
7
+ data.tar.gz: 2261fdb8e7b312e73162b9d10c0e761cae31f00448827238904d6785c5827d04f72d5e0a73b72b6dda11461d814a2ff59b53896d541c2fe18b796ce85f3dbacd
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,17 @@
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
+
1
15
  == 4.0.1
2
16
 
3
17
  - Minor release fixes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 4.0.1
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,8 +2,8 @@ module FixtureReplacement
2
2
  module Version
3
3
  unless defined?(FixtureReplacement::VERSION)
4
4
  MAJOR = 4
5
- MINOR = 0
6
- TINY = 1
5
+ MINOR = 1
6
+ TINY = 0
7
7
 
8
8
  version_string = "#{MAJOR}.#{MINOR}.#{TINY}"
9
9
  version_string << " RC#{RELEASE_CANDIDATE}" if defined?(RELEASE_CANDIDATE)
@@ -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.1
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