Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
j_platform / spec / controllers / base_controller_spec.rb
Size: Mime:
require 'spec_helper'

describe BaseController, :type => :controller do
  include_context "controller setup"
  before(:each) do
    Rails.cache.clear
    session[:user_id] = 4
    stub_get("/api/v1/users/me.json").to_return(body: fixture("user4.json"), headers: {content_type: "application/json; charset=utf-8"})
    stub_get("/api/v1/projects/1.json?include_client=true&include_social_accounts=true").to_return(body: fixture("project_with_social_accounts.json"), headers: {content_type: "application/json; charset=utf-8"})
    stub_get("/api/v1/projects/2.json?include_client=true&include_social_accounts=true").to_return(body: fixture("project2.json"), headers: {content_type: "application/json; charset=utf-8"})
  end

  describe "#current_organization" do
    it "returns the current organization that the user belongs to" do
      stub_get("/api/v1/organizations/current.json").to_return(body: fixture("current_organization.json"), headers: {content_type: "application/json; charset=utf-8"})
      expect(controller.current_organization.id).to eq(1)
    end
  end

  describe "#current_clients" do
    it "returns the current clients the user belongs to" do
      expect(controller.current_clients).to eq(assigns(:_current_clients))
      expect(controller.current_clients.count).to eq(1)
    end
  end

  describe "#current_projects" do
    it "returns the current projects that user belongs to" do
      expect(controller.current_projects).to eq(assigns(:_current_projects))
      expect(controller.current_projects.count).to eq(3)
    end
  end

  describe "#client_with_projects" do
    it "returns the current projects that user belongs to grouped by clients" do
      expect(controller.client_with_projects).to eq(assigns(:_client_with_projects))
      expect(controller.client_with_projects.keys.count).to eq(1)
      expect(controller.client_with_projects.values.flatten.count).to eq(2)
    end
  end

  describe "#change_working_project" do
    it "changes the current working project" do
      session[:project_id] = 1
      xhr :get, :change_working_project, use_route: :change_working_project_path, working_project_id: 2
      expect(session[:project_id]).to eq(2)
    end
  end

  describe "#current_user" do
    it "sets @user and @current_user to logged-in user" do
      controller.instance_eval { current_user }
      expect(controller.current_user.id).to eq(4)
    end
  end

  describe "#current_project" do
    it "gets a current project from the first project of all current client projects" do
      expect(controller.current_project).to eq(assigns(:_current_project))
      expect(controller.current_project).to eq(controller.current_projects.first)
      expect(session[:project_id]).to eq(controller.current_project.id)
    end
    it "gets a current project from session data" do
      session[:project_id] = 2
      expect(controller.current_project).to eq(assigns(:_current_project))
      expect(controller.current_project.id).to eq(session[:project_id])
    end
  end

  describe "#current_client" do
    it "gets the client that the current project belongs to" do
      expect(controller.current_client.id).to eq(controller.current_project.client_id)
      expect(controller.current_client).to eq(assigns(:_current_client))
    end
  end

  describe "#current_project_id" do
    it "gets current project id" do
      expect(controller.current_project_id).to eq(controller.current_project.id)
    end
  end

  describe "#s3_service" do
    it "instantiate a s3 service" do
      expect(controller.s3_service).to be_a S3Service
      expect(controller.s3_service).to eq(assigns(:_s3))
    end
  end

  describe "with no projects" do
    before(:each) do
      stub_get("/api/v1/users/me.json").to_return(body: fixture("user_no_projects.json"), headers: {content_type: "application/json; charset=utf-8"})
    end

    describe "#current_client" do
      it "returns nil" do
        expect(controller.current_client).to eq(nil)
      end
    end
  end
end