Skip to content

Commit

Permalink
Merge remote-tracking branch 'mlandauer/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
henare committed Apr 27, 2017
2 parents f6009b0 + 30757a7 commit f316f3b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/models/black_list.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class BlackList < ActiveRecord::Base
belongs_to :address
belongs_to :caused_by_delivery, class_name: "Delivery"

def has_record_of_cause?
caused_by_delivery.present? && caused_by_delivery.subject.present?
end
end
4 changes: 3 additions & 1 deletion app/views/addresses/to.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
= @address.text
is on the blacklist
%p
- unless @address.blacklist(current_admin.team).caused_by_delivery.subject.blank?
- if @address.blacklist(current_admin.team).has_record_of_cause?
Reason:
= link_to truncate(@address.blacklist(current_admin.team).caused_by_delivery.postfix_log_lines.first.extended_status, length: 160), @address.blacklist(current_admin.team).caused_by_delivery
= time_ago_in_words(@address.blacklist(current_admin.team).caused_by_delivery.postfix_log_lines.first.created_at)
ago
- else
We don't know why this was blacklisted. The delivery that caused it may have been archived.

- if policy(@address.blacklist(current_admin.team)).destroy?
= button_to "Remove from blacklist", @address.blacklist(current_admin.team), method: :delete, class: "btn btn-danger"
Expand Down
9 changes: 6 additions & 3 deletions app/views/black_lists/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
%tr
%td= black_list.address.text
%td
- unless black_list.caused_by_delivery.subject.blank?
- if black_list.has_record_of_cause?
= link_to truncate(black_list.caused_by_delivery.postfix_log_lines.first.extended_status, length: 160), black_list.caused_by_delivery
- else
We don't know why this was blacklisted. The delivery that caused it may have been archived.
%td
= time_ago_in_words(black_list.caused_by_delivery.postfix_log_lines.first.created_at)
ago
- if black_list.caused_by_delivery
= time_ago_in_words(black_list.caused_by_delivery.postfix_log_lines.first.created_at)
ago
- if policy(black_list).destroy?
%td
= button_to "Remove", black_list, method: :delete, class: "btn btn-danger"
1 change: 1 addition & 0 deletions spec/factories/black_lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

FactoryGirl.define do
factory :black_list do
team_id 1
address_id 1
caused_by_delivery_id 1
end
Expand Down
29 changes: 29 additions & 0 deletions spec/models/black_list_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
require 'spec_helper'

describe BlackList do
describe "#has_record_of_black_list_cause?" do
context "when the caused_by_delivery is missing" do
let(:black_list) { create(:black_list, caused_by_delivery: nil ) }

it { expect(black_list.has_record_of_cause?).to be false }
end

context "when the caused_by_delivery present but has no subject" do
let(:black_list) do
delivery = create(:delivery, email: create(:email, subject: nil))
create(:black_list, caused_by_delivery: delivery)
end

it { expect(black_list.has_record_of_cause?).to be false }
end

context "when the caused_by_delivery present and has a subject" do
let(:delivery) { create(:delivery) }
let(:black_list) { create(:black_list, caused_by_delivery: delivery) }

before do
allow(delivery).to receive(:subject).and_return("foo")
end

it do
expect(black_list.has_record_of_cause?).to be true
end
end
end
end

0 comments on commit f316f3b

Please sign in to comment.