diff options
| author | mo khan <mo@mokhan.ca> | 2014-11-15 17:14:08 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-11-15 17:14:08 -0700 |
| commit | 700f6c4993dcbfab7963ac7473be116245c3ad83 (patch) | |
| tree | 2dd394c0bb354dcf2c41f2dba03d95ede9b1d05c | |
| parent | c6b45629633a1187af8fc44dd196320a61b1ff84 (diff) | |
display flash messages and add first functional test.
| -rw-r--r-- | app/helpers/application_helper.rb | 3 | ||||
| -rw-r--r-- | app/views/layouts/public.html.erb | 1 | ||||
| -rw-r--r-- | app/views/shared/_flash.html.erb | 6 | ||||
| -rw-r--r-- | spec/features/login_spec.rb | 12 | ||||
| -rw-r--r-- | spec/helpers/application_helper_spec.rb | 15 |
5 files changed, 37 insertions, 0 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..358c93b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def alert_class_for(flash_type) + "alert-#{{ success: 'success', error: 'danger', alert: 'warning', notice: 'info' }.fetch(flash_type.to_sym, flash_type)}" + end end diff --git a/app/views/layouts/public.html.erb b/app/views/layouts/public.html.erb index 6c02291..abce0b3 100644 --- a/app/views/layouts/public.html.erb +++ b/app/views/layouts/public.html.erb @@ -14,6 +14,7 @@ </head> <body> <div class="container"> + <%= render partial: 'shared/flash' %> <%= yield %> </div> <!-- /container --> </body> diff --git a/app/views/shared/_flash.html.erb b/app/views/shared/_flash.html.erb new file mode 100644 index 0000000..d21c1d1 --- /dev/null +++ b/app/views/shared/_flash.html.erb @@ -0,0 +1,6 @@ +<% flash.each do |type, message| %> + <div class="alert <%= alert_class_for(type) %> alert-dismissible fade in"> + <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> + <%= message %> + </div> +<% end if flash.any? %> diff --git a/spec/features/login_spec.rb b/spec/features/login_spec.rb index ef83ce3..fcf219d 100644 --- a/spec/features/login_spec.rb +++ b/spec/features/login_spec.rb @@ -12,4 +12,16 @@ describe "the signin process", type: :feature do click_button "Sign in" expect(page).to have_content("Dashboard") end + + context "when the password is incorrect" do + it 'displays an error' do + visit root_path + within ".form-signin" do + fill_in 'email', with: user.email + fill_in 'password', with: 'wrong' + end + click_button "Sign in" + expect(page).to have_content(I18n.translate(:invalid_credentials)) + end + end end diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 0000000..940c7bb --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +describe ApplicationHelper do + describe "#alert_class_for" do + it { expect(alert_class_for(:success)).to eql('alert-success') } + + it { expect(alert_class_for(:error)).to eql('alert-danger') } + + it { expect(alert_class_for(:alert)).to eql('alert-warning') } + + it { expect(alert_class_for(:notice)).to eql('alert-info') } + + it { expect(alert_class_for(:unknown)).to eql('alert-unknown') } + end +end |
