user controller test
This commit is contained in:
parent
b5782b13d8
commit
6248e1211a
|
@ -1,9 +1,9 @@
|
||||||
# quickpay_user GET /users/:id/quickpay(.:format) users#quickpay
|
# quickpay_user GET /users/:id/quickpay(.:format) users#quickpay
|
||||||
# edit_dagschotel_user GET /users/:id/dagschotel/edit(.:format) users#edit_dagschotel
|
# edit_dagschotel_user GET /users/:id/dagschotel/edit(.:format) users#edit_dagschotel
|
||||||
# edit_user GET /users/:id/edit(.:format) users#edit
|
# edit_user GET /users/:id/edit(.:format) users#edit
|
||||||
# user GET /users/:id(.:format) users#show
|
# user GET /users/:id(.:format) users#show
|
||||||
# PATCH /users/:id(.:format) users#update
|
# PATCH /users/:id(.:format) users#update
|
||||||
# PUT /users/:id(.:format) users#update
|
# PUT /users/:id(.:format) users#update
|
||||||
#
|
#
|
||||||
|
|
||||||
describe UsersController, type: :controller do
|
describe UsersController, type: :controller do
|
||||||
|
@ -22,10 +22,13 @@ describe UsersController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should be successful' do
|
it 'should be successful' do
|
||||||
expect(response).to render_template(:show)
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should render the user' do
|
||||||
|
expect(response).to render_template(:show)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should load the correct user' do
|
it 'should load the correct user' do
|
||||||
expect(assigns(:user)).to eq(@user)
|
expect(assigns(:user)).to eq(@user)
|
||||||
end
|
end
|
||||||
|
@ -40,6 +43,10 @@ describe UsersController, type: :controller do
|
||||||
get :edit, id: @user
|
get :edit, id: @user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should be successful' do
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should render the form' do
|
it 'should render the form' do
|
||||||
expect(response).to render_template(:edit)
|
expect(response).to render_template(:edit)
|
||||||
end
|
end
|
||||||
|
@ -79,10 +86,73 @@ describe UsersController, type: :controller do
|
||||||
#####################
|
#####################
|
||||||
|
|
||||||
describe 'GET edit_dagschotel' do
|
describe 'GET edit_dagschotel' do
|
||||||
|
it 'should be successful' do
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should render the page' do
|
it 'should render the page' do
|
||||||
get :edit_dagschotel, id: @user
|
get :edit_dagschotel, id: @user
|
||||||
expect(response).to render_template(:edit_dagschotel)
|
expect(response).to render_template(:edit_dagschotel)
|
||||||
expect(response).to have_http_status(200)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
##############
|
||||||
|
# QUICKPAY #
|
||||||
|
##############
|
||||||
|
|
||||||
|
describe 'GET quickpay' do
|
||||||
|
describe 'successful' do
|
||||||
|
before :each do
|
||||||
|
@dagschotel = create :product, stock: 20
|
||||||
|
@user.update_attribute(:dagschotel, @dagschotel)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be successful' do
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should make an order' do
|
||||||
|
expect{
|
||||||
|
get :quickpay, id: @user
|
||||||
|
}.to change{ @user.reload.orders_count }.by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'order' do
|
||||||
|
before :each do
|
||||||
|
get :quickpay, id: @user
|
||||||
|
@order = @user.orders.last
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should contain 1 orderitem' do
|
||||||
|
expect(@order.order_items.size).to eq 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should have an orderitem with count 1' do
|
||||||
|
expect(@order.order_items.first.count).to eq 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should contain an orderitem for @dagschotel' do
|
||||||
|
expect(@order.order_items.first.product).to eq @dagschotel
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'failed' do
|
||||||
|
before :each do
|
||||||
|
@dagschotel = create :product, stock: 0
|
||||||
|
@user.update_attribute(:dagschotel, @dagschotel)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail' do
|
||||||
|
get :quickpay, id: @user
|
||||||
|
expect(response).to have_http_status(302)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not make an order' do
|
||||||
|
expect{
|
||||||
|
get :quickpay, id: @user
|
||||||
|
}.to_not change{ @user.reload.orders_count }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue