Sha256: 187227cca7a80fbdaaf054e8042be69142377be3b2da2b20e10d8adc16473331

Contents?: true

Size: 1.6 KB

Versions: 17

Compression:

Stored size: 1.6 KB

Contents

require "spec_helper"

describe ErpApp::Organizer::Crm::RelationshipController do

  describe "GET index" do

    before(:each) do
      basic_user_auth

    end

    it "has a 200 status code" do
      get :index, {:use_route => :erp_app, :party_id => 1, :relationship_type => "customer_of_partner"}
      response.code.should eq("200")
    end

    it "throw ActiveRecord::RecordNotFound when no party id passed" do
      expect { get :index, {:use_route => :erp_app} }.to raise_error(ActiveRecord::RecordNotFound)
    end

    it "should return a successful response even if there are no relationships" do
      get :index, {:use_route => :erp_app, :party_id => 1, :relationship_type => "customer_of_partner"}
      response.should be_success
    end

    it "has a relationship count == 2" do

      #for some reason I had to use Factory's instead of Rspec doubles because of a method call
      #on this object in the controller
      relationships = [FactoryGirl.build(:party_relationship), FactoryGirl.build(:party_relationship)]

      #Since find_relationships_by_type is an instance method, need to mock a instance of 
      #Party and then spec the return value for the above method
      @party = double("Party")
      @party.should_receive(:find_relationships_by_type).and_return(relationships)
      Party.should_receive(:find).and_return(@party)

      get :index, {:use_route => :erp_app, :party_id => 1, :relationship_type => "customer_of_partner"}

      #I want to evaluate the returned JSON, so parse it.
      parsed_body = JSON.parse(response.body)
      parsed_body["totalCount"].should eq(2)
    end

  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
erp_app-3.1.16 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.15 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.14 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.13 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.12 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.11 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.10 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.9 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.8 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.7 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.6 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.5 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.4 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.3 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.2 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.1 spec/controllers/organizer/crm/relationship_controller_spec.rb
erp_app-3.1.0 spec/controllers/organizer/crm/relationship_controller_spec.rb