Skip to content

Commit

Permalink
#17 Admin user list fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhanoguzhan committed Aug 29, 2013
1 parent 1ff74df commit bba795a
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 45 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ gem 'haml-rails'
gem 'bootstrap-sass', :git => 'git://github.com/thomas-mcdonald/bootstrap-sass.git', :branch => '3'
gem 'simple_form', "3.0.0.rc"
gem 'country_select'
gem "datagrid", :git => "git://github.com/bogdan/datagrid.git"
gem 'will_paginate', '~> 3.0'

# Use ActiveModel has_secure_password
Expand Down
8 changes: 0 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
GIT
remote: git://github.com/bogdan/datagrid.git
revision: bab159913f1666f9c5247a01578a5aaa959aa32c
specs:
datagrid (0.9.3)
rails (>= 3.0)

GIT
remote: git://github.com/thomas-mcdonald/bootstrap-sass.git
revision: a71f09a26b2d6a56a70a2cdf26110434cd3fbdf8
Expand Down Expand Up @@ -147,7 +140,6 @@ DEPENDENCIES
bootstrap-sass!
coffee-rails (~> 4.0.0)
country_select
datagrid!
devise
haml (~> 4.0.2)
haml-rails
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ def index
end

def admin
@grid = Grids::UsersGrid.new(params[:grid])
@assets = @grid.assets.paginate(:page => params[:page])
@users = User.all
end

def user
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module UsersHelper
end
5 changes: 0 additions & 5 deletions app/models/grids.rb

This file was deleted.

23 changes: 0 additions & 23 deletions app/models/grids/users_grid.rb

This file was deleted.

26 changes: 23 additions & 3 deletions app/views/home/admin.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
.h1
Admin Home

%div== Total #{@assets.total_entries}
= datagrid_table(@grid, @assets, :html => {:class => "table table-hover"})
= will_paginate @assets
%h1 Listing users

%table
%tr
%th email
%th created_at
%th updated_at
%th
%th
%th

- @users.each do |user|
%tr
%td= user.email
%td=l user.created_at
%td=l user.updated_at
%td= link_to 'Show', user
%td= link_to 'Edit', edit_user_path(user)
%td= link_to 'Destroy', user, :method => :delete, :data => { :confirm => 'Are you sure?' }

%br

= link_to 'New User', new_user_path
7 changes: 7 additions & 0 deletions app/views/users/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= simple_form_for(@user) do |f|
= f.error_notification

.form-inputs

.form-actions
= f.button :submit
7 changes: 7 additions & 0 deletions app/views/users/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%h1 Editing user

= render 'form'

= link_to 'Show', @user
\|
= link_to 'Back', users_path
3 changes: 0 additions & 3 deletions app/views/users/index.html.haml

This file was deleted.

4 changes: 4 additions & 0 deletions app/views/users/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
json.array!(@users) do |user|
json.extract! user,
json.url user_url(user, format: :json)
end
5 changes: 5 additions & 0 deletions app/views/users/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%h1 New user

= render 'form'

= link_to 'Back', users_path
Empty file removed app/views/users/show.html.erb
Empty file.
6 changes: 6 additions & 0 deletions app/views/users/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%p#notice= notice


= link_to 'Edit', edit_user_path(@user)
\|
= link_to 'Back', users_path
1 change: 1 addition & 0 deletions app/views/users/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.extract! @user, :created_at, :updated_at
49 changes: 49 additions & 0 deletions test/controllers/users_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
require 'test_helper'

class UsersControllerTest < ActionController::TestCase
setup do
@user = users(:one)
end

test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:users)
end

test "should get new" do
get :new
assert_response :success
end

test "should create user" do
assert_difference('User.count') do
post :create, user: { }
end

assert_redirected_to user_path(assigns(:user))
end

test "should show user" do
get :show, id: @user
assert_response :success
end

test "should get edit" do
get :edit, id: @user
assert_response :success
end

test "should update user" do
patch :update, id: @user, user: { }
assert_redirected_to user_path(assigns(:user))
end

test "should destroy user" do
assert_difference('User.count', -1) do
delete :destroy, id: @user
end

assert_redirected_to users_path
end
end
4 changes: 4 additions & 0 deletions test/helpers/users_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class UsersHelperTest < ActionView::TestCase
end

0 comments on commit bba795a

Please sign in to comment.