Skip to content

Commit

Permalink
Using flash :notice key everywhere now instead of :success and :failu…
Browse files Browse the repository at this point in the history
…re. More in line with Rails conventions.
  • Loading branch information
Dan Croak committed Jun 30, 2011
1 parent b2cd877 commit d955f09
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@

* [#129] Denying access redirects to root_url when signed in, sign_in_url when signed out. (Dan Croak)
* New configuration setting: denied_access_url. (Dan Croak)
* Using flash :notice key everywhere now instead of :success and :failure. More in line with Rails conventions. (Dan Croak)

0.11.2
-------------------
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/clearance/passwords_controller.rb
Expand Up @@ -59,7 +59,7 @@ def forbid_non_existent_user
end

def flash_failure_when_forbidden
flash.now[:failure] = translate(:forbidden,
flash.now[:notice] = translate(:forbidden,
:scope => [:clearance, :controllers, :passwords],
:default => "Please double check the URL or try submitting the form again.")
end
Expand All @@ -72,17 +72,17 @@ def flash_notice_after_create
end

def flash_failure_after_create
flash.now[:failure] = translate(:unknown_email,
flash.now[:notice] = translate(:unknown_email,
:scope => [:clearance, :controllers, :passwords],
:default => "Unknown email.")
end

def flash_success_after_update
flash[:success] = translate(:signed_in, :default => "Signed in.")
flash[:notice] = translate(:signed_in, :default => "Signed in.")
end

def flash_failure_after_update
flash.now[:failure] = translate(:blank_password,
flash.now[:notice] = translate(:blank_password,
:scope => [:clearance, :controllers, :passwords],
:default => "Password can't be blank.")
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/clearance/sessions_controller.rb
Expand Up @@ -29,21 +29,21 @@ def destroy
private

def flash_failure_after_create
flash.now[:failure] = translate(:bad_email_or_password,
flash.now[:notice] = translate(:bad_email_or_password,
:scope => [:clearance, :controllers, :sessions],
:default => "Bad email or password.")
end

def flash_success_after_create
flash[:success] = translate(:signed_in, :default => "Signed in.")
flash[:notice] = translate(:signed_in, :default => "Signed in.")
end

def url_after_create
'/'
end

def flash_success_after_destroy
flash[:success] = translate(:signed_out, :default => "Signed out.")
flash[:notice] = translate(:signed_out, :default => "Signed out.")
end

def url_after_destroy
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/clearance/users_controller.rb
Expand Up @@ -13,7 +13,7 @@ def create
@user = ::User.new(params[:user])
if @user.save
sign_in(@user)
flash_notice_after_create
flash_success_after_create
redirect_to(url_after_create)
else
flash_failure_after_create
Expand All @@ -23,14 +23,14 @@ def create

private

def flash_notice_after_create
def flash_success_after_create
flash[:notice] = translate(:signed_up,
:scope => [:clearance, :controllers, :users],
:default => "You are now signed up.")
end

def flash_failure_after_create
flash.now[:failure] = translate(:bad_email_or_password,
flash.now[:notice] = translate(:bad_email_or_password,
:scope => [:clearance, :controllers, :passwords],
:default => "Must be a valid email address. Password can't be blank.")
end
Expand Down
1 change: 1 addition & 0 deletions gemfiles/3.1.0.rc4.gemfile
Expand Up @@ -19,4 +19,5 @@ gem "sass-rails"
gem "coffee-script"
gem "uglifier"
gem "jquery-rails"
gem "turn"

4 changes: 4 additions & 0 deletions gemfiles/3.1.0.rc4.gemfile.lock
Expand Up @@ -53,6 +53,7 @@ GEM
activesupport (= 3.1.0.rc4)
activesupport (3.1.0.rc4)
multi_json (~> 1.0)
ansi (1.2.5)
arel (2.1.1)
aruba (0.4.3)
bcat (>= 0.6.1)
Expand Down Expand Up @@ -182,6 +183,8 @@ GEM
tilt (1.3.2)
treetop (1.4.9)
polyglot (>= 0.3.1)
turn (0.8.2)
ansi (>= 1.2.2)
tzinfo (0.3.28)
uglifier (0.5.4)
execjs (>= 0.3.0)
Expand Down Expand Up @@ -209,4 +212,5 @@ DEPENDENCIES
sass-rails
shoulda-matchers!
sqlite3
turn
uglifier
5 changes: 1 addition & 4 deletions spec/controllers/passwords_controller_spec.rb
Expand Up @@ -53,10 +53,7 @@
ActionMailer::Base.deliveries.should be_empty
end

it "should set the failure flash to Unknown email" do
flash.now[:failure].should =~ /unknown email/i
end

it { should set_the_flash.to(/unknown email/i).now }
it { should render_template(:new) }
end
end
Expand Down

0 comments on commit d955f09

Please sign in to comment.