Sha256: db4dfc78ae39359ae43f30925a1299ec320dad97ca1bd849df528f4dcc027f47

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'

describe ActiveRemote::Serializers::JSON do
  describe "#as_json" do
    let(:attributes) { { :guid => 'foo', :name => 'bar', :updated_at => nil } }
    let(:serializable_attributes) { { "tag" => attributes.stringify_keys } }

    subject { Tag.new(attributes) }

    context "when options are nil" do
      it "substitutes an empty hash" do
        subject.as_json(nil).should eq serializable_attributes
      end
    end

    it "accepts standard JSON options" do
      subject.as_json(:root => false).should eq attributes.stringify_keys
    end

    context "with publishable attributes defined" do
      let(:expected_json) { { :tag => attributes.slice(:name) }.to_json }

      before { Tag.attr_publishable :name }
      after { reset_publishable_attributes(Tag) }

      it "serializes to JSON with only the publishable attributes" do
        subject.to_json.should eq expected_json
      end
    end

    context "without publishable attributes defined" do
      let(:expected_json) { { :tag => attributes }.to_json }

      it "serializes to JSON" do
        subject.to_json.should eq expected_json
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_remote-1.6.1 spec/lib/active_remote/serializers/json_spec.rb
active_remote-1.6.0 spec/lib/active_remote/serializers/json_spec.rb