forked from AnilRh/rpush
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rpush#528 from splitwise/jess/improve-test-coverage
Improve test coverage
- Loading branch information
Showing
54 changed files
with
1,159 additions
and
1,240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.6.3 | ||
2.6.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,6 @@ | ||
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 | ||
it_behaves_like 'Rpush::Client::Adm::App' | ||
it_behaves_like 'Rpush::Client::ActiveRecord::App' | ||
end if active_record? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,6 @@ | ||
require 'unit_spec_helper' | ||
require 'unit/notification_shared.rb' | ||
|
||
describe Rpush::Client::ActiveRecord::Adm::Notification do | ||
it_should_behave_like 'an Notification subclass' | ||
|
||
let(:app) { Rpush::Client::ActiveRecord::Adm::App.create!(name: 'test', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') } | ||
let(:notification_class) { Rpush::Client::ActiveRecord::Adm::Notification } | ||
let(:notification) { notification_class.new } | ||
|
||
it "has a 'data' payload limit of 6144 bytes" do | ||
notification.data = { key: "a" * 6144 } | ||
expect(notification.valid?).to eq(false) | ||
expect(notification.errors[:base]).to eq ["Notification payload data cannot be larger than 6144 bytes."] | ||
end | ||
|
||
it 'limits the number of registration ids to 100' do | ||
notification.registration_ids = ['a'] * (100 + 1) | ||
expect(notification.valid?).to eq(false) | ||
expect(notification.errors[:base]).to eq ["Number of registration_ids cannot be larger than 100."] | ||
end | ||
|
||
it 'validates data can be blank if collapse_key is set' do | ||
notification.app = app | ||
notification.registration_ids = 'a' | ||
notification.collapse_key = 'test' | ||
notification.data = nil | ||
expect(notification.valid?).to eq(true) | ||
expect(notification.errors[:data]).to be_empty | ||
end | ||
|
||
it 'validates data is present if collapse_key is not set' do | ||
notification.collapse_key = nil | ||
notification.data = nil | ||
expect(notification.valid?).to eq(false) | ||
expect(notification.errors[:data]).to eq ['must be set unless collapse_key is specified'] | ||
end | ||
|
||
it 'includes expiresAfter in the payload' do | ||
notification.expiry = 100 | ||
expect(notification.as_json['expiresAfter']).to eq 100 | ||
end | ||
it_behaves_like 'Rpush::Client::Adm::Notification' | ||
it_behaves_like 'Rpush::Client::ActiveRecord::Notification' | ||
end if active_record? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,6 @@ | ||
require 'unit_spec_helper' | ||
|
||
describe Rpush::Client::ActiveRecord::App do | ||
it 'does not validate an app with an invalid certificate' do | ||
app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'foo') | ||
app.valid? | ||
expect(app.errors[:certificate]).to eq ['value must contain a certificate and a private key.'] | ||
end | ||
|
||
it 'validates a certificate without a password' do | ||
app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development', certificate: TEST_CERT | ||
app.valid? | ||
expect(app.errors[:certificate]).to eq [] | ||
end | ||
|
||
it 'validates a certificate with a password' do | ||
app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development', | ||
certificate: TEST_CERT_WITH_PASSWORD, password: 'fubar' | ||
app.valid? | ||
expect(app.errors[:certificate]).to eq [] | ||
end | ||
|
||
it 'validates a certificate with an incorrect password' do | ||
app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development', | ||
certificate: TEST_CERT_WITH_PASSWORD, password: 'incorrect' | ||
app.valid? | ||
expect(app.errors[:certificate]).to eq ['value must contain a certificate and a private key.'] | ||
end | ||
describe Rpush::Client::ActiveRecord::Apns::App do | ||
it_behaves_like 'Rpush::Client::Apns::App' | ||
it_behaves_like 'Rpush::Client::ActiveRecord::App' | ||
end if active_record? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
require 'unit_spec_helper' | ||
|
||
describe Rpush::Client::ActiveRecord::Apns::Feedback do | ||
it 'validates the format of the device_token' do | ||
notification = Rpush::Client::ActiveRecord::Apns::Feedback.new(device_token: "{$%^&*()}") | ||
expect(notification.valid?).to be_falsey | ||
expect(notification.errors[:device_token]).to include('is invalid') | ||
end | ||
it_behaves_like 'Rpush::Client::Apns::Feedback' | ||
end if active_record? |
Oops, something went wrong.