cover the user model

This commit is contained in:
Felix Van der Jeugt 2016-02-05 22:47:51 +01:00
parent 71fc48cd71
commit 91e551e35e
5 changed files with 72 additions and 2 deletions

View file

@ -29,6 +29,7 @@ group :test do
gem 'codeclimate-test-reporter', require: nil
gem 'rspec-rails'
gem 'coveralls', require: false
gem 'webmock'
end
group :development do

View file

@ -36,6 +36,7 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
addressable (2.4.0)
airbrake (4.3.5)
builder
multi_json
@ -89,6 +90,8 @@ GEM
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
tins (~> 1.6.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
daemons (1.2.3)
delayed_job (4.1.1)
activesupport (>= 3.0, < 5.0)
@ -129,6 +132,7 @@ GEM
haml (>= 4.0.6, < 5.0)
html2haml (>= 1.0.1)
railties (>= 4.0.1)
hashdiff (0.2.3)
hashie (3.4.3)
hike (1.2.3)
html2haml (2.0.0)
@ -242,6 +246,7 @@ GEM
rspec-support (3.4.1)
ruby_parser (3.7.3)
sexp_processor (~> 4.1)
safe_yaml (1.0.4)
sass (3.2.19)
sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0)
@ -289,6 +294,10 @@ GEM
unf_ext (0.0.7.2)
warden (1.2.6)
rack (>= 1.0)
webmock (1.22.6)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
will_paginate (3.0.7)
PLATFORMS
@ -329,7 +338,8 @@ DEPENDENCIES
sqlite3
turbolinks
uglifier (>= 1.3.0)
webmock
will_paginate (= 3.0.7)
BUNDLED WITH
1.10.6
1.11.2

View file

@ -42,4 +42,6 @@ Rails.application.configure do
Paperclip.options[:command_path] = "/usr/local/bin/"
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.api_url = "http://www.example.com"
end

View file

@ -24,7 +24,7 @@ require 'identicon'
FactoryGirl.define do
factory :user do
name { Faker::Name.name }
name { Faker::Internet.user_name }
avatar { Identicon.data_url_for name }
private { false }

View file

@ -19,6 +19,8 @@
# private :boolean default("f")
#
require 'webmock/rspec'
describe User do
before :each do
@user = create :user
@ -52,10 +54,65 @@ describe User do
end
end
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
describe 'koelkast' do
it 'should be false by default' do
expect(@user.reload.koelkast).to be false
end
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
end
end