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.50 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.49 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.48 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.47 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.46 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.45 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.44 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.43 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.42 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.41 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.40 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.39 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.38 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.37 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.36 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.35 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.34 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.33 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.32 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.31 spec/sequel/serializer/json_serializer_spec.rb