2014-12-04 19:50:02 +01:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: users
|
|
|
|
#
|
2014-12-09 18:56:56 +01:00
|
|
|
# id :integer not null, primary key
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# remember_created_at :datetime
|
2015-03-19 16:22:55 +01:00
|
|
|
# admin :boolean
|
|
|
|
# dagschotel_id :integer
|
|
|
|
# avatar_file_name :string
|
|
|
|
# avatar_content_type :string
|
|
|
|
# avatar_file_size :integer
|
|
|
|
# avatar_updated_at :datetime
|
|
|
|
# orders_count :integer default("0")
|
|
|
|
# koelkast :boolean default("f")
|
2015-09-14 17:52:25 +02:00
|
|
|
# name :string
|
2015-09-02 20:33:35 +02:00
|
|
|
# encrypted_password :string default(""), not null
|
|
|
|
# private :boolean default("f")
|
2014-12-04 19:50:02 +01:00
|
|
|
#
|
|
|
|
|
2016-02-05 22:47:51 +01:00
|
|
|
require 'webmock/rspec'
|
|
|
|
|
2015-09-02 20:33:35 +02:00
|
|
|
describe User do
|
|
|
|
before :each do
|
|
|
|
@user = create :user
|
2015-03-03 18:16:05 +01:00
|
|
|
end
|
|
|
|
|
2015-09-02 20:33:35 +02:00
|
|
|
it 'has a valid factory' do
|
|
|
|
expect(@user).to be_valid
|
2015-03-03 18:16:05 +01:00
|
|
|
end
|
2015-09-21 15:54:56 +02:00
|
|
|
|
|
|
|
############
|
|
|
|
# FIELDS #
|
|
|
|
############
|
|
|
|
|
|
|
|
describe 'fields' do
|
|
|
|
describe 'avatar' do
|
|
|
|
it 'should be present' do
|
|
|
|
@user.avatar = nil
|
|
|
|
expect(@user).to_not be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'orders_count' do
|
|
|
|
it 'should automatically cache the number of orders' do
|
|
|
|
expect{ create :order, user: @user }.to change{ @user.reload.orders_count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
2015-10-28 23:34:03 +01:00
|
|
|
|
|
|
|
describe 'admin' do
|
|
|
|
it 'should be false by default' do
|
|
|
|
expect(@user.reload.admin).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-05 22:47:51 +01:00
|
|
|
describe 'balance' do
|
|
|
|
before :all do
|
|
|
|
@api_url = "www.example.com/api.json"
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be nil if offline' do
|
|
|
|
stub_request(:get, /.*/).to_return(status: 404)
|
|
|
|
expect(@user.balance).to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be updated when online' do
|
|
|
|
balance = 5
|
|
|
|
stub_request(:get, /.*/).to_return(status: 200, body: JSON.dump({ balance: balance }))
|
|
|
|
expect(@user.balance).to eq balance
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'omniauth' do
|
|
|
|
it 'should be a new user' do
|
|
|
|
name = "yet-another-test-user"
|
|
|
|
omniauth = double(uid: name)
|
|
|
|
expect(User.from_omniauth(omniauth).name).to eq name
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be the logged in user' do
|
|
|
|
second_user = create :user
|
|
|
|
omniauth = double(uid: second_user.name)
|
|
|
|
expect(User.from_omniauth(omniauth)).to eq second_user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'static users' do
|
2015-10-28 23:34:03 +01:00
|
|
|
describe 'koelkast' do
|
|
|
|
it 'should be false by default' do
|
|
|
|
expect(@user.reload.koelkast).to be false
|
|
|
|
end
|
2016-02-05 22:47:51 +01:00
|
|
|
|
|
|
|
it 'should be true for koelkast' do
|
|
|
|
expect(User.koelkast.koelkast).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not be an admin' do
|
|
|
|
expect(User.koelkast.admin).to be false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'guest' do
|
|
|
|
it 'should not be an admin' do
|
|
|
|
expect(User.guest.admin).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be public' do
|
|
|
|
expect(User.guest.private).to be false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be a guest' do
|
|
|
|
expect(User.guest.guest?).to be true
|
|
|
|
end
|
2015-10-28 23:34:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
############
|
|
|
|
# SCOPES #
|
|
|
|
############
|
|
|
|
|
|
|
|
describe 'scopes' do
|
|
|
|
it 'members should return members' do
|
|
|
|
create :koelkast
|
|
|
|
user = create :user
|
|
|
|
expect(User.members).to eq([@user, user])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'publik should return publik members' do
|
|
|
|
user = create :user
|
|
|
|
create :user, private: true
|
|
|
|
expect(User.publik).to eq([@user, user])
|
|
|
|
end
|
2015-09-21 15:54:56 +02:00
|
|
|
end
|
2014-11-06 14:46:59 +01:00
|
|
|
end
|