Commit 4be375ef36518d8fbdf61695d184ccf614e0b18f

Authored by Nick Recobra
1 parent d1942b79
Exists in master and in 1 other branch production

Drying AppsController more & recover flash class.

app/controllers/apps_controller.rb
... ... @@ -2,6 +2,7 @@ class AppsController < InheritedResources::Base
2 2  
3 3 before_filter :require_admin!, :except => [:index, :show]
4 4 before_filter :parse_email_at_notices_or_set_default, :only => [:create, :update]
  5 + respond_to :html
5 6  
6 7 def show
7 8 where_clause = {}
... ... @@ -35,23 +36,15 @@ class AppsController < InheritedResources::Base
35 36 edit!
36 37 end
37 38  
38   - def create
39   - create! :success => 'Great success! Configure your app with the API key below'
40   - end
41   -
42   - def update
43   - update! :success => "Good news everyone! '#{resource.name}' was successfully updated."
44   - end
45   -
46   - def destroy
47   - destroy! :success => "'#{resource.name}' was successfully destroyed."
48   - end
49   -
50 39 protected
51 40 def begin_of_association_chain
52 41 current_user unless current_user.admin?
53 42 end
54 43  
  44 + def interpolation_options
  45 + {:app_name => resource.name}
  46 + end
  47 +
55 48 # email_at_notices is edited as a string, and stored as an array.
56 49 def parse_email_at_notices_or_set_default
57 50 if params[:app] && val = params[:app][:email_at_notices]
... ...
config/initializers/inherited_resources.rb 0 → 100644
... ... @@ -0,0 +1 @@
  1 +InheritedResources.flash_keys = [:success, :error]
... ...
config/locales/en.yml
... ... @@ -3,3 +3,11 @@
3 3  
4 4 en:
5 5 hello: "Hello world"
  6 + flash:
  7 + apps:
  8 + create:
  9 + success: Great success! Configure your app with the API key below
  10 + update:
  11 + success: "Good news everyone! '%{app_name}' was successfully updated."
  12 + destroy:
  13 + success: "'%{app_name}' was successfully destroyed."
... ...
spec/controllers/apps_controller_spec.rb
... ... @@ -201,7 +201,7 @@ describe AppsController do
201 201  
202 202 it "should display a message" do
203 203 post :create, :app => {}
204   - request.flash[:notice].should match(/success/)
  204 + request.flash[:success].should match(/success/)
205 205 end
206 206 end
207 207 end
... ... @@ -219,7 +219,7 @@ describe AppsController do
219 219  
220 220 it "should display a message" do
221 221 put :update, :id => @app.id, :app => {}
222   - request.flash[:notice].should match(/success/)
  222 + request.flash[:success].should match(/success/)
223 223 end
224 224 end
225 225  
... ... @@ -424,7 +424,7 @@ describe AppsController do
424 424  
425 425 it "should display a message" do
426 426 delete :destroy, :id => @app.id
427   - request.flash[:notice].should match(/success/)
  427 + request.flash[:success].should match(/success/)
428 428 end
429 429  
430 430 it "should redirect to the apps page" do
... ...