Commit 3977fd27618d606d64c1c237567d19429997a51b
1 parent
a5cf65d0
Exists in
master
and in
1 other branch
Add full management controls for users.
Showing
10 changed files
with
178 additions
and
5 deletions
Show diff stats
README.md
... | ... | @@ -6,4 +6,12 @@ Installation |
6 | 6 | |
7 | 7 | 1. Install MongoDB |
8 | 8 | 2. Install & Run Bundler |
9 | -3. Seed DB - rake db:seed | |
10 | 9 | \ No newline at end of file |
10 | +3. Seed DB - rake db:seed | |
11 | + | |
12 | +TODO | |
13 | +---- | |
14 | + | |
15 | +Add capistrano | |
16 | +Add form.error_messages | |
17 | +Add a deployment view | |
18 | +Add ability for watchers to be configured for types of notifications they should receive | |
11 | 19 | \ No newline at end of file | ... | ... |
app/controllers/application_controller.rb
app/controllers/users_controller.rb
1 | 1 | class UsersController < ApplicationController |
2 | 2 | respond_to :html |
3 | 3 | |
4 | - before_filter :authenticate_admin! | |
4 | + before_filter :require_admin! | |
5 | 5 | |
6 | 6 | def index |
7 | 7 | @users = User.paginate(:page => params[:page]) |
... | ... | @@ -12,18 +12,47 @@ class UsersController < ApplicationController |
12 | 12 | end |
13 | 13 | |
14 | 14 | def new |
15 | + @user = User.new | |
15 | 16 | end |
16 | 17 | |
17 | 18 | def edit |
19 | + @user = User.find(params[:id]) | |
18 | 20 | end |
19 | 21 | |
20 | 22 | def create |
23 | + @user = User.new(params[:user]) | |
24 | + | |
25 | + if @user.save | |
26 | + flash[:success] = "#{@user.name} is now part of the team. Be sure to add them as a project watcher." | |
27 | + redirect_to user_path(@user) | |
28 | + else | |
29 | + render :new | |
30 | + end | |
21 | 31 | end |
22 | 32 | |
23 | 33 | def update |
34 | + # Devise Hack | |
35 | + if params[:user][:password].blank? && params[:user][:password_confirmation].blank? | |
36 | + params[:user].delete(:password) | |
37 | + params[:user].delete(:password_confirmation) | |
38 | + end | |
39 | + | |
40 | + @user = User.find(params[:id]) | |
41 | + | |
42 | + if @user.update_attributes(params[:user]) | |
43 | + flash[:success] = "#{@user.name}'s information was successfully updated" | |
44 | + redirect_to user_path(@user) | |
45 | + else | |
46 | + render :edit | |
47 | + end | |
24 | 48 | end |
25 | 49 | |
26 | 50 | def destroy |
51 | + @user = User.find(params[:id]) | |
52 | + @user.destroy | |
53 | + | |
54 | + flash[:notice] = "That's sad. #{@user.name} is no longer part of your team." | |
55 | + redirect_to users_path | |
27 | 56 | end |
28 | 57 | |
29 | 58 | end | ... | ... |
app/models/user.rb
... | ... | @@ -0,0 +1,19 @@ |
1 | +.required | |
2 | + = f.label :name | |
3 | + = f.text_field :name | |
4 | + | |
5 | +.required | |
6 | + = f.label :email | |
7 | + = f.text_field :email | |
8 | + | |
9 | +.required | |
10 | + = f.label :password | |
11 | + = f.password_field :password | |
12 | + | |
13 | +.required | |
14 | + = f.label :password_confirmation | |
15 | + = f.password_field :password_confirmation | |
16 | + | |
17 | +.checkbox | |
18 | + = f.check_box :admin | |
19 | + = f.label :admin, 'Admin?' | |
0 | 20 | \ No newline at end of file | ... | ... |
spec/controllers/deploys_controller_spec.rb
... | ... | @@ -30,7 +30,7 @@ describe DeploysController do |
30 | 30 | post :create, :deploy => @params, :api_key => 'APIKEY' |
31 | 31 | end |
32 | 32 | |
33 | - it 'sends an email notification', :focused => true do | |
33 | + it 'sends an email notification' do | |
34 | 34 | post :create, :deploy => @params, :api_key => 'APIKEY' |
35 | 35 | email = ActionMailer::Base.deliveries.last |
36 | 36 | email.to.should include(@app.watchers.first.email) | ... | ... |
spec/controllers/users_controller_spec.rb
... | ... | @@ -26,5 +26,105 @@ describe UsersController do |
26 | 26 | assigns(:user).should == user |
27 | 27 | end |
28 | 28 | end |
29 | + | |
30 | + context "GET /users/new" do | |
31 | + it 'assigns a new user' do | |
32 | + get :new | |
33 | + assigns(:user).should be_a(User) | |
34 | + assigns(:user).should be_new_record | |
35 | + end | |
36 | + end | |
37 | + | |
38 | + context "GET /users/:id/edit" do | |
39 | + it 'finds the user' do | |
40 | + user = Factory(:user) | |
41 | + get :edit, :id => user.id | |
42 | + assigns(:user).should == user | |
43 | + end | |
44 | + end | |
45 | + | |
46 | + context "POST /users" do | |
47 | + context "when the create is successful" do | |
48 | + before do | |
49 | + @user = Factory(:user) | |
50 | + User.should_receive(:new).and_return(@user) | |
51 | + @user.should_receive(:save).and_return(true) | |
52 | + end | |
53 | + | |
54 | + it "sets a message to display" do | |
55 | + post :create | |
56 | + request.flash[:success].should include('part of the team') | |
57 | + end | |
58 | + | |
59 | + it "redirects to the user's page" do | |
60 | + post :create | |
61 | + response.should redirect_to(user_path(@user)) | |
62 | + end | |
63 | + end | |
64 | + | |
65 | + context "when the create is unsuccessful" do | |
66 | + before do | |
67 | + @user = Factory(:user) | |
68 | + User.should_receive(:new).and_return(@user) | |
69 | + @user.should_receive(:save).and_return(false) | |
70 | + end | |
71 | + | |
72 | + it "renders the new page" do | |
73 | + post :create | |
74 | + response.should render_template(:new) | |
75 | + end | |
76 | + end | |
77 | + end | |
78 | + | |
79 | + context "PUT /users/:id" do | |
80 | + context "when the update is successful" do | |
81 | + before do | |
82 | + @user = Factory(:user) | |
83 | + end | |
84 | + | |
85 | + it "sets a message to display" do | |
86 | + put :update, :id => @user.to_param, :user => {:name => 'Kermit'} | |
87 | + request.flash[:success].should include('updated') | |
88 | + end | |
89 | + | |
90 | + it "redirects to the user's page" do | |
91 | + put :update, :id => @user.to_param, :user => {:name => 'Kermit'} | |
92 | + response.should redirect_to(user_path(@user)) | |
93 | + end | |
94 | + end | |
95 | + | |
96 | + context "when the update is unsuccessful" do | |
97 | + before do | |
98 | + @user = Factory(:user) | |
99 | + end | |
100 | + | |
101 | + it "renders the edit page" do | |
102 | + put :update, :id => @user.to_param, :user => {:name => nil} | |
103 | + response.should render_template(:edit) | |
104 | + end | |
105 | + end | |
106 | + end | |
107 | + | |
108 | + context "DELETE /users/:id" do | |
109 | + before do | |
110 | + @user = Factory(:user) | |
111 | + end | |
112 | + | |
113 | + it "destroys the user" do | |
114 | + delete :destroy, :id => @user.id | |
115 | + User.where(:id => @user.id).first.should be_nil | |
116 | + end | |
117 | + | |
118 | + it "redirects to the users index page" do | |
119 | + delete :destroy, :id => @user.id | |
120 | + response.should redirect_to(users_path) | |
121 | + end | |
122 | + | |
123 | + it "sets a message to display" do | |
124 | + delete :destroy, :id => @user.id | |
125 | + request.flash[:notice].should include('no longer part of your team') | |
126 | + end | |
127 | + end | |
128 | + | |
29 | 129 | end |
30 | 130 | end | ... | ... |
spec/spec_helper.rb
... | ... | @@ -13,6 +13,10 @@ RSpec.configure do |config| |
13 | 13 | config.mock_with :rspec |
14 | 14 | config.include Devise::TestHelpers, :type => :controller |
15 | 15 | |
16 | + config.filter_run :focused => true | |
17 | + config.run_all_when_everything_filtered = true | |
18 | + config.alias_example_to :fit, :focused => true | |
19 | + | |
16 | 20 | config.before(:each) do |
17 | 21 | DatabaseCleaner.orm = "mongoid" |
18 | 22 | DatabaseCleaner.strategy = :truncation | ... | ... |