users controller test
This commit is contained in:
parent
e8f4fe6849
commit
0885359d71
|
@ -25,14 +25,6 @@ class UsersController < ApplicationController
|
||||||
@categories = Product.categories
|
@categories = Product.categories
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_dagschotel
|
|
||||||
@user.dagschotel = Product.find(params[:product_id])
|
|
||||||
@user.save
|
|
||||||
|
|
||||||
flash[:success] = "Succesfully updated dagschotel"
|
|
||||||
redirect_to @user
|
|
||||||
end
|
|
||||||
|
|
||||||
def quickpay
|
def quickpay
|
||||||
order = @user.orders.build
|
order = @user.orders.build
|
||||||
order.order_items.build(count: 1, product: @user.dagschotel)
|
order.order_items.build(count: 1, product: @user.dagschotel)
|
||||||
|
@ -47,7 +39,7 @@ class UsersController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def user_params
|
def user_params
|
||||||
params.require(:user).permit(:avatar, :private)
|
params.require(:user).permit(:avatar, :private, :dagschotel_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def init
|
def init
|
||||||
|
|
|
@ -29,6 +29,8 @@ class User < ActiveRecord::Base
|
||||||
has_many :products, through: :orders
|
has_many :products, through: :orders
|
||||||
belongs_to :dagschotel, class_name: 'Product'
|
belongs_to :dagschotel, class_name: 'Product'
|
||||||
|
|
||||||
|
validates :dagschotel, presence: true, if: -> { dagschotel_id }
|
||||||
|
|
||||||
scope :members, -> { where koelkast: false }
|
scope :members, -> { where koelkast: false }
|
||||||
scope :publik, -> { where private: false }
|
scope :publik, -> { where private: false }
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
- if controller_name == 'products' && current_user && current_user.admin?
|
- if controller_name == 'products' && can?(:manage, Product)
|
||||||
= link_to "Edit", edit_product_path(product), class: "btn btn-default"
|
= link_to "Edit", edit_product_path(product), class: "btn btn-default"
|
||||||
= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'}
|
= link_to "Delete", product_path(product), method: :delete, class: "btn btn-danger", data: {confirm: 'Are you sure?'}
|
||||||
- if controller_name == 'users'
|
- if controller_name == 'users'
|
||||||
.product_dagschotel
|
.product_dagschotel
|
||||||
- if current_user.dagschotel != product
|
- if current_user.dagschotel != product
|
||||||
= link_to "Make dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-default"
|
= button_to "Make dagschotel", { controller: 'users', action: 'update', "user[dagschotel_id]" => product.id }, method: :put, class: "btn btn-default"
|
||||||
- else
|
- else
|
||||||
= link_to "Huidige dagschotel", dagschotel_user_path(current_user, product), class: "btn btn-success", disabled: true
|
%span.btn.btn-success= "Current dagschotel"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
.col-md-3
|
.col-md-3
|
||||||
.thumbnail.pic
|
.thumbnail.pic
|
||||||
.form_row_image
|
.center
|
||||||
= image_tag product.avatar
|
= image_tag product.avatar
|
||||||
.caption
|
.caption
|
||||||
= kcal_tag product.calories
|
= kcal_tag product.calories
|
||||||
|
|
|
@ -20,9 +20,8 @@ Rails.application.routes.draw do
|
||||||
resources :users, only: [:show, :edit, :update] do
|
resources :users, only: [:show, :edit, :update] do
|
||||||
resources :orders, only: [:new, :create, :destroy]
|
resources :orders, only: [:new, :create, :destroy]
|
||||||
member do
|
member do
|
||||||
get 'quickpay' => 'users#quickpay'
|
get 'quickpay' => 'users#quickpay'
|
||||||
get 'dagschotel/edit' => 'users#edit_dagschotel', as: 'edit_dagschotel'
|
get 'dagschotel/edit' => 'users#edit_dagschotel', as: 'edit_dagschotel'
|
||||||
get 'dagschotel/:product_id' => 'users#update_dagschotel', as: 'dagschotel'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
require 'identicon'
|
# quickpay_user GET /users/:id/quickpay(.:format) users#quickpay
|
||||||
require 'faker'
|
# edit_dagschotel_user GET /users/:id/dagschotel/edit(.:format) users#edit_dagschotel
|
||||||
|
# edit_user GET /users/:id/edit(.:format) users#edit
|
||||||
|
# user GET /users/:id(.:format) users#show
|
||||||
|
# PATCH /users/:id(.:format) users#update
|
||||||
|
# PUT /users/:id(.:format) users#update
|
||||||
|
#
|
||||||
|
|
||||||
describe UsersController, type: :controller do
|
describe UsersController, type: :controller do
|
||||||
before :each do
|
before :each do
|
||||||
|
@ -7,6 +12,10 @@ describe UsersController, type: :controller do
|
||||||
sign_in @user
|
sign_in @user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##########
|
||||||
|
# SHOW #
|
||||||
|
##########
|
||||||
|
|
||||||
describe 'GET show' do
|
describe 'GET show' do
|
||||||
before :each do
|
before :each do
|
||||||
get :show, id: @user
|
get :show, id: @user
|
||||||
|
@ -22,6 +31,10 @@ describe UsersController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##########
|
||||||
|
# EDIT #
|
||||||
|
##########
|
||||||
|
|
||||||
describe 'GET edit' do
|
describe 'GET edit' do
|
||||||
before :each do
|
before :each do
|
||||||
get :edit, id: @user
|
get :edit, id: @user
|
||||||
|
@ -36,6 +49,10 @@ describe UsersController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
############
|
||||||
|
# UPDATE #
|
||||||
|
############
|
||||||
|
|
||||||
describe 'PUT update' do
|
describe 'PUT update' do
|
||||||
it 'should load the correct user' do
|
it 'should load the correct user' do
|
||||||
put :update, id: @user, user: attributes_for(:user)
|
put :update, id: @user, user: attributes_for(:user)
|
||||||
|
@ -48,9 +65,19 @@ describe UsersController, type: :controller do
|
||||||
put :update, id: @user, user: { private: new_private }
|
put :update, id: @user, user: { private: new_private }
|
||||||
expect(@user.reload.private).to be new_private
|
expect(@user.reload.private).to be new_private
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should update dagschotel' do
|
||||||
|
product = create :product
|
||||||
|
put :update, id: @user, user: { dagschotel_id: product.id }
|
||||||
|
expect(@user.reload.dagschotel).to eq(product)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#####################
|
||||||
|
# EDIT_DAGSCHOTEL #
|
||||||
|
#####################
|
||||||
|
|
||||||
describe 'GET edit_dagschotel' do
|
describe 'GET edit_dagschotel' do
|
||||||
it 'should render the page' do
|
it 'should render the page' do
|
||||||
get :edit_dagschotel, id: @user
|
get :edit_dagschotel, id: @user
|
||||||
|
@ -58,12 +85,4 @@ describe UsersController, type: :controller do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET update_dagschotel' do
|
|
||||||
it 'should update the dagschotel' do
|
|
||||||
product = create :product
|
|
||||||
get :update_dagschotel, id: @user, product_id: product
|
|
||||||
expect(@user.reload.dagschotel).to eq(product)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue