Commit 9558cd2ab8c93921362cb640d05c679a7ff6aabe
1 parent
31e67669
Exists in
master
and in
1 other branch
Add Users#index and Users#show pages
Showing
10 changed files
with
136 additions
and
5 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -0,0 +1,29 @@ |
1 | +class UsersController < ApplicationController | |
2 | + respond_to :html | |
3 | + | |
4 | + before_filter :authenticate_admin! | |
5 | + | |
6 | + def index | |
7 | + @users = User.paginate(:page => params[:page]) | |
8 | + end | |
9 | + | |
10 | + def show | |
11 | + @user = User.find(params[:id]) | |
12 | + end | |
13 | + | |
14 | + def new | |
15 | + end | |
16 | + | |
17 | + def edit | |
18 | + end | |
19 | + | |
20 | + def create | |
21 | + end | |
22 | + | |
23 | + def update | |
24 | + end | |
25 | + | |
26 | + def destroy | |
27 | + end | |
28 | + | |
29 | +end | ... | ... |
app/models/user.rb
1 | 1 | class User |
2 | 2 | include Mongoid::Document |
3 | + include Mongoid::Timestamps | |
3 | 4 | |
4 | 5 | devise :database_authenticatable, |
5 | 6 | :recoverable, :rememberable, :trackable, |
... | ... | @@ -7,6 +8,7 @@ class User |
7 | 8 | |
8 | 9 | field :name |
9 | 10 | field :admin, :type => Boolean, :default => false |
11 | + key :name | |
10 | 12 | |
11 | 13 | validates_presence_of :name |
12 | 14 | ... | ... |
app/views/shared/_navigation.html.haml
1 | 1 | #nav-bar |
2 | 2 | %ul |
3 | 3 | //%li= link_to 'Dashboard', admin_dashboard_path, :class => active_if_here(:dashboards) |
4 | - %li.apps{:class => active_if_here(:apps)}= link_to 'Apps', apps_path | |
5 | - %li.errs{:class => active_if_here(:errs)}= link_to 'Errs', errs_path | |
4 | + %li.apps{:class => active_if_here(:apps)}= link_to 'Apps', apps_path | |
5 | + %li.errs{:class => active_if_here(:errs)}= link_to 'Errs', errs_path | |
6 | + %li.users{:class => active_if_here(:users)}= link_to 'Users', users_path | |
6 | 7 | %div.clear |
7 | 8 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +- content_for :title, 'Users' | |
2 | + | |
3 | +%table | |
4 | + %thead | |
5 | + %tr | |
6 | + %th Name | |
7 | + %th.main Email | |
8 | + %th Admin? | |
9 | + %tbody | |
10 | + - @users.each do |user| | |
11 | + %tr | |
12 | + %td.nowrap= link_to user.name, user_path(user) | |
13 | + %td= user.email | |
14 | + %td= user.admin? ? 'Y' : 'N' | |
15 | += will_paginate @users, :previous_label => '« Previous', :next_label => 'Next »' | |
16 | + | |
0 | 17 | \ No newline at end of file | ... | ... |
config/routes.rb
... | ... | @@ -6,13 +6,14 @@ Errbit::Application.routes.draw do |
6 | 6 | match '/notifier_api/v2/notices' => 'notices#create' |
7 | 7 | match '/deploys.txt' => 'deploys#create' |
8 | 8 | |
9 | + resources :notices, :only => [:show] | |
10 | + resources :deploys, :only => [:show] | |
11 | + resources :users | |
9 | 12 | resources :errs, :only => [:index] do |
10 | 13 | collection do |
11 | 14 | get :all |
12 | 15 | end |
13 | 16 | end |
14 | - resources :notices, :only => [:show] | |
15 | - resources :deploys, :only => [:show] | |
16 | 17 | |
17 | 18 | resources :apps do |
18 | 19 | resources :errs do | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe UsersController do | |
4 | + | |
5 | + it_requires_authentication | |
6 | + it_requires_admin | |
7 | + | |
8 | + context 'Signed in as an admin' do | |
9 | + before do | |
10 | + sign_in Factory(:admin) | |
11 | + end | |
12 | + | |
13 | + context "GET /users" do | |
14 | + it 'paginates all users' do | |
15 | + users = 3.times.inject(WillPaginate::Collection.new(1,30)) {|page,_| page << Factory.build(:user)} | |
16 | + User.should_receive(:paginate).and_return(users) | |
17 | + get :index | |
18 | + assigns(:users).should == users | |
19 | + end | |
20 | + end | |
21 | + | |
22 | + context "GET /users/:id" do | |
23 | + it 'finds the user' do | |
24 | + user = Factory(:user) | |
25 | + get :show, :id => user.id | |
26 | + assigns(:user).should == user | |
27 | + end | |
28 | + end | |
29 | + end | |
30 | +end | ... | ... |
spec/factories/user_factories.rb
spec/support/macros.rb
... | ... | @@ -13,7 +13,7 @@ def it_requires_authentication(options = {}) |
13 | 13 | } |
14 | 14 | options.reverse_merge!(default_options) |
15 | 15 | |
16 | - context 'when logged out' do | |
16 | + context 'when signed out' do | |
17 | 17 | before do |
18 | 18 | sign_out :user |
19 | 19 | end |
... | ... | @@ -25,4 +25,34 @@ def it_requires_authentication(options = {}) |
25 | 25 | end |
26 | 26 | end |
27 | 27 | end |
28 | +end | |
29 | + | |
30 | +def it_requires_admin(options = {}) | |
31 | + default_options = { | |
32 | + :for => { | |
33 | + :index => :get, | |
34 | + :show => :get, | |
35 | + :new => :get, | |
36 | + :create => :post, | |
37 | + :edit => :get, | |
38 | + :update => :put, | |
39 | + :destroy => :delete | |
40 | + }, | |
41 | + :params => {:id => 'dummyid'} | |
42 | + } | |
43 | + options.reverse_merge!(default_options) | |
44 | + | |
45 | + context 'when signed in as a regular user' do | |
46 | + before do | |
47 | + sign_out :user | |
48 | + sign_in Factory(:user) | |
49 | + end | |
50 | + | |
51 | + options[:for].each do |action, method| | |
52 | + it "#{method.to_s.upcase} #{action} redirects to the root path" do | |
53 | + send(method, action, options[:params]) | |
54 | + response.should redirect_to(root_path) | |
55 | + end | |
56 | + end | |
57 | + end | |
28 | 58 | end |
29 | 59 | \ No newline at end of file | ... | ... |