forked from dsjoerg/ggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_spec.rb
More file actions
61 lines (47 loc) · 1.6 KB
/
user_spec.rb
File metadata and controls
61 lines (47 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# encoding: UTF-8
require 'spec_helper'
describe User do
# This test only tests the expected keys against the value of the model and
# not the correctness of the values!
it 'should serialize via jbuilder correctly' do
expected_keys = [:email, :password, :password_confirmation, :remember_me, :handle]
user = FactoryGirl.create(:user)
hash = user.to_builder.attributes!
expected_keys.each do |xk|
hash[xk.to_s].should == user.send(xk)
end
hash['accounts'].should_not be_nil
hash['notifications'].should_not be_nil
hash['accounts'][0].keys.length.should == 23
hash['notifications'][0].keys.length.should == 6
end
it 'should require an email' do
user = User.new
user.email = nil
user.valid?.should == false
end
it 'should require a password' do
user = User.new
user.password = nil
user.valid?.should == false
end
it 'should create a valid notification with #notify' do
user = FactoryGirl.create(:user)
user.ack_all_notifications!
user.notifications.count.should == 0
user.notify('gg!')
user.notifications.should_not be_empty
n = user.notifications.where(:ack_at => nil).first
n.message.should == 'gg!'
end
it 'should allow create parameters to be passed to #notify' do
user = FactoryGirl.create(:user)
user.ack_all_notifications!
user.notifications.count.should == 0
user.notify({:title => 'gg!', :message => 'good game.'})
user.notifications.should_not be_empty
n = user.notifications.where(:ack_at => nil).first
n.title.should == 'gg!'
n.message.should == 'good game.'
end
end