Skip to content

Commit

Permalink
more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
andersoncardoso committed Sep 10, 2014
1 parent 86c6982 commit 52af115
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/concerns/i18n_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def current_translations
end

def language_options
I18n.available_locales.map { |lang| [i18n_language_names[lang], lang] }
I18n.available_locales.map { |lang| [i18n_language_names[lang], lang.to_s] }
end
end
end
45 changes: 45 additions & 0 deletions spec/controllers/settings_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'spec_helper'

describe SettingsController do
let(:user) { FactoryGirl.create :user, language: 'en', mail_notifications: 'daily' }

before { login_user user }

describe "GET show" do
it 'renders setings page' do
get :show, id: user.id
expect(assigns :user).to eq user
expect(assigns :settings).to eq user.settings
expect(response).to render_template :show
end

it "redirects if not user itself" do
other = FactoryGirl.create :user
get :show, id: other.id
expect(response).to redirect_to controller.root_path
end
end

describe "GET show" do
it 'renders setings page' do
expect(user.language).to eq 'en'
expect(user.mail_notifications).to eq 'daily'

patch :update, id: user.id, settings: {mail_notifications: 'weekly', language: 'pt-BR' }

expect(response.status).to eq 200
expect(response.body).to include({redirect: controller.user_path(user)}.to_json)

user.reload
expect(user.language).to eq 'pt-BR'
expect(user.mail_notifications).to eq 'weekly'
end

it "redirects if not user itself" do
other = FactoryGirl.create :user
patch :update, id: other.id
expect(response).to redirect_to controller.root_path
end
end

end
9 changes: 9 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@
expect(translations).to eq I18n.backend.send(:translations)[:en].with_indifferent_access
end
end

describe "#language_options" do
it "generates list of options" do
opts = helper.language_options
expect(opts).to be_a_kind_of Array
expect(opts).to include ['English', 'en']
expect(opts).to include ['Português', 'pt-BR']
end
end
end

describe "Concerns::ContactsHelper" do
Expand Down
15 changes: 15 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
it { expect(subject).to have_db_column :contacts }
it { expect(subject).to have_db_column :avatar }
it { expect(subject).to have_db_column :location }
it { expect(subject).to have_db_column :mail_notifications }

it 'validates format of email' do
user.email = 'invalidmail'
Expand All @@ -39,6 +40,11 @@
expect(User.find_by(:id => user.id).contacts).to eq({'test' => 'ok', 'address' => 'av paulista, 800, SP'})
end

it "has default for mail_notifications" do
user = FactoryGirl.create(:user)
expect(user.mail_notifications).to eq 'daily'
end

describe "encryption matches legacy DB" do
let(:salt) { 'batata-frita' }

Expand Down Expand Up @@ -130,4 +136,13 @@

it { expect(user.auth_token).to_not be nil }
end

describe "settings" do
let(:user) { FactoryGirl.build :user }

it "build settings model for the user" do
expect(Settings).to receive(:new).with(user)
user.settings
end
end
end

0 comments on commit 52af115

Please sign in to comment.