-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b71a542
commit 3045816
Showing
20 changed files
with
727 additions
and
4 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
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'spec_helper' | ||
|
||
require_relative "../../../../lib/outboxer/web" | ||
|
||
RSpec.describe 'GET /', type: :request do | ||
include Rack::Test::Methods | ||
|
||
def app | ||
Outboxer::Web | ||
end | ||
|
||
context 'when there are no publishers' do | ||
before do | ||
header 'Host', 'localhost' | ||
|
||
get '/' | ||
end | ||
|
||
it "doesn't show any publishers" do | ||
expect(last_response).to be_ok | ||
expect(last_response.body).to include('There are no publishers to display') | ||
end | ||
end | ||
|
||
context 'when there is a publisher' do | ||
let!(:publisher) { create(:outboxer_publisher, :publishing, name: 'localhost:14325') } | ||
|
||
before do | ||
header 'Host', 'localhost' | ||
|
||
get '/' | ||
end | ||
|
||
it "shows publisher" do | ||
expect(last_response).to be_ok | ||
expect(last_response.body).to include(publisher.name) | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'spec_helper' | ||
|
||
require_relative '../../../../../app/models/application_record' | ||
require_relative '../../../../../app/models/event' | ||
|
||
require_relative "../../../../../lib/outboxer/web" | ||
|
||
RSpec.describe 'POST /message/:id/delete', type: :request do | ||
include Rack::Test::Methods | ||
|
||
def app | ||
Outboxer::Web | ||
end | ||
|
||
let!(:event) { Event.create!(id: 1, type: 'Event') } | ||
let!(:message) do | ||
Outboxer::Models::Message.find_by!(messageable_type: 'Event', messageable_id: event.id) | ||
end | ||
|
||
before do | ||
header 'Host', 'localhost' | ||
|
||
post "/message/#{message.id}/delete" | ||
|
||
follow_redirect! | ||
end | ||
|
||
it 'deletes message' do | ||
expect(Outboxer::Models::Message.exists?(message.id)).to be false | ||
end | ||
|
||
it 'redirects with flash' do | ||
expect(last_response).to be_ok | ||
expect(last_request.env['x-rack.flash'][:primary]).to include('was deleted') | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
|
||
require_relative '../../../../../app/models/application_record' | ||
require_relative '../../../../../app/models/event' | ||
|
||
require_relative "../../../../../lib/outboxer/web" | ||
|
||
RSpec.describe 'GET /message/:id/messageable', type: :request do | ||
include Rack::Test::Methods | ||
|
||
def app | ||
Outboxer::Web | ||
end | ||
|
||
let(:event) { Event.create!(type: 'Event') } | ||
let!(:message) do | ||
Outboxer::Models::Message.find_by!(messageable_type: 'Event', messageable_id: event.id) | ||
end | ||
|
||
before do | ||
header 'Host', 'localhost' | ||
|
||
get "/message/#{message.id}/messageable" | ||
end | ||
|
||
it 'loads the associated messageable object for a message' do | ||
expect(last_response).to be_ok | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
|
||
require_relative '../../../../../app/models/application_record' | ||
require_relative '../../../../../app/models/event' | ||
|
||
require_relative "../../../../../lib/outboxer/web" | ||
|
||
RSpec.describe 'POST /message/:id/requeue', type: :request do | ||
include Rack::Test::Methods | ||
|
||
def app | ||
Outboxer::Web | ||
end | ||
|
||
let!(:event) { Event.create!(id: 1, type: 'Event') } | ||
let!(:message) do | ||
Outboxer::Models::Message.find_by!(messageable_type: 'Event', messageable_id: event.id) | ||
end | ||
|
||
before do | ||
header 'Host', 'localhost' | ||
|
||
post "/message/#{message.id}/requeue" | ||
|
||
follow_redirect! | ||
|
||
message.reload | ||
end | ||
|
||
it 'requeues a message' do | ||
expect(message.status).to eql('queued') | ||
end | ||
|
||
it 'redirects with flash' do | ||
expect(last_response).to be_ok | ||
expect(last_request.env['x-rack.flash'][:primary]).to include('was queued') | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
|
||
require_relative '../../../../../app/models/application_record' | ||
require_relative '../../../../../app/models/event' | ||
|
||
require_relative "../../../../../lib/outboxer/web" | ||
|
||
RSpec.describe 'GET /message/:id', type: :request do | ||
include Rack::Test::Methods | ||
|
||
def app | ||
Outboxer::Web | ||
end | ||
|
||
let(:event) { Event.create!(type: 'Event') } | ||
let!(:message) do | ||
Outboxer::Models::Message.find_by!(messageable_type: 'Event', messageable_id: event.id) | ||
end | ||
|
||
before do | ||
header 'Host', 'localhost' | ||
|
||
get "/message/#{message.id}" | ||
end | ||
|
||
it 'loads message' do | ||
expect(last_response).to be_ok | ||
expect(last_response.body).to include(message.id.to_s) | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
require 'spec_helper' | ||
|
||
require_relative '../../../../../app/models/application_record' | ||
require_relative '../../../../../app/models/event' | ||
|
||
require_relative "../../../../../lib/outboxer/web" | ||
|
||
RSpec.describe 'POST /messages/delete_all', type: :request do | ||
include Rack::Test::Methods | ||
|
||
def app | ||
Outboxer::Web | ||
end | ||
|
||
let!(:event_1) { Event.create!(id: 1, type: 'Event') } | ||
let!(:message_1) do | ||
Outboxer::Models::Message.find_by!(messageable_type: 'Event', messageable_id: event_1.id) | ||
end | ||
|
||
let!(:event_2) { Event.create!(id: 2, type: 'Event') } | ||
let!(:message_2) do | ||
Outboxer::Models::Message.find_by!(messageable_type: 'Event', messageable_id: event_2.id) | ||
end | ||
|
||
let!(:event_3) { Event.create!(id: 3, type: 'Event') } | ||
let!(:message_3) do | ||
Outboxer::Models::Message.find_by!(messageable_type: 'Event', messageable_id: event_3.id) | ||
end | ||
|
||
context 'when no status provided' do | ||
before do | ||
header 'Host', 'localhost' | ||
|
||
post '/messages/delete_all', { | ||
page: 1, | ||
per_page: 10, | ||
sort: :queued_at, | ||
order: :desc, | ||
time_zone: 'Australia/Sydney' | ||
} | ||
|
||
follow_redirect! | ||
end | ||
|
||
it 'deletes all messages' do | ||
expect(Outboxer::Models::Message.count).to eq(0) | ||
end | ||
|
||
it 'does not delete events' do | ||
expect(Event.count).to eq(3) | ||
end | ||
|
||
it 'redirects to /messages' do | ||
expect(last_response).to be_ok | ||
expect(last_request.url).to include( | ||
"messages?sort=queued_at&order=desc&per_page=10&time_zone=Australia%2FSydney") | ||
end | ||
|
||
it 'flashes deleted messages count' do | ||
expect(last_request.env['x-rack.flash'][:primary]).to include('3 messages have been deleted') | ||
end | ||
end | ||
|
||
context 'when failed status provided' do | ||
before do | ||
message_2.update!(status: Outboxer::Models::Message::Status::PUBLISHING) | ||
message_3.update!(status: Outboxer::Models::Message::Status::FAILED) | ||
|
||
header 'Host', 'localhost' | ||
|
||
post '/messages/delete_all', { | ||
status: :failed, | ||
page: 1, | ||
per_page: 10, | ||
sort: :queued_at, | ||
order: :desc, | ||
time_zone: 'Australia/Sydney' | ||
} | ||
|
||
follow_redirect! | ||
end | ||
|
||
it 'deletes failed messages' do | ||
expect(Outboxer::Models::Message.failed.count).to eq(0) | ||
end | ||
|
||
it 'does not delete other messages' do | ||
expect(Outboxer::Models::Message.queued.count).to eq(1) | ||
expect(Outboxer::Models::Message.publishing.count).to eq(1) | ||
end | ||
|
||
it 'redirects to /messages' do | ||
expect(last_response).to be_ok | ||
expect(last_request.url).to include( | ||
"messages?status=failed&sort=queued_at&order=desc&per_page=10&time_zone=Australia%2FSydney") | ||
end | ||
|
||
it 'flashes deleted messages count' do | ||
expect(last_request.env['x-rack.flash'][:primary]).to include('1 message have been deleted') | ||
end | ||
end | ||
end |
Oops, something went wrong.