Sha256: f3064ceaf27e90c347c967a5cb839fe4e653ee469576fb567c6e30abd63fe55a

Contents?: true

Size: 962 Bytes

Versions: 4

Compression:

Stored size: 962 Bytes

Contents

require 'spec_helper'

describe SonJay::ActsAsModel do
  context "included as a class mixin" do

    let( :klass ) {
      Class.new do
        include SonJay::ActsAsModel

        class Content
          attr_reader :loaded_data

          def load_data(data)
            @loaded_data = data
          end
        end

        def sonj_content
          @sonj_content ||= Content.new
        end
      end
    }

    describe '::parse_json' do
      it "returns a new instance with parsed JSON data loaded into its #sonj_content object" do
        instance = klass.parse_json( '{"hello": "world"}' )
        loaded_data = instance.sonj_content.loaded_data
        expect( loaded_data ).to eq( {'hello' => 'world'} )
      end
    end

    describe '::array_class' do
      it "returns an array model class with the target as its entry class" do
        result = klass.array_class
        expect( result.entry_class ).to eq( klass )
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
son_jay-0.4.1 spec/acts_as_model_spec.rb
son_jay-0.4.0 spec/acts_as_model_spec.rb
son_jay-0.3.0 spec/acts_as_model_spec.rb
son_jay-0.2.0.alpha spec/acts_as_model_spec.rb