Description:
fixed dependency errors in spec
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r293:463e9531da32 - - 6 files changed: 43 inserted, 39 deleted

@@ -0,0 +1,20
1 +
2 + module ConfigSpecHelperMethods
3 +
4 + def find_or_create_and_set_config(key, type, value)
5 + c = Configuration.find_by_key(key)
6 + c ||= Configuration.new(:key => key,
7 + :value_type => type)
8 + c.value = value
9 + c.save!
10 + end
11 +
12 + def enable_multicontest
13 + find_or_create_and_set_config('system.multicontests','boolean','true')
14 + end
15 +
16 + def disable_multicontest
17 + find_or_create_and_set_config('system.multicontests','boolean','false')
18 + end
19 +
20 + end
@@ -62,96 +62,97
62 ((user.site.started!=true) or (user.site.finished?))
62 ((user.site.started!=true) or (user.site.finished?))
63 end
63 end
64 return true
64 return true
65 end
65 end
66
66
67 def self.show_tasks_to?(user)
67 def self.show_tasks_to?(user)
68 if time_limit_mode?
68 if time_limit_mode?
69 return false if not user.contest_started?
69 return false if not user.contest_started?
70 end
70 end
71 return true
71 return true
72 end
72 end
73
73
74 def self.show_grading_result
74 def self.show_grading_result
75 return (get(SYSTEM_MODE_CONF_KEY)=='analysis')
75 return (get(SYSTEM_MODE_CONF_KEY)=='analysis')
76 end
76 end
77
77
78 def self.allow_test_request(user)
78 def self.allow_test_request(user)
79 mode = get(SYSTEM_MODE_CONF_KEY)
79 mode = get(SYSTEM_MODE_CONF_KEY)
80 early_timeout = get(TEST_REQUEST_EARLY_TIMEOUT_KEY)
80 early_timeout = get(TEST_REQUEST_EARLY_TIMEOUT_KEY)
81 if (mode=='contest')
81 if (mode=='contest')
82 return false if ((user.site!=nil) and
82 return false if ((user.site!=nil) and
83 ((user.site.started!=true) or
83 ((user.site.started!=true) or
84 (early_timeout and (user.site.time_left < 30.minutes))))
84 (early_timeout and (user.site.time_left < 30.minutes))))
85 end
85 end
86 return false if mode=='analysis'
86 return false if mode=='analysis'
87 return true
87 return true
88 end
88 end
89
89
90 def self.task_grading_info
90 def self.task_grading_info
91 if Configuration.task_grading_info_cache==nil
91 if Configuration.task_grading_info_cache==nil
92 read_grading_info
92 read_grading_info
93 end
93 end
94 return Configuration.task_grading_info_cache
94 return Configuration.task_grading_info_cache
95 end
95 end
96
96
97 def self.standard_mode?
97 def self.standard_mode?
98 return get(SYSTEM_MODE_CONF_KEY) == 'standard'
98 return get(SYSTEM_MODE_CONF_KEY) == 'standard'
99 end
99 end
100
100
101 def self.contest_mode?
101 def self.contest_mode?
102 return get(SYSTEM_MODE_CONF_KEY) == 'contest'
102 return get(SYSTEM_MODE_CONF_KEY) == 'contest'
103 end
103 end
104
104
105 def self.indv_contest_mode?
105 def self.indv_contest_mode?
106 return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest'
106 return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest'
107 end
107 end
108
108
109 def self.multicontests?
109 def self.multicontests?
110 + g = get('system.multicontests')
110 return get('system.multicontests') == true
111 return get('system.multicontests') == true
111 end
112 end
112
113
113 def self.time_limit_mode?
114 def self.time_limit_mode?
114 mode = get(SYSTEM_MODE_CONF_KEY)
115 mode = get(SYSTEM_MODE_CONF_KEY)
115 return ((mode == 'contest') or (mode == 'indv-contest'))
116 return ((mode == 'contest') or (mode == 'indv-contest'))
116 end
117 end
117
118
118 def self.analysis_mode?
119 def self.analysis_mode?
119 return get(SYSTEM_MODE_CONF_KEY) == 'analysis'
120 return get(SYSTEM_MODE_CONF_KEY) == 'analysis'
120 end
121 end
121
122
122 def self.contest_time_limit
123 def self.contest_time_limit
123 contest_time_str = Configuration['contest.time_limit']
124 contest_time_str = Configuration['contest.time_limit']
124
125
125 if not defined? Configuration.contest_time_str
126 if not defined? Configuration.contest_time_str
126 Configuration.contest_time_str = nil
127 Configuration.contest_time_str = nil
127 end
128 end
128
129
129 if Configuration.contest_time_str != contest_time_str
130 if Configuration.contest_time_str != contest_time_str
130 Configuration.contest_time_str = contest_time_str
131 Configuration.contest_time_str = contest_time_str
131 if tmatch = /(\d+):(\d+)/.match(contest_time_str)
132 if tmatch = /(\d+):(\d+)/.match(contest_time_str)
132 h = tmatch[1].to_i
133 h = tmatch[1].to_i
133 m = tmatch[2].to_i
134 m = tmatch[2].to_i
134
135
135 Configuration.contest_time = h.hour + m.minute
136 Configuration.contest_time = h.hour + m.minute
136 else
137 else
137 Configuration.contest_time = nil
138 Configuration.contest_time = nil
138 end
139 end
139 end
140 end
140 return Configuration.contest_time
141 return Configuration.contest_time
141 end
142 end
142
143
143 protected
144 protected
144
145
145 def self.convert_type(val,type)
146 def self.convert_type(val,type)
146 case type
147 case type
147 when 'string'
148 when 'string'
148 return val
149 return val
149
150
150 when 'integer'
151 when 'integer'
151 return val.to_i
152 return val.to_i
152
153
153 when 'boolean'
154 when 'boolean'
154 return (val=='true')
155 return (val=='true')
155 end
156 end
156 end
157 end
157
158
@@ -1,104 +1,89
1 require File.dirname(__FILE__) + '/../spec_helper'
1 require File.dirname(__FILE__) + '/../spec_helper'
2 -
2 + require File.dirname(__FILE__) + '/../config_spec_helper'
3 - module ConfigHelperMethods
4 - def enable_multicontest
5 - c = Configuration.new(:key => 'system.multicontests',
6 - :value_type => 'boolean',
7 - :value => 'true')
8 - c.save
9 - end
10 -
11 - def disable_multicontest
12 - c = Configuration.new(:key => 'system.multicontests',
13 - :value_type => 'boolean',
14 - :value => 'false')
15 - c.save
16 - end
17 - end
18
3
19 describe MainController, "when a user comes to list page" do
4 describe MainController, "when a user comes to list page" do
20
5
21 it "should redirect user to login page when unlogged-in user try to access main/list" do
6 it "should redirect user to login page when unlogged-in user try to access main/list" do
22 get 'list'
7 get 'list'
23 response.should redirect_to(:action => 'login')
8 response.should redirect_to(:action => 'login')
24 end
9 end
25
10
26 end
11 end
27
12
28 describe MainController, "when a logged in user comes to list page, with multicontests off" do
13 describe MainController, "when a logged in user comes to list page, with multicontests off" do
29 integrate_views
14 integrate_views
30
15
31 - include ConfigHelperMethods
16 + include ConfigSpecHelperMethods
32
17
33 fixtures :users
18 fixtures :users
34 fixtures :problems
19 fixtures :problems
35 fixtures :contests
20 fixtures :contests
36
21
37 before(:each) do
22 before(:each) do
38 disable_multicontest
23 disable_multicontest
39 end
24 end
40
25
41 it "should list available problems" do
26 it "should list available problems" do
42 john = users(:john)
27 john = users(:john)
43 get "list", {}, {:user_id => john.id}
28 get "list", {}, {:user_id => john.id}
44
29
45 response.should render_template 'main/list'
30 response.should render_template 'main/list'
46 response.should have_text(/add/)
31 response.should have_text(/add/)
47 response.should have_text(/easy_problem/)
32 response.should have_text(/easy_problem/)
48 response.should have_text(/hard_problem/)
33 response.should have_text(/hard_problem/)
49 end
34 end
50
35
51 end
36 end
52
37
53 describe MainController, "when a logged in user comes to list page, with multicontests on" do
38 describe MainController, "when a logged in user comes to list page, with multicontests on" do
54 integrate_views
39 integrate_views
55
40
56 - include ConfigHelperMethods
41 + include ConfigSpecHelperMethods
57
42
58 fixtures :users
43 fixtures :users
59 fixtures :problems
44 fixtures :problems
60 fixtures :contests
45 fixtures :contests
61
46
62 before(:each) do
47 before(:each) do
63 enable_multicontest
48 enable_multicontest
64 end
49 end
65
50
66 it "should list only available public problems to users with no contest assigned" do
51 it "should list only available public problems to users with no contest assigned" do
67 john = users(:john)
52 john = users(:john)
68 get "list", {}, {:user_id => john.id}
53 get "list", {}, {:user_id => john.id}
69
54
70 response.should render_template('main/list')
55 response.should render_template('main/list')
71 response.should have_text(/add/)
56 response.should have_text(/add/)
72 response.should_not have_text(/easy_problem/)
57 response.should_not have_text(/easy_problem/)
73 response.should_not have_text(/hard_problem/)
58 response.should_not have_text(/hard_problem/)
74 end
59 end
75
60
76 it "should list available problems on a specific contest" do
61 it "should list available problems on a specific contest" do
77 james = users(:james)
62 james = users(:james)
78 get "list", {}, {:user_id => james.id}
63 get "list", {}, {:user_id => james.id}
79
64
80 response.should render_template('main/list')
65 response.should render_template('main/list')
81 response.should have_text(/add/)
66 response.should have_text(/add/)
82 response.should have_text(/easy_problem/)
67 response.should have_text(/easy_problem/)
83 response.should_not have_text(/hard_problem/)
68 response.should_not have_text(/hard_problem/)
84 end
69 end
85
70
86 it "should shows available problems by contests" do
71 it "should shows available problems by contests" do
87 james = users(:james)
72 james = users(:james)
88 get "list", {}, {:user_id => james.id}
73 get "list", {}, {:user_id => james.id}
89
74
90 response.should render_template('main/list')
75 response.should render_template('main/list')
91 response.should have_text(Regexp.new('Contest A.*easy_problem', Regexp::MULTILINE))
76 response.should have_text(Regexp.new('Contest A.*easy_problem', Regexp::MULTILINE))
92 end
77 end
93
78
94 it "should shows available problems by contests; problems belonging to more the one contest should appear many times" do
79 it "should shows available problems by contests; problems belonging to more the one contest should appear many times" do
95 jack = users(:jack)
80 jack = users(:jack)
96 get "list", {}, {:user_id => jack.id}
81 get "list", {}, {:user_id => jack.id}
97
82
98 response.should render_template('main/list')
83 response.should render_template('main/list')
99 response.should have_text(Regexp.new('Contest A.*easy_problem.*Contest B.*easy_problem', Regexp::MULTILINE))
84 response.should have_text(Regexp.new('Contest A.*easy_problem.*Contest B.*easy_problem', Regexp::MULTILINE))
100 response.should have_text(Regexp.new('Contest B.*hard_problem', Regexp::MULTILINE))
85 response.should have_text(Regexp.new('Contest B.*hard_problem', Regexp::MULTILINE))
101 end
86 end
102 end
87 end
103
88
104 describe MainController, "when a user loads sources and compiler messages" do
89 describe MainController, "when a user loads sources and compiler messages" do
@@ -1,67 +1,71
1
1
2 require File.dirname(__FILE__) + '/../spec_helper'
2 require File.dirname(__FILE__) + '/../spec_helper'
3
3
4 describe UsersController, "when a new user registers" do
4 describe UsersController, "when a new user registers" do
5
5
6 before(:each) do
6 before(:each) do
7 # create john
7 # create john
8
8
9 @john_info = {:login => 'john',
9 @john_info = {:login => 'john',
10 :full_name => 'John John',
10 :full_name => 'John John',
11 :email => 'john@space.com'}
11 :email => 'john@space.com'}
12 @john = User.new(@john_info)
12 @john = User.new(@john_info)
13
13
14 @john_activation_key = "123456"
14 @john_activation_key = "123456"
15
15
16 @john.should_receive(:activation_key).
16 @john.should_receive(:activation_key).
17 any_number_of_times.
17 any_number_of_times.
18 and_return(@john_activation_key)
18 and_return(@john_activation_key)
19
19
20 + Configuration.new(:key => 'system.online_registration',
21 + :value_type => 'boolean',
22 + :value => 'true').save
23 +
20 get :new
24 get :new
21 response.should render_template('users/new')
25 response.should render_template('users/new')
22 end
26 end
23
27
24 it "should show the new form again when user information is invalid" do
28 it "should show the new form again when user information is invalid" do
25 User.should_receive(:new).with(any_args()).and_return(@john)
29 User.should_receive(:new).with(any_args()).and_return(@john)
26 @john.should_receive(:activated=).with(false)
30 @john.should_receive(:activated=).with(false)
27 @john.should_receive(:valid?).and_return(false)
31 @john.should_receive(:valid?).and_return(false)
28 @john.should_not_receive(:save)
32 @john.should_not_receive(:save)
29
33
30 post :register, :login => @john_info[:login],
34 post :register, :login => @john_info[:login],
31 :full_name => @john_info[:full_name],
35 :full_name => @john_info[:full_name],
32 :email => @john_info[:email]
36 :email => @john_info[:email]
33
37
34 response.should render_template('users/new')
38 response.should render_template('users/new')
35 end
39 end
36
40
37 it "should create unactivated user and send e-mail with activation key" do
41 it "should create unactivated user and send e-mail with activation key" do
38 User.should_receive(:new).with(any_args()).and_return(@john)
42 User.should_receive(:new).with(any_args()).and_return(@john)
39 @john.should_receive(:activated=).with(false)
43 @john.should_receive(:activated=).with(false)
40 @john.should_receive(:valid?).and_return(true)
44 @john.should_receive(:valid?).and_return(true)
41 @john.should_receive(:save).and_return(true)
45 @john.should_receive(:save).and_return(true)
42
46
43 smtp_mock = mock("smtp")
47 smtp_mock = mock("smtp")
44 smtp_mock.should_receive(:send_message) do |msg,fr,to|
48 smtp_mock.should_receive(:send_message) do |msg,fr,to|
45 to.should == [@john_info[:email]]
49 to.should == [@john_info[:email]]
46 msg.index(@john_activation_key).should_not be_nil
50 msg.index(@john_activation_key).should_not be_nil
47 end
51 end
48
52
49 Net::SMTP.should_receive(:start).
53 Net::SMTP.should_receive(:start).
50 with(any_args()).
54 with(any_args()).
51 and_yield(smtp_mock)
55 and_yield(smtp_mock)
52
56
53 post :register, :login => @john_info[:login],
57 post :register, :login => @john_info[:login],
54 :full_name => @john_info[:full_name],
58 :full_name => @john_info[:full_name],
55 :email => @john_info[:email]
59 :email => @john_info[:email]
56
60
57 response.should render_template('users/new_splash')
61 response.should render_template('users/new_splash')
58 end
62 end
59
63
60 it "should create unactivated user and return error page when e-mail sending error" do
64 it "should create unactivated user and return error page when e-mail sending error" do
61 User.should_receive(:new).with(any_args()).and_return(@john)
65 User.should_receive(:new).with(any_args()).and_return(@john)
62 @john.should_receive(:activated=).with(false)
66 @john.should_receive(:activated=).with(false)
63 @john.should_receive(:valid?).and_return(true)
67 @john.should_receive(:valid?).and_return(true)
64 @john.should_receive(:save).and_return(true)
68 @john.should_receive(:save).and_return(true)
65
69
66 smtp_mock = mock("smtp")
70 smtp_mock = mock("smtp")
67 smtp_mock.should_receive(:send_message).
71 smtp_mock.should_receive(:send_message).
@@ -1,78 +1,78
1
1
2 require File.dirname(__FILE__) + '/../spec_helper'
2 require File.dirname(__FILE__) + '/../spec_helper'
3
3
4 - describe Configuration do
4 + describe Configuration, "when using cache" do
5 -
6 - # only work with cached configuration
7 - class Configuration
8 - @@cache = true
9 - end
10
5
11 before(:each) do
6 before(:each) do
7 + Configuration.cache = true
12 @int_config = mock(Configuration,
8 @int_config = mock(Configuration,
13 :id => 1,
9 :id => 1,
14 :key => 'mode',
10 :key => 'mode',
15 :value_type => 'integer',
11 :value_type => 'integer',
16 :value => '30')
12 :value => '30')
17
13
18 @string_config = mock(Configuration,
14 @string_config = mock(Configuration,
19 :id => 2,
15 :id => 2,
20 :key => 'title',
16 :key => 'title',
21 :value_type => 'string',
17 :value_type => 'string',
22 :value => 'Hello')
18 :value => 'Hello')
23
19
24 @boolean_config = mock(Configuration,
20 @boolean_config = mock(Configuration,
25 :id => 3,
21 :id => 3,
26 :key => 'single_user_mode',
22 :key => 'single_user_mode',
27 :value_type => 'boolean',
23 :value_type => 'boolean',
28 :value => 'true')
24 :value => 'true')
29 end
25 end
30
26
27 + after(:each) do
28 + Configuration.cache = false
29 + end
30 +
31 it "should retrieve int config" do
31 it "should retrieve int config" do
32 Configuration.should_receive(:find).once.with(:all).
32 Configuration.should_receive(:find).once.with(:all).
33 and_return([@int_config, @string_config, @boolean_config])
33 and_return([@int_config, @string_config, @boolean_config])
34
34
35 Configuration.clear
35 Configuration.clear
36 val = Configuration.get('mode')
36 val = Configuration.get('mode')
37 val.should == 30
37 val.should == 30
38 end
38 end
39
39
40 it "should retrieve boolean config" do
40 it "should retrieve boolean config" do
41 Configuration.should_receive(:find).once.with(:all).
41 Configuration.should_receive(:find).once.with(:all).
42 and_return([@int_config, @string_config, @boolean_config])
42 and_return([@int_config, @string_config, @boolean_config])
43
43
44 Configuration.clear
44 Configuration.clear
45 val = Configuration.get('single_user_mode')
45 val = Configuration.get('single_user_mode')
46 val.should == true
46 val.should == true
47 end
47 end
48
48
49 it "should retrieve string config" do
49 it "should retrieve string config" do
50 Configuration.should_receive(:find).once.with(:all).
50 Configuration.should_receive(:find).once.with(:all).
51 and_return([@int_config, @string_config, @boolean_config])
51 and_return([@int_config, @string_config, @boolean_config])
52
52
53 Configuration.clear
53 Configuration.clear
54 val = Configuration.get('title')
54 val = Configuration.get('title')
55 val.should == "Hello"
55 val.should == "Hello"
56 end
56 end
57
57
58 it "should retrieve config with []" do
58 it "should retrieve config with []" do
59 Configuration.should_receive(:find).once.with(:all).
59 Configuration.should_receive(:find).once.with(:all).
60 and_return([@int_config, @string_config, @boolean_config])
60 and_return([@int_config, @string_config, @boolean_config])
61
61
62 Configuration.clear
62 Configuration.clear
63 val = Configuration['title']
63 val = Configuration['title']
64 val.should == "Hello"
64 val.should == "Hello"
65 end
65 end
66
66
67 it "should read config table once" do
67 it "should read config table once" do
68 Configuration.should_receive(:find).once.with(:all).
68 Configuration.should_receive(:find).once.with(:all).
69 and_return([@int_config, @string_config, @boolean_config])
69 and_return([@int_config, @string_config, @boolean_config])
70
70
71 Configuration.clear
71 Configuration.clear
72 val = Configuration.get('title')
72 val = Configuration.get('title')
73 val.should == "Hello"
73 val.should == "Hello"
74 val = Configuration.get('single_user_mode')
74 val = Configuration.get('single_user_mode')
75 val.should == true
75 val.should == true
76 val = Configuration.get('mode')
76 val = Configuration.get('mode')
77 val.should == 30
77 val.should == 30
78 end
78 end
@@ -1,50 +1,50
1 -
2 require File.dirname(__FILE__) + '/../spec_helper'
1 require File.dirname(__FILE__) + '/../spec_helper'
2 + require File.dirname(__FILE__) + '/../config_spec_helper'
3
3
4 describe User do
4 describe User do
5
5
6 before(:each) do
6 before(:each) do
7 @password = "hello"
7 @password = "hello"
8 @salt = "123"
8 @salt = "123"
9 @john = stub_model(User, :salt => @salt,
9 @john = stub_model(User, :salt => @salt,
10 :hashed_password => User.encrypt(@password,@salt))
10 :hashed_password => User.encrypt(@password,@salt))
11 end
11 end
12
12
13 it "should be authenticated if activated" do
13 it "should be authenticated if activated" do
14 @john.should_receive(:activated).and_return(true)
14 @john.should_receive(:activated).and_return(true)
15 @john.authenticated?(@password).should == true
15 @john.authenticated?(@password).should == true
16 end
16 end
17
17
18 it "should not be authenticated if inactivated" do
18 it "should not be authenticated if inactivated" do
19 @john.should_receive(:activated).and_return(false)
19 @john.should_receive(:activated).and_return(false)
20 @john.authenticated?(@password).should == false
20 @john.authenticated?(@password).should == false
21 end
21 end
22
22
23 it "should not be authenticated if incorrect password is provided" do
23 it "should not be authenticated if incorrect password is provided" do
24 @john.should_receive(:activated).and_return(true)
24 @john.should_receive(:activated).and_return(true)
25 @john.should_receive(:hashed_password).and_return("byebye")
25 @john.should_receive(:hashed_password).and_return("byebye")
26 @john.authenticated?(@password).should == false
26 @john.authenticated?(@password).should == false
27 end
27 end
28
28
29 end
29 end
30
30
31 describe User, "during registration" do
31 describe User, "during registration" do
32
32
33 class User
33 class User
34 public :encrypt_new_password
34 public :encrypt_new_password
35 end
35 end
36
36
37 before(:each) do
37 before(:each) do
38 @john = User.new(:login => 'john', :password => 'hello')
38 @john = User.new(:login => 'john', :password => 'hello')
39 @john.encrypt_new_password
39 @john.encrypt_new_password
40 end
40 end
41
41
42 it "should produce and accept activation key" do
42 it "should produce and accept activation key" do
43 activation_key = @john.activation_key
43 activation_key = @john.activation_key
44
44
45 @john.verify_activation_key(activation_key).should == true
45 @john.verify_activation_key(activation_key).should == true
46 end
46 end
47
47
48 it "should not accept invalid activation key" do
48 it "should not accept invalid activation key" do
49 @john.verify_activation_key("12345").should == false
49 @john.verify_activation_key("12345").should == false
50 end
50 end
@@ -60,110 +60,104
60 @mary_first = mock_model(User,
60 @mary_first = mock_model(User,
61 :login => 'mary1',
61 :login => 'mary1',
62 :password => 'hello',
62 :password => 'hello',
63 :email => @mary_email,
63 :email => @mary_email,
64 :created_at => @time_first_register)
64 :created_at => @time_first_register)
65 @mary_second = User.new(:login => 'mary2',
65 @mary_second = User.new(:login => 'mary2',
66 :password => 'hello',
66 :password => 'hello',
67 :email => @mary_email)
67 :email => @mary_email)
68 User.stub!(:find_by_email).
68 User.stub!(:find_by_email).
69 with(@mary_email, {:order => "created_at DESC"}).
69 with(@mary_email, {:order => "created_at DESC"}).
70 and_return(@mary_first)
70 and_return(@mary_first)
71 end
71 end
72
72
73 class User
73 class User
74 public :enough_time_interval_between_same_email_registrations
74 public :enough_time_interval_between_same_email_registrations
75 end
75 end
76
76
77 it "should not be allowed if the time interval is less than 5 mins" do
77 it "should not be allowed if the time interval is less than 5 mins" do
78 time_now = @time_first_register + 4.minutes
78 time_now = @time_first_register + 4.minutes
79 Time.stub!(:now).and_return(time_now)
79 Time.stub!(:now).and_return(time_now)
80
80
81 @mary_second.enough_time_interval_between_same_email_registrations
81 @mary_second.enough_time_interval_between_same_email_registrations
82 @mary_second.errors.length.should_not be_zero
82 @mary_second.errors.length.should_not be_zero
83 end
83 end
84
84
85 it "should be allowed if the time interval is more than 5 mins" do
85 it "should be allowed if the time interval is more than 5 mins" do
86 time_now = @time_first_register + 6.minutes
86 time_now = @time_first_register + 6.minutes
87 Time.stub!(:now).and_return(time_now)
87 Time.stub!(:now).and_return(time_now)
88
88
89 @mary_second.enough_time_interval_between_same_email_registrations
89 @mary_second.enough_time_interval_between_same_email_registrations
90 @mary_second.errors.length.should be_zero
90 @mary_second.errors.length.should be_zero
91 end
91 end
92
92
93 end
93 end
94
94
95 describe User, "as a class" do
95 describe User, "as a class" do
96
96
97 it "should be able to generate random password" do
97 it "should be able to generate random password" do
98 password1 = User.random_password
98 password1 = User.random_password
99 password2 = User.random_password
99 password2 = User.random_password
100
100
101 password1.should_not == password2
101 password1.should_not == password2
102 end
102 end
103
103
104 end
104 end
105
105
106 describe User, "when requesting problem description," do
106 describe User, "when requesting problem description," do
107
107
108 + include ConfigSpecHelperMethods
109 +
108 fixtures :users
110 fixtures :users
109 fixtures :problems
111 fixtures :problems
110
112
111 before(:each) do
113 before(:each) do
112 @james = users(:james)
114 @james = users(:james)
113 @john = users(:john)
115 @john = users(:john)
114 @jack = users(:jack)
116 @jack = users(:jack)
115 @add = problems(:one)
117 @add = problems(:one)
116 @easy = problems(:easy)
118 @easy = problems(:easy)
117 @hard = problems(:hard)
119 @hard = problems(:hard)
118 end
120 end
119
121
120 it "should check if a problem is in user's contests" do
122 it "should check if a problem is in user's contests" do
121 @james.problem_in_user_contests?(@easy).should be_true
123 @james.problem_in_user_contests?(@easy).should be_true
122 @james.problem_in_user_contests?(@hard).should be_false
124 @james.problem_in_user_contests?(@hard).should be_false
123
125
124 @john.problem_in_user_contests?(@easy).should be_false
126 @john.problem_in_user_contests?(@easy).should be_false
125 @john.problem_in_user_contests?(@hard).should be_false
127 @john.problem_in_user_contests?(@hard).should be_false
126 end
128 end
127
129
128 it "should be able to view problem in user's contests, when multicontests is on" do
130 it "should be able to view problem in user's contests, when multicontests is on" do
129 enable_multicontest
131 enable_multicontest
130 @james.can_view_problem?(@easy).should be_true
132 @james.can_view_problem?(@easy).should be_true
131 @jack.can_view_problem?(@easy).should be_true
133 @jack.can_view_problem?(@easy).should be_true
132 @jack.can_view_problem?(@hard).should be_true
134 @jack.can_view_problem?(@hard).should be_true
133 end
135 end
134
136
135 it "should not be able to view problem not in user's contests, when multicontests is on" do
137 it "should not be able to view problem not in user's contests, when multicontests is on" do
136 enable_multicontest
138 enable_multicontest
139 + @james.can_view_problem?(@hard).should be_false
140 + end
141 +
142 + it "with no assigned contest should not be able to view problem in contests when multicontests is on" do
143 + enable_multicontest
144 + @john.can_view_problem?(@add).should be_true
137 @john.can_view_problem?(@easy).should be_false
145 @john.can_view_problem?(@easy).should be_false
138 @john.can_view_problem?(@hard).should be_false
146 @john.can_view_problem?(@hard).should be_false
139 - @james.can_view_problem?(@hard).should be_false
140 end
147 end
141
148
142 it "should be able to view all available problems, when multicontests is off" do
149 it "should be able to view all available problems, when multicontests is off" do
143 disable_multicontest
150 disable_multicontest
144 @john.can_view_problem?(@easy).should be_true
151 @john.can_view_problem?(@easy).should be_true
145 @john.can_view_problem?(@hard).should be_true
152 @john.can_view_problem?(@hard).should be_true
146 @james.can_view_problem?(@easy).should be_true
153 @james.can_view_problem?(@easy).should be_true
147 @james.can_view_problem?(@hard).should be_true
154 @james.can_view_problem?(@hard).should be_true
148 end
155 end
149
156
150 it "should be able to view public problems, when multicontests is on" do
157 it "should be able to view public problems, when multicontests is on" do
151 enable_multicontest
158 enable_multicontest
152 @john.can_view_problem?(@add).should be_true
159 @john.can_view_problem?(@add).should be_true
153 @james.can_view_problem?(@add).should be_true
160 @james.can_view_problem?(@add).should be_true
154 end
161 end
155
162
156 - def enable_multicontest
157 - c = Configuration.new(:key => 'system.multicontests',
158 - :value_type => 'boolean',
159 - :value => 'true')
160 - c.save
161 end
163 end
162 -
163 - def disable_multicontest
164 - c = Configuration.new(:key => 'system.multicontests',
165 - :value_type => 'boolean',
166 - :value => 'false')
167 - c.save
168 - end
169 - end
You need to be logged in to leave comments. Login now