-
Notifications
You must be signed in to change notification settings - Fork 102
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 #94 in INTL/shuttle from yunus/update-multiple-tra…
…nslation-at-once to master * commit '87432a373ce8d7c613f6a9d6c7921dcbadd1fbab': Update multiple translation at once
- Loading branch information
Showing
8 changed files
with
462 additions
and
37 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2014 Square Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Implements basic mediator functionality such as keeping track of errors and | ||
# providing helper methods to interact with them. | ||
# | ||
# Fields | ||
# ====== | ||
# | ||
# | | | | ||
# |:---------|:---------------------------------------------------------------------------------| | ||
# | `errors` | an array which should keep track of errors that happened in the inheriting class | | ||
|
||
class BasicMediator | ||
|
||
attr_reader :errors | ||
|
||
def initialize | ||
@errors = [] | ||
end | ||
|
||
# @return [true, false] true if no errors have been recorded, false otherwise | ||
def success? | ||
@errors.blank? | ||
end | ||
|
||
# @return [true, false] true if any errors have been recorded, false otherwise | ||
def failure? | ||
!success? | ||
end | ||
|
||
private | ||
|
||
# Add multiple errors at once | ||
# | ||
# @param [Array<String>] msgs a list of error messages in String format | ||
|
||
def add_errors(msgs) | ||
@errors.push(*msgs) | ||
end | ||
|
||
# Add a single error | ||
# | ||
# @param [String] msg an error message in String format | ||
|
||
def add_error(msg) | ||
@errors.push(msg) | ||
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
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 |
---|---|---|
|
@@ -95,14 +95,6 @@ | |
{"name"=>"test2 user3", "email"=>"[email protected]"}, | ||
{"name"=>"1test2 user4", "email"=>"[email protected]"}]) | ||
end | ||
|
||
it "returns fuzzy matched users' email addresses and names" do | ||
pending # TODO (yunus): implement fuzzy matching | ||
FactoryGirl.create(:user, :activated, first_name: "tast", last_name: "user1", email: '[email protected]') # fuzzy match | ||
FactoryGirl.create(:user, :activated, first_name: "attast", last_name: "user2", email: '[email protected]') # miss | ||
subject | ||
expect(JSON.parse(response.body)).to eql([{"name"=>"tast user1", "email"=>"[email protected]"}]) | ||
end | ||
end | ||
|
||
context "[matching by last name]" do | ||
|
@@ -118,14 +110,6 @@ | |
{"name"=>"user3 test2", "email"=>"[email protected]"}, | ||
{"name"=>"user4 1test2", "email"=>"[email protected]"}]) | ||
end | ||
|
||
it "returns fuzzy matched users' email addresses and names" do | ||
pending # TODO (yunus): implement fuzzy matching | ||
FactoryGirl.create(:user, :activated, first_name: "user1", last_name: "tast", email: '[email protected]') # fuzzy match | ||
FactoryGirl.create(:user, :activated, first_name: "user2", last_name: "attast", email: '[email protected]') # miss | ||
subject | ||
expect(JSON.parse(response.body)).to eql([{"name"=>"user1 tast", "email"=>"[email protected]"}]) | ||
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2014 Square Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require 'spec_helper' | ||
|
||
describe BasicMediator do | ||
before :each do | ||
@mediator = BasicMediator.new | ||
end | ||
|
||
describe "#success?" do | ||
it "returns true if there are no errors" do | ||
expect(@mediator.success?).to eql(true) | ||
end | ||
|
||
it "returns false if there are any errors" do | ||
@mediator.send(:add_error, "Test") | ||
expect(@mediator.success?).to eql(false) | ||
end | ||
end | ||
|
||
describe "#failure?" do | ||
it "returns true if there are any errors" do | ||
@mediator.send(:add_error, "Test") | ||
expect(@mediator.failure?).to eql(true) | ||
end | ||
|
||
it "returns false if there are no errors" do | ||
expect(@mediator.failure?).to eql(false) | ||
end | ||
end | ||
|
||
describe "#add_error" do | ||
it "adds an error to mediator" do | ||
@mediator.send(:add_error, "Test1") | ||
@mediator.send(:add_error, "Test2") | ||
expect(@mediator.errors).to eql(["Test1", "Test2"]) | ||
end | ||
end | ||
|
||
describe "#add_errors" do | ||
it "adds errors in bulk to mediator" do | ||
@mediator.send(:add_errors, ["Test1", "Test2"]) | ||
@mediator.send(:add_errors, ["Test3", "Test4"]) | ||
expect(@mediator.errors).to eql(["Test1", "Test2", "Test3", "Test4"]) | ||
end | ||
end | ||
end |
Oops, something went wrong.