Skip to content

Commit

Permalink
Merge pull request #16 from it3s/fix-i18n-specs
Browse files Browse the repository at this point in the history
Replace hardcoded strings with translations (fix #14)
  • Loading branch information
LuizArmesto committed Mar 15, 2014
2 parents 63eb279 + b38f24c commit ad34650
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 41 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ group :development, :test do
gem 'pry' # better shell sessions and debug tool
gem 'pry-rails' # use pry as rails console
gem 'konacha' # js tests with mocha + chai
gem 'guard-rspec', require: false # launch specs when files are modified
end

group :test do
Expand All @@ -60,4 +61,5 @@ group :test do
gem 'database_cleaner' # improved database cleaning for tests
gem 'simplecov', '~> 0.7.1', require: false # coverage report
gem 'coveralls', require: false # use coveralls with travisCI
gem 'i18n-tasks', '~> 0.3.9' # check for translations
end
99 changes: 73 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ GEM
tzinfo (~> 0.3.37)
addressable (2.3.5)
arel (4.0.2)
atomic (1.1.14)
bcrypt-ruby (3.1.2)
atomic (1.1.15)
bcrypt (3.1.7)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
better_errors (1.1.0)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
Expand All @@ -53,6 +55,9 @@ GEM
carrierwave (~> 0.5)
celluloid (0.15.2)
timers (~> 1.1.0)
celluloid-io (0.15.0)
celluloid (>= 0.15.0)
nio4r (>= 0.5.0)
chunky_png (1.3.0)
clean_logger (0.0.5)
rails
Expand All @@ -65,14 +70,14 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.7.0)
colorize (0.6.0)
compass (0.12.2)
colorize (0.7.0)
compass (0.12.3)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
compass-rails (1.1.3)
sass (= 3.2.14)
compass-rails (1.1.6)
compass (>= 0.12.2)
connection_pool (1.2.0)
connection_pool (2.0.0)
coveralls (0.7.0)
multi_json (~> 1.3)
rest-client
Expand All @@ -82,18 +87,23 @@ GEM
database_cleaner (1.2.0)
debug_inspector (0.0.2)
diff-lcs (1.2.5)
dotenv (0.9.0)
dotenv (0.10.0)
easy_translate (0.4.0)
json
thread
thread_safe
ejs (1.1.1)
erubis (2.7.0)
excon (0.31.0)
execjs (2.0.2)
factory_girl (4.4.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.4.0)
factory_girl_rails (4.4.1)
factory_girl (~> 4.4.0)
railties (>= 3.0.0)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
ffi (1.9.3)
fog (1.20.0)
builder
excon (~> 0.31.0)
Expand All @@ -110,9 +120,27 @@ GEM
thor (>= 0.13.6)
formatador (0.2.4)
fssm (0.2.10)
guard (2.5.1)
formatador (>= 0.2.4)
listen (~> 2.6)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-rspec (4.2.8)
guard (~> 2.1)
rspec (>= 2.14, < 4.0)
highline (1.6.21)
hike (1.2.3)
http_accept_language (2.0.1)
i18n (0.6.9)
i18n-tasks (0.3.9)
activesupport
easy_translate (>= 0.4.0)
erubis
highline
slop (>= 3.4.7)
term-ansicolor
terminal-table
jquery-fileupload-rails (0.4.1)
actionpack (>= 3.1)
railties (>= 3.1)
Expand All @@ -122,7 +150,7 @@ GEM
json (1.8.1)
jwt (0.1.11)
multi_json (>= 1.5)
konacha (3.1.0)
konacha (3.2.0)
actionpack (>= 3.1, < 5)
capybara
colorize
Expand All @@ -132,9 +160,15 @@ GEM
addressable (~> 2.3)
letter_opener (1.2.0)
launchy (~> 2.2)
letter_opener_web (1.1.2)
letter_opener_web (1.1.3)
letter_opener (~> 1.0)
rails (>= 3.2)
listen (2.7.1)
celluloid (>= 0.15.2)
celluloid-io (>= 0.15.0)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.4)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
Expand All @@ -144,12 +178,13 @@ GEM
subexec (~> 0.2.1)
mini_portile (0.5.2)
minitest (4.7.5)
multi_json (1.8.4)
multi_json (1.9.0)
multi_xml (0.5.5)
multipart-post (2.0.0)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.8.0)
nio4r (1.0.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
oauth (0.4.7)
Expand All @@ -167,14 +202,14 @@ GEM
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
polyglot (0.3.3)
polyglot (0.3.4)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
pry-rails (0.3.2)
pry (>= 0.9.10)
puma (2.7.1)
puma (2.8.1)
rack (>= 1.1, < 2.0)
rack (1.5.2)
rack-test (0.6.2)
Expand All @@ -193,6 +228,9 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.1.1)
rb-fsevent (0.9.4)
rb-inotify (0.9.3)
ffi (>= 0.5.0)
rdoc (4.1.1)
json (~> 1.4)
redis (3.0.7)
Expand All @@ -201,10 +239,14 @@ GEM
remotipart (1.2.1)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec-core (2.14.7)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.5)
rspec-mocks (2.14.6)
rspec-rails (2.14.1)
actionpack (>= 3.0)
activemodel (>= 3.0)
Expand All @@ -214,16 +256,17 @@ GEM
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
sass (3.2.14)
sass-rails (4.0.1)
sass-rails (4.0.2)
railties (>= 4.0.0, < 5.0)
sass (>= 3.1.10)
sass (~> 3.2.0)
sprockets (~> 2.8, <= 2.11.0)
sprockets-rails (~> 2.0.0)
sdoc (0.4.0)
json (~> 1.8)
rdoc (~> 4.0, < 5.0)
shoulda-matchers (2.5.0)
activesupport (>= 3.0.0)
sidekiq (2.17.6)
sidekiq (2.17.7)
celluloid (>= 0.15.2)
connection_pool (>= 1.0.0)
json
Expand All @@ -236,12 +279,12 @@ GEM
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
slop (3.4.7)
slop (3.5.0)
sorcery (0.8.5)
bcrypt-ruby (>= 3.0)
oauth (~> 0.4.4)
oauth2 (>= 0.8.0, < 1.0.0)
sprockets (2.10.1)
sprockets (2.11.0)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
Expand All @@ -253,9 +296,11 @@ GEM
subexec (0.2.3)
term-ansicolor (1.3.0)
tins (~> 1.0)
terminal-table (1.4.5)
thor (0.18.1)
thread_safe (0.1.3)
atomic
thread (0.1.3)
thread_safe (0.2.0)
atomic (>= 1.1.7, < 2)
tilt (1.4.1)
timers (1.1.0)
tins (1.0.0)
Expand All @@ -266,11 +311,11 @@ GEM
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.38)
uglifier (2.4.0)
tzinfo (0.3.39)
uglifier (2.5.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
underscore-rails (1.5.2)
underscore-rails (1.6.0)
websocket-driver (0.3.2)
xpath (2.0.0)
nokogiri (~> 1.3)
Expand All @@ -295,7 +340,9 @@ DEPENDENCIES
fog
font-awesome-sass
foreman
guard-rspec
http_accept_language
i18n-tasks (~> 0.3.9)
jquery-fileupload-rails
jquery-rails
konacha
Expand Down
24 changes: 24 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :rspec do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }

# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end

32 changes: 32 additions & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# config/i18n-tasks.yml
# i18n data storage
data:
read:
- 'config/locales/%{locale}.yml'
- 'config/locales/%{locale}/*.yml'

# i18n usage search in source
search:
# search these directories (relative to your Rails.root directory, default: 'app/')
paths:
- 'app/'
- 'vendor/'
- 'spec/'

# do not report these keys as unused
ignore_unused:
- activerecord.*
- simple_form.*

# do not report these keys when they have the same value as the base locale version
ignore_eq_base:
all:
- simple_form.required.mark
- contacts.facebook
- contacts.twitter

pt-BR:
- contacts.email
- contacts.site
- sessions.form.login.email
- simple_form.labels.defaults.email
6 changes: 3 additions & 3 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@

describe "no data" do
let(:params) { {} }
it { expect(response.body).to match({:errors => 'Fields can\'t be blank' }.to_json) }
it { expect(response.body).to match({:errors => controller.t('sessions.create.blank')}.to_json) }
it_behaves_like "return json with :unprocessable_entity"
end

describe "user pending" do
let!(:user) { FactoryGirl.create(:pending_user, :password => passwd) }
let(:params) { {:email => user.email, :password => passwd} }

it { expect(response.body).to match({:errors => 'Activation pending'}.to_json) }
it { expect(response.body).to match({:errors => controller.t('sessions.create.pending')}.to_json) }
it_behaves_like "return json with :unprocessable_entity"
end

describe "invalid email or password" do
let!(:user) { FactoryGirl.create(:user, :password => passwd) }
let(:params) { {:email => user.email, :password => '321654'} }

it { expect(response.body).to match({:errors => 'E-mail or Password invalid'}.to_json) }
it { expect(response.body).to match({:errors => controller.t('sessions.create.invalid')}.to_json) }
it_behaves_like "return json with :unprocessable_entity"
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
end

context "invalid params" do
let(:errors_json) { {:errors => {:password_confirmation => ["doesn't match Password"]}}.to_json }
let(:errors_json) { {:errors => {:password_confirmation => [controller.t('activerecord.errors.messages.confirmation', {:attribute => 'Password'})]}}.to_json }
before { params.merge! :user => {:password => '123456', :password_confirmation => '654321', :email => user.email} }
it 'return errors' do
post :update_password, params
Expand Down Expand Up @@ -223,7 +223,7 @@
it 'validates model and returns errors' do
post :update, {:id => user.id, :user => user_params.merge!(:name => "")}
expect(assigns :user).to eq user
expect(response.body).to eq({:errors => {:name => ["can't be blank"]}}.to_json)
expect(response.body).to eq({:errors => {:name => [controller.t('activerecord.errors.messages.blank')]}}.to_json)
user.reload
end

Expand Down
Loading

0 comments on commit ad34650

Please sign in to comment.