-
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
339ce18
commit 86891b2
Showing
9 changed files
with
160 additions
and
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
require "spec_helper" | ||
|
||
describe ValidationErrorReporter::Entity do | ||
|
||
describe ".models_for(model_names)" do | ||
it "returns all models" do | ||
expect(described_class.models_for).to eq([Company, Project]) | ||
end | ||
module ValidationErrorReporter | ||
describe Entity do | ||
describe ".models_for(model_names)" do | ||
it "returns all models" do | ||
expect(described_class.models_for).to eq([Company, Project]) | ||
end | ||
|
||
context "when when given a list of models as strings" do | ||
it "resolved the models that exists in the application" do | ||
expect(described_class.models_for(["Company", "Model1"])).to eq([Company]) | ||
context "when when given a list of models as strings" do | ||
it "resolved the models that exists in the application" do | ||
expect(described_class.models_for(["Company", "Model1"])).to eq([Company]) | ||
end | ||
end | ||
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 |
---|---|---|
@@ -1,41 +1,44 @@ | ||
require "spec_helper" | ||
|
||
describe ValidationErrorReporter::Error do | ||
subject do | ||
described_class.new(double( | ||
id: 1, | ||
class: double( | ||
model_name: double(name: "Project", human: "Project"), | ||
count: 1, | ||
primary_key: :id | ||
), | ||
errors: double( | ||
full_messages: [ | ||
"Name can't be blank", | ||
"Name is too short (minimum is 2 characters)"] | ||
) | ||
)) | ||
end | ||
module ValidationErrorReporter | ||
describe Error do | ||
subject do | ||
described_class.new(double( | ||
id: 1, | ||
class: double( | ||
model_name: double(name: "Project", human: "Project"), | ||
count: 1, | ||
primary_key: :id | ||
), | ||
errors: double( | ||
full_messages: [ | ||
"Name can't be blank", | ||
"Name is too short (minimum is 2 characters)"] | ||
) | ||
)) | ||
end | ||
|
||
describe "#to_s" do | ||
it "outputs the records with the errors" do | ||
expect(subject.to_s).to eq( | ||
"Project 1:\n" + | ||
" Name can't be blank\n" + | ||
" Name is too short (minimum is 2 characters)" | ||
) | ||
describe "#to_s" do | ||
it "outputs the records with the errors" do | ||
expect(subject.to_s).to eq( | ||
"Project 1:\n" + | ||
" Name can't be blank\n" + | ||
" Name is too short (minimum is 2 characters)" | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe "#model_name" do | ||
it "returns the name of the wrapped model record" do | ||
expect(subject.model_name).to eq("Project") | ||
describe "#model_name" do | ||
it "returns the name of the wrapped model record" do | ||
expect(subject.model_name).to eq("Project") | ||
end | ||
end | ||
end | ||
|
||
describe "#model_total_count" do | ||
it "return the total number of records for the model" do | ||
expect(subject.model_total_count).to eq(1) | ||
describe "#model_total_count" do | ||
it "return the total number of records for the model" do | ||
expect(subject.model_total_count).to eq(1) | ||
end | ||
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
require "spec_helper" | ||
|
||
describe ValidationErrorReporter::Formatter do | ||
module ValidationErrorReporter | ||
describe Formatter do | ||
|
||
describe "#format(message)" do | ||
it "outpus a formatted message" do | ||
expect(subject.format(:message)).to eq(:message) | ||
describe "#format(message)" do | ||
it "outpus a formatted message" do | ||
expect(subject.format(:message)).to eq(:message) | ||
end | ||
end | ||
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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
require "spec_helper" | ||
|
||
describe ValidationErrorReporter::Notifiers::Console do | ||
let(:subject) { described_class.new(double) } | ||
module ValidationErrorReporter | ||
describe Notifiers::Console do | ||
let(:subject) { described_class.new(double) } | ||
|
||
describe "#notify" do | ||
it "sends its message to it's output" do | ||
printer = double | ||
notifier = described_class.new(double, printer) | ||
describe "#notify" do | ||
it "sends its message to it's output" do | ||
printer = double | ||
notifier = described_class.new(double, printer) | ||
|
||
expect(printer).to receive(:puts).with(:message) | ||
expect(printer).to receive(:puts).with(:message) | ||
|
||
notifier.notify(:message) | ||
notifier.notify(:message) | ||
end | ||
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 |
---|---|---|
@@ -1,30 +1,32 @@ | ||
require "spec_helper" | ||
|
||
describe ValidationErrorReporter::Notifiers::Email do | ||
include Mail::Matchers | ||
module ValidationErrorReporter | ||
describe Notifiers::Email do | ||
include Mail::Matchers | ||
|
||
let(:configuration) do | ||
ValidationErrorReporter::Configuration.new(from: "from@example.com", to: "to@example.com") | ||
end | ||
let(:subject) { described_class.new(configuration) } | ||
|
||
describe "#notify" do | ||
it "accumulates the notifications" do | ||
error = double | ||
subject.notify(error) | ||
expect(subject.instance_exec { @output }).to eq([error]) | ||
let(:configuration) do | ||
Configuration.new(from: "from@example.com", to: "to@example.com") | ||
end | ||
end | ||
let(:subject) { described_class.new(configuration) } | ||
|
||
describe "#finalize" do | ||
before do | ||
subject.finalize | ||
describe "#notify" do | ||
it "accumulates the notifications" do | ||
error = double | ||
subject.notify(error) | ||
expect(subject.instance_exec { @output }).to eq([error]) | ||
end | ||
end | ||
|
||
it { is_expected.to have_sent_email } | ||
it { is_expected.to have_sent_email.from("from@example.com") } | ||
it { is_expected.to have_sent_email.to("to@example.com") } | ||
it { is_expected.to have_sent_email.with_subject("ValidationErrorReporter") } | ||
it { is_expected.to have_sent_email.with_body("") } | ||
describe "#finalize" do | ||
before do | ||
subject.finalize | ||
end | ||
|
||
it { is_expected.to have_sent_email } | ||
it { is_expected.to have_sent_email.from("from@example.com") } | ||
it { is_expected.to have_sent_email.to("to@example.com") } | ||
it { is_expected.to have_sent_email.with_subject("ValidationErrorReporter") } | ||
it { is_expected.to have_sent_email.with_body("") } | ||
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
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,20 +1,20 @@ | ||
require "spec_helper" | ||
|
||
describe ValidationErrorReporter::Profiler do | ||
module ValidationErrorReporter | ||
describe Profiler do | ||
describe "#profile" do | ||
it "returns a hash with stats" do | ||
error_1 = double(model_name: "Project", model_total_count: 4) | ||
error_2 = double(model_name: "Project", model_total_count: 4) | ||
|
||
describe "#profile" do | ||
it "returns a hash with stats" do | ||
error_1 = double(model_name: "Project", model_total_count: 4) | ||
error_2 = double(model_name: "Project", model_total_count: 4) | ||
|
||
expect(subject.profile([error_1, error_2])).to eq({ | ||
"Project" => { | ||
count: 2, | ||
total: 4, | ||
rate: 50.0, | ||
}, | ||
}) | ||
expect(subject.profile([error_1, error_2])).to eq({ | ||
"Project" => { | ||
count: 2, | ||
total: 4, | ||
rate: 50.0, | ||
}, | ||
}) | ||
end | ||
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 |
---|---|---|
@@ -1,40 +1,41 @@ | ||
require "spec_helper" | ||
|
||
describe ValidationErrorReporter::Reporter do | ||
module ValidationErrorReporter | ||
describe Reporter do | ||
|
||
let(:configuration) { ValidationErrorReporter::Configuration.new } | ||
let(:subject) { described_class.new(configuration) } | ||
let(:configuration) { Configuration.new } | ||
let(:subject) { described_class.new(configuration) } | ||
|
||
describe "initialize(configration)" do | ||
it "assigns notifiers from the configuration" do | ||
expect(subject.notifiers).to eq(configuration.notifiers) | ||
expect(subject.profiler).to eq(configuration.profiler) | ||
describe "initialize(configration)" do | ||
it "assigns notifiers from the configuration" do | ||
expect(subject.notifiers).to eq(configuration.notifiers) | ||
expect(subject.profiler).to eq(configuration.profiler) | ||
end | ||
end | ||
end | ||
|
||
describe "#report(error)" do | ||
it "sends all the failed records to the notifiers" do | ||
error = double(:to_s) | ||
describe "#report(error)" do | ||
it "sends all the failed records to the notifiers" do | ||
error = double(:to_s) | ||
|
||
expect(error).to receive(:to_s).exactly(1).times | ||
expect_any_instance_of(ValidationErrorReporter::Notifiers::Console).to receive(:notify).exactly(1).times | ||
expect(error).to receive(:to_s).exactly(1).times | ||
expect_any_instance_of(Notifiers::Console).to receive(:notify).exactly(1).times | ||
|
||
subject.report(error) | ||
subject.report(error) | ||
end | ||
end | ||
end | ||
|
||
describe "#finalize" do | ||
it "finalizes all notifiers" do | ||
notifier = double | ||
configuration = ValidationErrorReporter::Configuration.new | ||
configuration.notifiers = [notifier] | ||
describe "#finalize" do | ||
it "finalizes all notifiers" do | ||
notifier = double | ||
configuration = Configuration.new | ||
configuration.notifiers = [notifier] | ||
|
||
reporter = described_class.new(configuration) | ||
reporter = described_class.new(configuration) | ||
|
||
expect(notifier).to receive(:notify).exactly(1).times | ||
expect(notifier).to receive(:finalize).exactly(1).times | ||
reporter.finalize | ||
expect(notifier).to receive(:notify).exactly(1).times | ||
expect(notifier).to receive(:finalize).exactly(1).times | ||
reporter.finalize | ||
end | ||
end | ||
end | ||
|
||
end |