Sha256: be713e94eac3b3ec84768b840b10fb7d3cf882300d12ce43bc0e7ed0ab5553c8

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

module FavouriteObject
  describe Favourite do

  	let(:user) { User.create({email: "user@example.com" })}
  	let(:arbitrary_object) { ArbitraryObject.create() }
  	let(:favourite) { FavouriteObject::Favourite.create(owner: user, target: arbitrary_object) }

  	describe "" do
  		before :each do
  			favourite.save
  		end

  		it "toggles the status of a favourite" do
        favourite.is_favourited = false
        favourite.save
        
  			favourite.toggle
  			favourite.is_favourited.should eq true
  		end

      it "returns true for a favourited object" do
        favourite.is_favourited = true
        favourite.save
        status = FavouriteObject::Favourite.is_favourited?(user, arbitrary_object.id, arbitrary_object.class.name)
        status.should eq true
      end

      it "returns true for a favourited third_party object" do
        third_party_favourite = FavouriteObject::Favourite.create(owner: user, third_party_type: "Sale", third_party_id: 1, is_favourited: true, third_party_flag: true)
        third_party_favourite.should be_valid

        status = FavouriteObject::Favourite.is_favourited?(user, 1, "Sale", true)
        status.should eq true
      end

      it "returns false for an unfavourited object" do
        favourite.is_favourited = false
        favourite.save
        status = FavouriteObject::Favourite.is_favourited?(user, arbitrary_object.id, arbitrary_object.class.name)
        status.should eq false
      end


  	end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
favourite_object-0.1.1 spec/models/favourite_object/favourite_spec.rb
favourite_object-0.1.0 spec/models/favourite_object/favourite_spec.rb
favourite_object-0.0.3 spec/models/favourite_object/favourite_spec.rb
favourite_object-0.0.2 spec/models/favourite_object/favourite_spec.rb
favourite_object-0.0.1 spec/models/favourite_object/favourite_spec.rb