dupe 0.4.1 → 0.4.2

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.
data/lib/dupe/dupe.rb CHANGED
@@ -222,6 +222,7 @@ class Dupe
222
222
  def create(model_name, records={})
223
223
  model_name = model_name.to_s.singularize.to_sym
224
224
  define model_name unless model_exists(model_name)
225
+ records = records.kind_of?(Array) ? records.map {|r| r.symbolize_keys} : records.symbolize_keys!
225
226
  create_and_insert records, :into => model_name
226
227
  end
227
228
 
@@ -180,6 +180,21 @@ describe Dupe do
180
180
  Dupe.database.tables[:book].first.should == @books.first
181
181
  Dupe.database.tables[:book].last.should == @books.last
182
182
  end
183
+
184
+ it "should symbolize hash keys to keep from duplicating column names" do
185
+ b = Dupe.create :book, 'title' => 'War And Peace', :title => 'War And Peace'
186
+ b.title.should == 'War And Peace'
187
+ b[:title].should == 'War And Peace'
188
+ b['title'].should == nil
189
+
190
+ bs = Dupe.create :books, [{:test => 2, 'test' => 2}, {:test => 4, 'test' => 4}]
191
+ bs.first.test.should == 2
192
+ bs.first[:test].should == 2
193
+ bs.first['test'].should == nil
194
+ bs.last.test.should == 4
195
+ bs.last[:test].should == 4
196
+ bs.last['test'].should == nil
197
+ end
183
198
  end
184
199
 
185
200
  describe "find" do
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.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Parker