Sha256: c168408ff86f76979eb097a10362066f4b886991388dbe27da7de9281d7216d8

Contents?: true

Size: 1.84 KB

Versions: 28

Compression:

Stored size: 1.84 KB

Contents

require 'unit_spec_helper'

describe Rpush::Client::ActiveRecord::Adm::App do
  subject { Rpush::Client::ActiveRecord::Adm::App.new(name: 'test', environment: 'development', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }
  let(:existing_app) { Rpush::Client::ActiveRecord::Adm::App.create!(name: 'existing', environment: 'development', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }

  it 'should be valid if properly instantiated' do
    expect(subject).to be_valid
  end

  it 'should be invalid if name' do
    subject.name = nil
    expect(subject).not_to be_valid
    expect(subject.errors[:name]).to eq ["can't be blank"]
  end

  it 'should be invalid if name is not unique within scope' do
    subject.name = existing_app.name
    expect(subject).not_to be_valid
    expect(subject.errors[:name]).to eq ["has already been taken"]
  end

  it 'should be invalid if missing client_id' do
    subject.client_id = nil
    expect(subject).not_to be_valid
    expect(subject.errors[:client_id]).to eq ["can't be blank"]
  end

  it 'should be invalid if missing client_secret' do
    subject.client_secret = nil
    expect(subject).not_to be_valid
    expect(subject.errors[:client_secret]).to eq ["can't be blank"]
  end

  describe '#access_token_expired?' do
    before(:each) do
      Timecop.freeze(Time.now)
    end

    after do
      Timecop.return
    end

    it 'should return true if access_token_expiration is nil' do
      expect(subject.access_token_expired?).to eq(true)
    end

    it 'should return true if expired' do
      subject.access_token_expiration = Time.now - 5.minutes
      expect(subject.access_token_expired?).to eq(true)
    end

    it 'should return false if not expired' do
      subject.access_token_expiration = Time.now + 5.minutes
      expect(subject.access_token_expired?).to eq(false)
    end
  end
end if active_record?

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
rpush-5.0.0 spec/unit/client/active_record/adm/app_spec.rb
rpush-4.2.0 spec/unit/client/active_record/adm/app_spec.rb
rpush-4.1.1 spec/unit/client/active_record/adm/app_spec.rb
rpush-4.1.0 spec/unit/client/active_record/adm/app_spec.rb
rpush-4.0.1 spec/unit/client/active_record/adm/app_spec.rb
rpush-4.0.0 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.3.1 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.3.0 spec/unit/client/active_record/adm/app_spec.rb
rpush_extended-3.2.6 spec/unit/client/active_record/adm/app_spec.rb
rpush_extended-3.2.5 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.2.4 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.2.3 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.2.2 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.2.1 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.2.0 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.1.1 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.1.0 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.0.2 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.0.1 spec/unit/client/active_record/adm/app_spec.rb
rpush-3.0.0 spec/unit/client/active_record/adm/app_spec.rb