Sha256: c63bc0a13ad7c7cd4a35019b27e320568d969275bfbbbe04d965a6d823246c3c

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 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}]"
    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

3 entries across 3 versions & 1 rubygems

Version Path
fossil-0.5.2 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.1 spec/sequel/serializer/json_serializer_spec.rb
fossil-0.5.0 spec/sequel/serializer/json_serializer_spec.rb