forked from jwang/apn_on_rails
/
device_spec.rb
60 lines (45 loc) · 1.93 KB
/
device_spec.rb
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
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper.rb')
describe APN::Device do
describe 'token' do
it 'should be unique' do
device = DeviceFactory.new(:token => APN::Device.first.token)
device.should_not be_valid
device.errors['token'].should include('has already been taken')
device = DeviceFactory.new(:token => device.token.succ)
device.should be_valid
end
it 'should get cleansed if it contains brackets' do
token = DeviceFactory.random_token
device = DeviceFactory.new(:token => "<#{token}>")
device.token.should == token
device.token.should_not == "<#{token}>"
end
it 'should be in the correct pattern' do
device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
device.should be_valid
device.token = '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6'
device.should_not be_valid
device.token = '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7!!'
device.should_not be_valid
end
end
describe 'to_hexa' do
it 'should convert the text string to hexadecimal' do
device = DeviceFactory.new(:token => '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz')
device.to_hexa.should == fixture_value('hexa.bin')
end
end
describe 'before_create' do
it 'should set the last_registered_at date to Time.now' do
time = Time.now
Time.stub(:now).and_return(time)
device = DeviceFactory.create
device.last_registered_at.should_not be_nil
device.last_registered_at.to_s.should == time.to_s
# ago = 1.week.ago
# device = DeviceFactory.create(:last_registered_at => ago)
# device.last_registered_at.should_not be_nil
# device.last_registered_at.to_s.should == ago.to_s
end
end
end