dupe 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,12 +58,12 @@ class Dupe
58
58
  # ===> :title, 'test'
59
59
  def generate(value=NilValue)
60
60
  if value == NilValue
61
- v = @default.respond_to?(:call) ? @default.call : @default
61
+ v = @default.respond_to?(:call) ? @default.call : (@default.dup rescue @default)
62
62
  else
63
63
  v = (@transformer ? @transformer.call(value) : value)
64
64
  end
65
65
 
66
- return @name, (v && v.respond_to?(:dup) ? v.dup : v)
66
+ return @name, v
67
67
  end
68
68
  end
69
69
  end
@@ -433,4 +433,32 @@ describe Dupe do
433
433
  end
434
434
 
435
435
  end
436
+
437
+ describe "creating resources should not change definitions (regression test)" do
438
+ before do
439
+ Dupe.define :book do |book|
440
+ book.authors []
441
+ book.genre do
442
+ Dupe.find_or_create :genre, :name => 'Sci-fi'
443
+ end
444
+ end
445
+ end
446
+
447
+ it "should not add a record to the definition when the default value is an array" do
448
+ b = Dupe.create :book
449
+ a = Dupe.create :author
450
+ b.authors << a
451
+ b.authors.include?(a).should be_true
452
+ b2 = Dupe.create :book
453
+ b2.authors.should be_empty
454
+ end
455
+
456
+ it "should not dupe the value returned by a lazy attribute" do
457
+ b = Dupe.create :book
458
+ b2 = Dupe.create :book
459
+ b.genre.should == b2.genre
460
+ b.genre.name = 'Science Fiction'
461
+ b2.genre.name.should == 'Science Fiction'
462
+ end
463
+ end
436
464
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dupe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Parker
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-11 00:00:00 -05:00
12
+ date: 2010-02-12 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency