Sha256: 1283b6414768b38edb0741d85e01b75d2de9f54c9d70b6c954a1706dadc06e65

Contents?: true

Size: 1.31 KB

Versions: 47

Compression:

Stored size: 1.31 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/../spec_helper_tables' unless metaclass.class_variable_defined? :@@set_up_demo_tables

describe "Sequel::Serializer" do

  describe "to_fos_json method" do
    before :each do 
      set_demo_db([TestTable,Dude,Horse])
    end

    it "adds :only=>[] to the options hash" do
      data = Trip.new
      mock(data).to_json({:only=>[], :methods=>[]})
      data.to_fos_json(:methods=>[])
    end

    it "handles single sequel model" do
      add_test_table_data({:id=>1, :'goofy name col' => 123})
      data = TestTable.first
      data.to_fos_json(:methods=>[:'goofy name col']).should == "{\"goofy name col\":123}"
    end

    it "handles an array of sequel models" do
      add_test_table_data({:id=>1, :'goofy name col' => 123})
      array = [TestTable.first]
      array.to_fos_json(:methods=>[:'goofy name col']).should=="[{\"goofy name col\":123}]"
      # another one just in case
      Dude.all.to_fos_json(:methods=>[:name]).should == "[{\"name\":\"dano\"},{\"name\":\"eric\"}]"
    end

    it "shows methods which are dynamically delegated" do
      add_test_table_data({:id=>1, :'date_col' => 123})
      data = TestTable.first
      data.to_fos_json(:methods=>[:date_col__round]).should == "{\"date_col__round\":123}"
    end
  end

end

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
fossil-0.5.10 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.9 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.8 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.7 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.6 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.5 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.3 spec/sequel/serializer/json_serializer_spec.rb