Repository URL to install this package:
|
Version:
2.23.0 ▾
|
require 'spec_helper'
describe JPlatform::Project, :type => :model do
before(:each) do
stub_get("/api/v1/projects/1.json").to_return(body: fixture("project.json"), headers: {content_type: "application/json; charset=utf-8"})
stub_get("/api/v1/projects/1.json?include_social_accounts=true").to_return(body: fixture("project_with_social_accounts.json"), headers: {content_type: "application/json; charset=utf-8"})
Rails.cache.clear
end
describe "post_social_account" do
before(:each) do
stub_get("/api/v1/project_social_accounts.json?project_id=1").to_return(body: fixture("project_social_accounts.json"), headers: {content_type: "application/json; charset=utf-8"})
stub_get("/api/v1/social_accounts/1.json").to_return(body: fixture("social_account.json"), headers: {content_type: "application/json; charset=utf-8"})
stub_get("/api/v1/social_accounts/2.json").to_return(body: fixture("social_account.json"), headers: {content_type: "application/json; charset=utf-8"})
end
it "does not include Google accounts" do
project = JPlatform::Project.new(id: 1)
google_post_account = project.post_social_accounts.select { |sa| sa.type.include? ("Google") }
expect(google_post_account.length).to eq(0)
end
end
describe "#==" do
it "returns true when objects IDs are the same" do
project = JPlatform::Project.new(id: 1, name: "test")
other = JPlatform::Project.new(id: 1, name: "bar")
expect(project == other).to be_truthy
end
it "returns false when objects IDs are different" do
project = JPlatform::Project.new(id: 1)
other = JPlatform::Project.new(id: 2)
expect(project == other).to be_falsey
end
end
it "returns the project information based on requested id" do
JPlatform::Project.find(1)
expect(a_get("/api/v1/projects/1.json")).to have_been_made
end
it "it override the default find, and cache the same project for 3 min" do
Rails.cache.clear
JPlatform::Project.find(1)
JPlatform::Project.find(1)
expect(a_get("/api/v1/projects/1.json")).to have_been_made.times(1)
end
it "returns attached social accounts directly if included" do
project = JPlatform::Project.find(1, params: { include_social_accounts: true })
expect(a_get("/api/v1/social_accounts.json?project_id=1")).not_to have_been_made
expect(a_get("/api/v1/project_social_accounts.json?project_id=1")).not_to have_been_made
expect(project.social_accounts.count).to eq(2)
end
it "fetches the attached social accounts using project_social_accounts if not included" do
stub_get("/api/v1/project_social_accounts.json?project_id=1").to_return(body: fixture("project_social_accounts.json"), headers: {content_type: "application/json; charset=utf-8"})
stub_get("/api/v1/social_accounts/1.json").to_return(body: fixture("social_account.json"), headers: {content_type: "application/json; charset=utf-8"})
stub_get("/api/v1/social_accounts/2.json").to_return(body: fixture("social_account.json"), headers: {content_type: "application/json; charset=utf-8"})
project = JPlatform::Project.find(1)
expect(a_get("/api/v1/social_accounts.json?project_id=1")).not_to have_been_made
expect(project.social_accounts.count).to eq(2)
end
end