Some tests for users controller, and fixed users#index
This commit is contained in:
parent
adfa9cc871
commit
4955481f14
9 changed files with 84 additions and 10 deletions
1
Gemfile
1
Gemfile
|
|
@ -76,6 +76,7 @@ group :development, :test do
|
||||||
gem 'rspec', '>= 3.0.0.beta'
|
gem 'rspec', '>= 3.0.0.beta'
|
||||||
gem 'rspec-rails', '>= 3.0.0.beta'
|
gem 'rspec-rails', '>= 3.0.0.beta'
|
||||||
gem 'capybara'
|
gem 'capybara'
|
||||||
|
gem 'database_cleaner'
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME: We should use http://weblog.rubyonrails.org/2012/3/21/strong-parameters/
|
# FIXME: We should use http://weblog.rubyonrails.org/2012/3/21/strong-parameters/
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ GEM
|
||||||
thor
|
thor
|
||||||
d3_rails (3.4.6)
|
d3_rails (3.4.6)
|
||||||
railties (>= 3.1.0)
|
railties (>= 3.1.0)
|
||||||
|
database_cleaner (1.2.0)
|
||||||
devise (3.2.4)
|
devise (3.2.4)
|
||||||
bcrypt (~> 3.0)
|
bcrypt (~> 3.0)
|
||||||
orm_adapter (~> 0.1)
|
orm_adapter (~> 0.1)
|
||||||
|
|
@ -305,6 +306,7 @@ DEPENDENCIES
|
||||||
cocoon
|
cocoon
|
||||||
coveralls
|
coveralls
|
||||||
d3_rails
|
d3_rails
|
||||||
|
database_cleaner
|
||||||
devise
|
devise
|
||||||
factory_girl_rails
|
factory_girl_rails
|
||||||
formtastic (~> 2.3.0.rc3)
|
formtastic (~> 2.3.0.rc3)
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ class Admin::UsersController < ApplicationController
|
||||||
before_filter :verify_admin
|
before_filter :verify_admin
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@users = User.all(:joins => :person,
|
@users = User.joins(:person).order("people.last_name ASC").select("users.*,
|
||||||
:order => "people.last_name ASC",
|
|
||||||
:select => "users.*,
|
|
||||||
people.last_name AS last_name,
|
people.last_name AS last_name,
|
||||||
people.first_name AS first_name,
|
people.first_name AS first_name,
|
||||||
people.public_name AS public_name,
|
people.public_name AS public_name,
|
||||||
|
|
|
||||||
34
spec/controllers/admin/users_controller_spec.rb
Normal file
34
spec/controllers/admin/users_controller_spec.rb
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Admin::UsersController do
|
||||||
|
shared_examples 'access as administration' do
|
||||||
|
describe "GET '#index'" do
|
||||||
|
it 'populates an array of users' do
|
||||||
|
user1,user2 = create(:user,email:"gopesh.7500@gmail.com"),create(:user,email:"gopesh@gmail.com")
|
||||||
|
get :index
|
||||||
|
expect(assigns(:users)).to match_array([user1,user2])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders index template' do
|
||||||
|
get :index
|
||||||
|
expect(response).to render_template :index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "PATCH '#update'" do
|
||||||
|
it 'locates the user' do
|
||||||
|
patch :update, id: @user.id, :user => {email:@user.email}
|
||||||
|
expect(assigns(:user)).to eq(@user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'admin access' do
|
||||||
|
before(:each) do
|
||||||
|
@user = create(:user)
|
||||||
|
@admin = create(:admin)
|
||||||
|
sign_in(@admin)
|
||||||
|
end
|
||||||
|
it_behaves_like 'access as administration'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :user do
|
factory :user do
|
||||||
email 'example@example.com'
|
sequence(:email) {|n|'name#{n}@example.com'}
|
||||||
password 'changeme'
|
password 'changeme'
|
||||||
password_confirmation 'changeme'
|
password_confirmation 'changeme'
|
||||||
confirmed_at Time.now
|
confirmed_at Time.now
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ Coveralls.wear!('rails')
|
||||||
ENV["RAILS_ENV"] ||= 'test'
|
ENV["RAILS_ENV"] ||= 'test'
|
||||||
require File.expand_path("../../config/environment", __FILE__)
|
require File.expand_path("../../config/environment", __FILE__)
|
||||||
|
|
||||||
if Rails.configuration.database_configuration['test']['database'] == ':memory:'
|
# if Rails.configuration.database_configuration['test']['database'] == ':memory:'
|
||||||
load "#{Rails.root}/db/schema.rb"
|
# load "#{Rails.root}/db/schema.rb"
|
||||||
load "#{Rails.root}/db/seeds.rb"
|
# load "#{Rails.root}/db/seeds.rb"
|
||||||
end
|
# end
|
||||||
|
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
|
|
||||||
|
|
@ -30,19 +30,25 @@ RSpec.configure do |config|
|
||||||
# config.mock_with :rr
|
# config.mock_with :rr
|
||||||
|
|
||||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||||
|
|
||||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||||
# examples within a transaction, remove the following line or assign false
|
# examples within a transaction, remove the following line or assign false
|
||||||
# instead of true.
|
# instead of true.
|
||||||
config.use_transactional_fixtures = true
|
config.use_transactional_fixtures = false
|
||||||
|
|
||||||
# Run specs in random order to surface order dependencies. If you find an
|
# Run specs in random order to surface order dependencies. If you find an
|
||||||
# order dependency and want to debug it, you can fix the order by providing
|
# order dependency and want to debug it, you can fix the order by providing
|
||||||
# the seed, which is printed after each run.
|
# the seed, which is printed after each run.
|
||||||
# --seed 1234
|
# --seed 1234
|
||||||
config.order = "random"
|
config.order = "random"
|
||||||
|
|
||||||
|
# Enables devise sign_in function
|
||||||
|
config.include Devise::TestHelpers, type: :controller
|
||||||
|
|
||||||
|
# Includes support/login_macros for feature tests
|
||||||
|
config.include SigninMacros, type: :feature
|
||||||
|
|
||||||
# Include factory_girls syntax
|
# Include factory_girls syntax
|
||||||
config.include FactoryGirl::Syntax::Methods
|
config.include FactoryGirl::Syntax::Methods
|
||||||
|
|
||||||
|
|
|
||||||
23
spec/support/database_cleaner.rb
Normal file
23
spec/support/database_cleaner.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
RSpec.configure do |config|
|
||||||
|
|
||||||
|
config.before(:suite) do
|
||||||
|
DatabaseCleaner.clean_with(:truncation)
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each) do
|
||||||
|
DatabaseCleaner.strategy = :transaction
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each, :js => true) do
|
||||||
|
DatabaseCleaner.strategy = :truncation
|
||||||
|
end
|
||||||
|
|
||||||
|
config.before(:each) do
|
||||||
|
DatabaseCleaner.start
|
||||||
|
end
|
||||||
|
|
||||||
|
config.after(:each) do
|
||||||
|
DatabaseCleaner.clean
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
10
spec/support/sigin_macros.rb
Normal file
10
spec/support/sigin_macros.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
module SigninMacros
|
||||||
|
def sign_in(user)
|
||||||
|
visit new_user_session_path
|
||||||
|
fill_in 'user_email', with:'user.email'
|
||||||
|
fill_in 'user_password', with: 'user.password'
|
||||||
|
click_button 'Sign in'
|
||||||
|
page.should have_content('Signed in successfully')
|
||||||
|
end
|
||||||
|
end
|
||||||
0
spec/support/signin_macros.rb
Normal file
0
spec/support/signin_macros.rb
Normal file
Loading…
Add table
Add a link
Reference in a new issue