Some basic tests for user controller index
This commit is contained in:
parent
4955481f14
commit
c97affca35
8 changed files with 31 additions and 38 deletions
|
|
@ -1,34 +1,27 @@
|
|||
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
|
||||
|
||||
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
|
||||
# pp response.body
|
||||
expect(assigns(:users)).to match_array([@user,@admin,user1,user2])
|
||||
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'
|
||||
it 'renders index template' do
|
||||
get :index
|
||||
# pp response.body
|
||||
expect(response).to render_template :index
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -7,4 +7,11 @@ FactoryGirl.define do
|
|||
password_confirmation 'changeme'
|
||||
confirmed_at Time.now
|
||||
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
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ require File.expand_path("../../config/environment", __FILE__)
|
|||
# end
|
||||
|
||||
require 'rspec/rails'
|
||||
|
||||
ActiveRecord::Migration.maintain_test_schema!
|
||||
# Requires supporting ruby files with custom matchers and macros, etc, in
|
||||
# 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
|
||||
|
|
@ -47,7 +47,7 @@ RSpec.configure do |config|
|
|||
config.include Devise::TestHelpers, type: :controller
|
||||
|
||||
# Includes support/login_macros for feature tests
|
||||
config.include SigninMacros, type: :feature
|
||||
config.include SignInMacros, type: :feature
|
||||
|
||||
# Include factory_girls syntax
|
||||
config.include FactoryGirl::Syntax::Methods
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
RSpec.configure do |config|
|
||||
|
||||
config.before(:suite) do
|
||||
DatabaseCleaner.clean_with(:truncation)
|
||||
end
|
||||
|
|
@ -19,5 +18,4 @@ RSpec.configure do |config|
|
|||
config.after(:each) do
|
||||
DatabaseCleaner.clean
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
RSpec.configure do |config|
|
||||
|
||||
config.before(:suite) do
|
||||
FactoryGirl.lint
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
RSpec.configure do |config|
|
||||
|
||||
config.before(:suite) do
|
||||
config.before(:suite) do
|
||||
load "#{Rails.root}/db/seeds.rb"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
module SigninMacros
|
||||
module SignInMacros
|
||||
def sign_in(user)
|
||||
visit new_user_session_path
|
||||
fill_in 'user_email', with:'user.email'
|
||||
Loading…
Add table
Add a link
Reference in a new issue