fixture_builder 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,7 +8,6 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
10
  s.authors = ['Ryan Dy', 'David Stevenson']
11
- s.date = %q{2011-04-29}
12
11
  s.description = %q{FixtureBuilder allows testers to use their existing factories, like FactoryGirl, to generate high performance fixtures that can be shared across all your tests}
13
12
  s.email = %q{mail@ryandy.com}
14
13
  s.extra_rdoc_files = [
@@ -6,7 +6,7 @@ module FixtureBuilder
6
6
  @configuration = configuration
7
7
  @custom_names = {}
8
8
  @model_name_procs = {}
9
- @record_names = []
9
+ @record_names = {}
10
10
  end
11
11
 
12
12
  def name_model_with(model_class, &block)
@@ -44,7 +44,8 @@ module FixtureBuilder
44
44
  else
45
45
  inferred_record_name(record_hash, table_name, row_index)
46
46
  end
47
- @record_names << name
47
+ @record_names[table_name] ||= []
48
+ @record_names[table_name] << name
48
49
  name.to_s
49
50
  end
50
51
 
@@ -53,8 +54,10 @@ module FixtureBuilder
53
54
  record_name_fields.each do |try|
54
55
  if name = record_hash[try]
55
56
  inferred_name = name.underscore.gsub(/\W/, ' ').squeeze(' ').tr(' ', '_')
56
- count = @record_names.select { |name| name.to_s.starts_with?(inferred_name) }.size
57
- # CHANGED == to starts_with?
57
+ count = 0
58
+ if @record_names[table_name]
59
+ count = @record_names[table_name].select {|name| name.to_s.starts_with?(inferred_name) }.size
60
+ end
58
61
  return count.zero? ? inferred_name : "#{inferred_name}_#{count}"
59
62
  end
60
63
  end
@@ -1,3 +1,3 @@
1
1
  module FixtureBuilder
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
data/test/namer_test.rb CHANGED
@@ -6,6 +6,12 @@ class Model
6
6
  end
7
7
  end
8
8
 
9
+ class AnotherModel
10
+ def self.table_name
11
+ 'another_models'
12
+ end
13
+ end
14
+
9
15
  class NamerTest < Test::Unit::TestCase
10
16
  def setup
11
17
  configuration = FixtureBuilder::Configuration.new
@@ -41,4 +47,18 @@ class NamerTest < Test::Unit::TestCase
41
47
  }
42
48
  assert_equal 'foo', @namer.record_name(hash, Model.table_name, '000')
43
49
  end
50
+
51
+ def test_name_not_unique_across_tables
52
+ hash = {
53
+ 'id' => 1,
54
+ 'title' => 'foo'
55
+ }
56
+ hash_with_same_title = {
57
+ 'id' => 2,
58
+ 'title' => 'foo'
59
+ }
60
+ assert_equal 'foo', @namer.record_name(hash, Model.table_name, '000')
61
+ assert_equal 'foo', @namer.record_name(hash, AnotherModel.table_name, '000')
62
+ assert_equal 'foo_1', @namer.record_name(hash_with_same_title, Model.table_name, '000')
63
+ end
44
64
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixture_builder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Dy
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-29 00:00:00 -07:00
19
+ date: 2011-09-19 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -107,7 +107,6 @@ files:
107
107
  - MIT-LICENSE
108
108
  - README.markdown
109
109
  - Rakefile
110
- - VERSION
111
110
  - fixture_builder.gemspec
112
111
  - lib/fixture_builder.rb
113
112
  - lib/fixture_builder/builder.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.2