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 / models / user_spec.rb
Size: Mime:
require 'spec_helper'

describe JPlatform::User do

  describe "#==" do
    it "returns true when objects IDs are the same" do
      user = JPlatform::User.new(id: 1, first_name: "foo")
      other = JPlatform::User.new(id: 1, first_name: "bar")
      expect(user == other).to be_true
    end
    it "returns false when objects IDs are different" do
      user = JPlatform::User.new(id: 1)
      other = JPlatform::User.new(id: 2)
      expect(user == other).to be_false
    end
  end

  describe "retrieves current user" do
    before(:each) do
      # should be done with access token from Oauth
      stub_get("/api/v1/users/me").to_return(body: fixture("user1.json"), headers: {content_type: "application/json; charset=utf-8"})
    end

    it "returns true when user is one of the clients' admin" do
      user = JPlatform::User.me
      expect(user.is_any_client_admin).to be_true
    end

    it "returns users created at as a time" do
      user = JPlatform::User.me
      expect(user.created_at.is_a? ActiveSupport::TimeWithZone).to be_true
    end

    it "returns the current user profile information" do
      user = JPlatform::User.me
      expect(user.id).to eq(1)
      #  1 should be replaced by an access token representation
    end
    it "returns current user's full name" do
      user = JPlatform::User.me
      expect(user.full_name).to eq([user.first_name, user.last_name].join(' '))
    end
    it "checks user is a role" do
      user = JPlatform::User.me
      user.role = 'member'
      expect(user.member?).to eq(true)
      expect(user.super_admin?).to eq(false)
      expect(user.org_admin?).to eq(false)

      user.role = 'super_admin'
      expect(user.member?).to eq(false)
      expect(user.super_admin?).to eq(true)
      expect(user.org_admin?).to eq(false)

      user.role = 'org_admin'
      expect(user.member?).to eq(false)
      expect(user.super_admin?).to eq(false)
      expect(user.org_admin?).to eq(true)
    end
  end
end