Commit 508db3da205f036fb2ad734cfc117ef291ac557c

Authored by Jared Pace
1 parent 3977fd27
Exists in master and in 1 other branch production

Don't show regular users links to manage apps

app/controllers/apps_controller.rb
1 class AppsController < ApplicationController 1 class AppsController < ApplicationController
2 2
  3 + before_filter :require_admin!, :except => [:index, :show]
  4 +
3 def index 5 def index
4 @apps = App.all 6 @apps = App.all
5 end 7 end
app/views/apps/index.html.haml
1 - content_for :title, 'Apps' 1 - content_for :title, 'Apps'
2 - content_for :action_bar do 2 - content_for :action_bar do
3 - %span= link_to('Add a New App', new_app_path, :class => 'add') 3 + %span= link_to('Add a New App', new_app_path, :class => 'add') if current_user.admin?
4 4
5 %table.apps 5 %table.apps
6 %thead 6 %thead
app/views/apps/show.html.haml
@@ -5,9 +5,10 @@ @@ -5,9 +5,10 @@
5 %strong API Key: 5 %strong API Key:
6 = @app.api_key 6 = @app.api_key
7 - content_for :action_bar do 7 - content_for :action_bar do
8 - = link_to 'edit', edit_app_path(@app)  
9 - |  
10 - = link_to 'destroy', app_path(@app), :method => :delete, :confirm => 'Seriously?' 8 + - if current_user.admin?
  9 + = link_to 'edit', edit_app_path(@app)
  10 + |
  11 + = link_to 'destroy', app_path(@app), :method => :delete, :confirm => 'Seriously?'
11 12
12 - if @app.errs.none? 13 - if @app.errs.none?
13 %h3 Setup your app 14 %h3 Setup your app
spec/controllers/apps_controller_spec.rb
1 require 'spec_helper' 1 require 'spec_helper'
2 2
3 -describe AppsController do 3 +describe AppsController, :focused => true do
4 4
5 it_requires_authentication 5 it_requires_authentication
6 -  
7 - before do  
8 - sign_in Factory(:user)  
9 - end 6 + it_requires_admin_privileges :for => {:new => :get, :edit => :get, :create => :post, :update => :put, :destroy => :delete}
10 7
11 describe "GET /apps" do 8 describe "GET /apps" do
12 it 'finds all apps' do 9 it 'finds all apps' do
  10 + sign_in Factory(:user)
13 3.times { Factory(:app) } 11 3.times { Factory(:app) }
14 apps = App.all 12 apps = App.all
15 get :index 13 get :index
@@ -19,115 +17,122 @@ describe AppsController do @@ -19,115 +17,122 @@ describe AppsController do
19 17
20 describe "GET /apps/:id" do 18 describe "GET /apps/:id" do
21 it 'finds the app' do 19 it 'finds the app' do
  20 + sign_in Factory(:user)
22 app = Factory(:app) 21 app = Factory(:app)
23 get :show, :id => app.id 22 get :show, :id => app.id
24 assigns(:app).should == app 23 assigns(:app).should == app
25 end 24 end
26 end 25 end
27 26
28 - describe "GET /apps/new" do  
29 - it 'instantiates a new app with a prebuilt watcher' do  
30 - get :new  
31 - assigns(:app).should be_a(App)  
32 - assigns(:app).should be_new_record  
33 - assigns(:app).watchers.should_not be_empty 27 + context 'logged in as an admin' do
  28 + before do
  29 + sign_in Factory(:admin)
34 end 30 end
35 - end  
36 31
37 - describe "GET /apps/:id/edit" do  
38 - it 'finds the correct app' do  
39 - app = Factory(:app)  
40 - get :edit, :id => app.id  
41 - assigns(:app).should == app 32 + describe "GET /apps/new" do
  33 + it 'instantiates a new app with a prebuilt watcher' do
  34 + get :new
  35 + assigns(:app).should be_a(App)
  36 + assigns(:app).should be_new_record
  37 + assigns(:app).watchers.should_not be_empty
  38 + end
42 end 39 end
43 - end  
44 40
45 - describe "POST /apps" do  
46 - before do  
47 - @app = Factory(:app)  
48 - App.stub(:new).and_return(@app) 41 + describe "GET /apps/:id/edit" do
  42 + it 'finds the correct app' do
  43 + app = Factory(:app)
  44 + get :edit, :id => app.id
  45 + assigns(:app).should == app
  46 + end
49 end 47 end
50 -  
51 - context "when the create is successful" do 48 +
  49 + describe "POST /apps" do
52 before do 50 before do
53 - @app.should_receive(:save).and_return(true) 51 + @app = Factory(:app)
  52 + App.stub(:new).and_return(@app)
54 end 53 end
  54 +
  55 + context "when the create is successful" do
  56 + before do
  57 + @app.should_receive(:save).and_return(true)
  58 + end
55 59
56 - it "should redirect to the app page" do  
57 - post :create, :app => {}  
58 - response.should redirect_to(app_path(@app))  
59 - end 60 + it "should redirect to the app page" do
  61 + post :create, :app => {}
  62 + response.should redirect_to(app_path(@app))
  63 + end
60 64
61 - it "should display a message" do  
62 - post :create, :app => {}  
63 - request.flash[:success].should match(/success/) 65 + it "should display a message" do
  66 + post :create, :app => {}
  67 + request.flash[:success].should match(/success/)
  68 + end
64 end 69 end
65 - end  
66 70
67 - context "when the create is unsuccessful" do  
68 - it "should render the new page" do  
69 - @app.should_receive(:save).and_return(false)  
70 - post :create, :app => {}  
71 - response.should render_template(:new) 71 + context "when the create is unsuccessful" do
  72 + it "should render the new page" do
  73 + @app.should_receive(:save).and_return(false)
  74 + post :create, :app => {}
  75 + response.should render_template(:new)
  76 + end
72 end 77 end
73 end 78 end
74 - end  
75 79
76 - describe "PUT /apps/:id" do  
77 - before do  
78 - @app = Factory(:app)  
79 - App.stub(:find).with(@app.id).and_return(@app)  
80 - end  
81 -  
82 - context "when the update is successful" do 80 + describe "PUT /apps/:id" do
83 before do 81 before do
84 - @app.should_receive(:update_attributes).and_return(true) 82 + @app = Factory(:app)
  83 + App.stub(:find).with(@app.id).and_return(@app)
85 end 84 end
  85 +
  86 + context "when the update is successful" do
  87 + before do
  88 + @app.should_receive(:update_attributes).and_return(true)
  89 + end
86 90
87 - it "should redirect to the app page" do  
88 - put :update, :id => @app.id, :app => {}  
89 - response.should redirect_to(app_path(@app))  
90 - end 91 + it "should redirect to the app page" do
  92 + put :update, :id => @app.id, :app => {}
  93 + response.should redirect_to(app_path(@app))
  94 + end
91 95
92 - it "should display a message" do  
93 - put :update, :id => @app.id, :app => {}  
94 - request.flash[:success].should match(/success/) 96 + it "should display a message" do
  97 + put :update, :id => @app.id, :app => {}
  98 + request.flash[:success].should match(/success/)
  99 + end
95 end 100 end
96 - end  
97 101
98 - context "when the update is unsuccessful" do  
99 - it "should render the edit page" do  
100 - @app.should_receive(:update_attributes).and_return(false)  
101 - put :update, :id => @app.id, :app => {}  
102 - response.should render_template(:edit) 102 + context "when the update is unsuccessful" do
  103 + it "should render the edit page" do
  104 + @app.should_receive(:update_attributes).and_return(false)
  105 + put :update, :id => @app.id, :app => {}
  106 + response.should render_template(:edit)
  107 + end
103 end 108 end
104 end 109 end
105 - end  
106 110
107 - describe "DELETE /apps/:id" do  
108 - before do  
109 - @app = Factory(:app)  
110 - App.stub(:find).with(@app.id).and_return(@app)  
111 - end 111 + describe "DELETE /apps/:id" do
  112 + before do
  113 + @app = Factory(:app)
  114 + App.stub(:find).with(@app.id).and_return(@app)
  115 + end
112 116
113 - it "should find the app" do  
114 - delete :destroy, :id => @app.id  
115 - assigns(:app).should == @app  
116 - end 117 + it "should find the app" do
  118 + delete :destroy, :id => @app.id
  119 + assigns(:app).should == @app
  120 + end
117 121
118 - it "should destroy the app" do  
119 - @app.should_receive(:destroy)  
120 - delete :destroy, :id => @app.id  
121 - end 122 + it "should destroy the app" do
  123 + @app.should_receive(:destroy)
  124 + delete :destroy, :id => @app.id
  125 + end
122 126
123 - it "should display a message" do  
124 - delete :destroy, :id => @app.id  
125 - request.flash[:success].should match(/success/)  
126 - end 127 + it "should display a message" do
  128 + delete :destroy, :id => @app.id
  129 + request.flash[:success].should match(/success/)
  130 + end
127 131
128 - it "should redirect to the apps page" do  
129 - delete :destroy, :id => @app.id  
130 - response.should redirect_to(apps_path) 132 + it "should redirect to the apps page" do
  133 + delete :destroy, :id => @app.id
  134 + response.should redirect_to(apps_path)
  135 + end
131 end 136 end
132 end 137 end
133 138
spec/controllers/users_controller_spec.rb
@@ -3,7 +3,7 @@ require &#39;spec_helper&#39; @@ -3,7 +3,7 @@ require &#39;spec_helper&#39;
3 describe UsersController do 3 describe UsersController do
4 4
5 it_requires_authentication 5 it_requires_authentication
6 - it_requires_admin 6 + it_requires_admin_privileges
7 7
8 context 'Signed in as an admin' do 8 context 'Signed in as an admin' do
9 before do 9 before do
spec/support/macros.rb
@@ -27,7 +27,7 @@ def it_requires_authentication(options = {}) @@ -27,7 +27,7 @@ def it_requires_authentication(options = {})
27 end 27 end
28 end 28 end
29 29
30 -def it_requires_admin(options = {}) 30 +def it_requires_admin_privileges(options = {})
31 default_options = { 31 default_options = {
32 :for => { 32 :for => {
33 :index => :get, 33 :index => :get,