spec/extensions/csv_serializer_spec.rb in sequel-4.41.0 vs spec/extensions/csv_serializer_spec.rb in sequel-4.42.0
- old
+ new
@@ -93,11 +93,11 @@
@album.name.must_equal 'AS'
@album.artist_id.must_equal 2
@album = @Album.from_csv('2,AS', :headers=>[nil, 'name'])
@album.name.must_equal 'AS'
- @album.artist_id.must_equal nil
+ @album.artist_id.must_be_nil
end
it "#from_csv should support :headers to specify headers" do
@album.from_csv('AS,2', :headers=>['name'])
@album.name.must_equal 'AS'
@@ -107,12 +107,14 @@
@album.name.must_equal 'AS'
@album.artist_id.must_equal 2
end
it "should support a to_csv class and dataset method" do
- @Album.dataset._fetch = {:id=>1, :name=>'RF', :artist_id=>2}
- @Artist.dataset._fetch = {:id=>2, :name=>'YJM'}
+ @Album.dataset = @Album.dataset.with_fetch(:id=>1, :name=>'RF', :artist_id=>2)
+ @Artist.dataset = @Artist.dataset.with_fetch(:id=>2, :name=>'YJM')
+ @Album.columns(:id, :name, :artist_id)
+ @Album.db_schema.replace(:id=>{:type=>:integer}, :artist_id=>{:type=>:integer})
@Album.array_from_csv(@Album.to_csv).must_equal [@album]
@Album.array_from_csv(@Album.dataset.to_csv(:only=>:name), :only=>:name).must_equal [@Album.load(:name=>@album.name)]
end
it "should have dataset to_csv method respect :array option" do
@@ -164,12 +166,11 @@
end
it "should use a dataset's selected columns" do
columns = [:id]
ds = @Artist.select(*columns).limit(1)
- ds.instance_variable_set(:@columns, columns)
- ds._fetch = [:id => 10]
- ds.to_csv(:write_headers => true).must_equal "id\n10\n"
+ ds.send(:columns=, columns)
+ ds.with_fetch(:id => 10).to_csv(:write_headers => true).must_equal "id\n10\n"
end
it "should pass all the examples from the documentation" do
@album.to_csv(:write_headers=>true).must_equal "id,name,artist_id\n1,RF,2\n"
@album.to_csv(:only=>:name).must_equal "RF\n"