Merge d50fd3cc23 into adfa9cc871
This commit is contained in:
commit
d2f14a1962
10 changed files with 78 additions and 16 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,
|
||||||
|
|
|
||||||
22
spec/controllers/admin/users_controller_spec.rb
Normal file
22
spec/controllers/admin/users_controller_spec.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Admin::UsersController do
|
||||||
|
before(:each) do
|
||||||
|
@user = create(:user)
|
||||||
|
@admin = create(:admin)
|
||||||
|
sign_in(@admin)
|
||||||
|
end
|
||||||
|
describe "GET '#index'" do
|
||||||
|
it 'populates an array of users' do
|
||||||
|
user1 = create(:user, email: "gopesh.7500@gmail.com")
|
||||||
|
user2 = create(:user, email: "gopesh@gmail.com")
|
||||||
|
get :index
|
||||||
|
expect(assigns(:users)).to match_array([@user,@admin,user1,user2])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders index template' do
|
||||||
|
get :index
|
||||||
|
expect(response).to render_template :index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -2,9 +2,16 @@
|
||||||
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
factory :admin, class: User do
|
||||||
|
sequence(:email) { |n| 'gopesh#{n}@exampleco.in' }
|
||||||
|
password 'changeme'
|
||||||
|
password_confirmation 'changeme'
|
||||||
|
confirmed_at Time.now
|
||||||
|
after(:create) { |user| user.role_ids = [3] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ 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'
|
||||||
|
ActiveRecord::Migration.maintain_test_schema!
|
||||||
# Requires supporting ruby files with custom matchers and macros, etc, in
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
||||||
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
||||||
# run as spec files by default. This means that files in spec/support that end
|
# run as spec files by default. This means that files in spec/support that end
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
21
spec/support/database_cleaner.rb
Normal file
21
spec/support/database_cleaner.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
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
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
FactoryGirl.lint
|
FactoryGirl.lint
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
config.before(:suite) do
|
||||||
config.before(:suite) do
|
|
||||||
load "#{Rails.root}/db/seeds.rb"
|
load "#{Rails.root}/db/seeds.rb"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
9
spec/support/sign_in_macros.rb
Normal file
9
spec/support/sign_in_macros.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue