Commit 43b4f0ca

mo khan <mo@mokhan.ca>
2015-02-02 05:05:11
move translations to separate files.
1 parent 893b13b
Changed files (6)
app
config
locales
controllers
my
passwords
passwords
spec
app/controllers/my/passwords_controller.rb
@@ -11,13 +11,13 @@ module My
     def password_changed(user)
       @user = user
       sign_in(@user, bypass: true) unless Rails.env.test?
-      flash[:notice] = t('passwords.updated')
+      flash[:notice] = t("my.passwords.updated")
       render :index
     end
 
     def password_changed_failed(user)
       @user = user
-      flash[:error] = t(:passwords_do_not_match)
+      flash[:error] = t("my.passwords.passwords_do_not_match")
       render :index
     end
   end
config/locales/controllers/my/passwords/en.yml
@@ -0,0 +1,5 @@
+en:
+  my:
+    passwords:
+      updated: 'Your password was updated.'
+      passwords_do_not_match: 'The passwords should match and should be a minimum of 6 characters.'
config/locales/controllers/passwords/en.yml
@@ -0,0 +1,3 @@
+en:
+  passwords:
+    send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
config/locales/en.yml
@@ -22,11 +22,7 @@
 en:
   hello: "Hello world"
   share_something: "You have not uploaded anything!"
-  passwords_do_not_match: 'The passwords should match and should be a minimum of 6 characters.'
   tutorial_saved: 'Your tutorial was added.'
-  passwords:
-    send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
-    updated: 'Your password was updated.'
   profile_saved: 'Your settings have been updated successfully!'
   avatar_uploaded: 'Your avatar has been updated.'
   my:
spec/controllers/my/passwords_controller_spec.rb
@@ -5,7 +5,7 @@ describe My::PasswordsController do
     context "when not logged in" do
       let(:user) { create(:user) }
 
-      it "should redirect you to the login page" do
+      it "redirects you to the login page" do
         put :update, id: user.id
         expect(response).to redirect_to(login_path)
       end
@@ -17,25 +17,33 @@ describe My::PasswordsController do
       before { http_login(user) }
 
       context "when the new password and the confirmation password does not match" do
-        before { put :update, :id => user.id, :user => { :password => 'foobar', :password_confirmation => 'barfoo' } }
+        before :each do
+          put :update, id: user.id, user: {
+            password: "foobar",
+            password_confirmation: "barfoo"
+          }
+        end
 
-        it "should display an error on the page" do
-          expect(flash[:error]).to eql(I18n.t(:passwords_do_not_match))
+        it "displays an error on the page" do
+          expect(flash[:error]).to eql(I18n.t("my.passwords.passwords_do_not_match"))
         end
 
-        it "should render the show template" do
+        it "renders the show template" do
           expect(response).to render_template(:index)
         end
       end
 
       context "when the password and confirmation match" do
-        let(:new_password) { 'booyakasham' }
+        let(:new_password) { "booyakasham" }
 
         before :each do
-          put :update, id: user.id, user: { password: new_password, password_confirmation: new_password }
+          put :update, id: user.id, user: {
+            password: new_password,
+            password_confirmation: new_password
+          }
         end
 
-        it "should update the users password" do
+        it "updates the users password" do
           expect(user.reload.authenticate(new_password)).to be_truthy
         end
       end
@@ -43,7 +51,7 @@ describe My::PasswordsController do
   end
 
   describe "#index" do
-    context 'when logged in' do
+    context "when logged in" do
       let(:user) { create(:user) }
 
       before :each do
@@ -52,7 +60,7 @@ describe My::PasswordsController do
       end
 
       context "when displaying a form to change the current password" do
-        it "should load the user" do
+        it "loads the user" do
           expect(assigns(:user)).to eql(user)
         end
       end
spec/features/change_password_spec.rb
@@ -6,22 +6,23 @@ describe "changing my password", js: true do
 
     before :each do
       visit login_path
-      within('.form-inline') do
-        fill_in('session_username', :with => user.email)
-        fill_in('session_password', :with => "password")
+      within(".form-inline") do
+        fill_in("session_username", :with => user.email)
+        fill_in("session_password", :with => "password")
       end
       click_button("Sign In")
       visit my_dashboard_path
       click_link("Account")
       within(".form-horizontal") do
-        fill_in('user_password', :with => "mopass")
-        fill_in('user_password_confirmation', :with => "mopass")
+        fill_in("user_password", :with => "mopass")
+        fill_in("user_password_confirmation", :with => "mopass")
       end
       click_button "Update password"
     end
 
-    it "should display a confirmation message" do
-      expect(page).to have_content(I18n.translate('passwords.updated'))
+    it "displays a confirmation message" do
+      confirmation_message = I18n.translate("my.passwords.updated")
+      expect(page).to have_content(confirmation_message)
     end
   end
 end