spec/cellular/models/sms_spec.rb in cellular-1.3.0 vs spec/cellular/models/sms_spec.rb in cellular-2.0.0
- old
+ new
@@ -5,13 +5,15 @@
let(:recipient) { '47xxxxxxxx' }
let(:sender) { 'Custom sender' }
let(:message) { 'This is an SMS message' }
let(:price) { 100 }
let(:country_code) { 'NO'}
+ let(:recipients) { nil }
subject do
described_class.new(
+ recipients: recipients,
recipient: recipient,
sender: sender,
message: message,
price: price,
country_code: country_code
@@ -21,52 +23,51 @@
before do
Cellular.config.backend = Cellular::Backends::Sendega
end
describe '#initialize' do
- its(:recipient) { should eq recipient }
- its(:sender) { should eq sender }
- its(:message) { should eq message }
- its(:price) { should eq price }
- its(:country_code) { should eq country_code }
+ it{ expect(subject.recipient).to eq recipient }
+ it{ expect(subject.sender).to eq sender }
+ it{ expect(subject.message).to eq message }
+ it{ expect(subject.price).to eq price }
+ it{ expect(subject.country_code).to eq country_code }
it { should_not be_delivered }
context 'when sender omitted' do
before do
Cellular.config.sender = 'Hyper'
end
subject { described_class.new }
-
- its(:sender) { should eq 'Hyper' }
+ it{ expect(subject.sender).to eq 'Hyper' }
end
context 'when price omitted' do
before do
Cellular.config.price = 5
end
subject { described_class.new }
- its(:price) { should eq 5 }
+ it{ expect(subject.price).to be 5 }
end
context 'when country omitted' do
before do
Cellular.config.country_code = 'NL'
end
subject { described_class.new }
-
- its(:country_code) { should eq 'NL' }
+ it{ expect(subject.country_code).to eq 'NL'}
end
end
describe '#deliver' do
before do
expect(Cellular::Backends::Sendega).to receive(:deliver).with(
+ recipients: recipients,
recipient: recipient,
sender: sender,
price: price,
country_code: country_code,
message: message
@@ -77,26 +78,28 @@
subject.deliver
expect(subject).to be_delivered
end
end
- describe "#deliver_later" do
- it "calls out to the Sidekiq job to send the SMS" do
+ describe "#deliver_async" do
+ it "makes ActiveJob schedule an SMS job" do
sms_options = {
receiver: "12345678",
message: "Test SMS"
}
+ wait = 100
- expect(Cellular::Jobs::AsyncMessenger)
- .to receive(:perform_async)
- .with sms_options
+ expect_any_instance_of(ActiveJob::ConfiguredJob)
+ .to receive(:perform_later)
+ .with(sms_options)
sms = Cellular::SMS.new sms_options
+ allow(ActiveJob::Base).to receive(:queue_adapter).and_return ActiveJob::QueueAdapters::TestAdapter.new
allow(sms).to receive(:options).and_return sms_options
- sms.deliver_later
+ sms.deliver_async(wait: wait)
end
end
describe '#save' do
it 'has not been implemented yet' do
@@ -111,32 +114,6 @@
expect do
subject.receive
end.to raise_error NotImplementedError
end
end
-
- describe '#country' do
- it 'issues a deprecation warning' do
- expect(subject).to receive(:warn)
- subject.country
- end
-
- it 'returns country_code' do
- allow(subject).to receive(:warn)
- expect(subject.country).to eq(subject.country_code)
- end
- end
-
- describe '#country=' do
- it 'issues a deprecation warning' do
- expect(subject).to receive(:warn)
- subject.country = 'Test'
- end
-
- it 'assigns country_code' do
- allow(subject).to receive(:warn)
- subject.country = 'Test'
- expect(subject.country_code).to eq('Test')
- end
- end
-
end