-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_spec.rb
91 lines (75 loc) · 2.5 KB
/
user_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require "user"
require "matchers"
describe User do
before(:each) do
@user = User.new("Person", "123")
end
it "should have a login" do
@user.should respond_to(:login)
@user.login.should be_instance_of(String)
end
it "should have a MD5 encoded password" do
@user.should respond_to(:password)
@user.password.should be_MD5
end
it "should have status" do
@user.should respond_to(:status)
end
it "should be able to check if it is a SpyShopper" do
@user.should respond_to(:is_spy_shopper)
@spy = SpyShopper.new("pirkejas-petras", "pass", 25, "Studentas")
@spy.is_spy_shopper.should be_true
end
it "should be able to check if it is a Client" do
@user.should respond_to(:is_client)
@client = Client.new("bosas", "boss22", "Swedbank lizingas", "Gelezinio vilko g. 18A")
@client.is_client.should be_true
end
it "should be able to check if it is a Manager" do
@user.should respond_to(:is_manager)
@manager = Manager.new("manager", "manager99")
@manager.is_manager.should be_true
end
end
describe User, "as a users DB" do
before(:each) do
@user = User.new("Person", "123")
end
it "should be able to insert user" do
User.should respond_to(:insert)
User.insert(@user)
User.db.keys.should include("Person")
User.db["Person"].should == @user
end
it "should NOT be able to insert users with same login" do
lambda { User.insert(@user) }.should raise_error
end
it "should be able to check if user exists" do
User.should respond_to(:exists)
User.exists(@user.login).should be_true
User.exists("some-bad-login").should be_false
end
it "should be able to find user by id" do
u = User.new("Man", "111")
User.insert(u)
id = User.db[u.login].id
User.db[u.login].should eql(User.by_id(id))
end
it "should be able to validate login and password" do
User.should respond_to(:valid)
User.valid("Person", "123").should be_true
User.valid("Person", "999").should be_false
end
it "should be able to get list of SpyShoppers" do
User.should respond_to(:spy_shoppers)
@spy = SpyShopper.new("pirkejas-petras", "pass", 25, "Studentas")
User.insert(@spy)
User.spy_shoppers.values.should include(@spy)
end
it "should be able to get list of Clients" do
User.should respond_to(:clients)
@client = Client.new("bosas", "boss22", "Swedbank lizingas", "Gelezinio vilko g. 18A")
User.insert(@client)
User.clients.values.should include(@client)
end
end