Description:
fixed dependency errors in spec
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
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 |
@@ -98,24 +98,25 | |||
|
98 | 98 | return get(SYSTEM_MODE_CONF_KEY) == 'standard' |
|
99 | 99 | end |
|
100 | 100 | |
|
101 | 101 | def self.contest_mode? |
|
102 | 102 | return get(SYSTEM_MODE_CONF_KEY) == 'contest' |
|
103 | 103 | end |
|
104 | 104 | |
|
105 | 105 | def self.indv_contest_mode? |
|
106 | 106 | return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest' |
|
107 | 107 | end |
|
108 | 108 | |
|
109 | 109 | def self.multicontests? |
|
110 | + g = get('system.multicontests') | |
|
110 | 111 | return get('system.multicontests') == true |
|
111 | 112 | end |
|
112 | 113 | |
|
113 | 114 | def self.time_limit_mode? |
|
114 | 115 | mode = get(SYSTEM_MODE_CONF_KEY) |
|
115 | 116 | return ((mode == 'contest') or (mode == 'indv-contest')) |
|
116 | 117 | end |
|
117 | 118 | |
|
118 | 119 | def self.analysis_mode? |
|
119 | 120 | return get(SYSTEM_MODE_CONF_KEY) == 'analysis' |
|
120 | 121 | end |
|
121 | 122 |
@@ -1,68 +1,53 | |||
|
1 | 1 | require File.dirname(__FILE__) + '/../spec_helper' |
|
2 | - | |
|
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 | |
|
2 | + require File.dirname(__FILE__) + '/../config_spec_helper' | |
|
18 | 3 | |
|
19 | 4 | describe MainController, "when a user comes to list page" do |
|
20 | 5 | |
|
21 | 6 | it "should redirect user to login page when unlogged-in user try to access main/list" do |
|
22 | 7 | get 'list' |
|
23 | 8 | response.should redirect_to(:action => 'login') |
|
24 | 9 | end |
|
25 | 10 | |
|
26 | 11 | end |
|
27 | 12 | |
|
28 | 13 | describe MainController, "when a logged in user comes to list page, with multicontests off" do |
|
29 | 14 | integrate_views |
|
30 | 15 | |
|
31 | - include ConfigHelperMethods | |
|
16 | + include ConfigSpecHelperMethods | |
|
32 | 17 | |
|
33 | 18 | fixtures :users |
|
34 | 19 | fixtures :problems |
|
35 | 20 | fixtures :contests |
|
36 | 21 | |
|
37 | 22 | before(:each) do |
|
38 | 23 | disable_multicontest |
|
39 | 24 | end |
|
40 | 25 | |
|
41 | 26 | it "should list available problems" do |
|
42 | 27 | john = users(:john) |
|
43 | 28 | get "list", {}, {:user_id => john.id} |
|
44 | 29 | |
|
45 | 30 | response.should render_template 'main/list' |
|
46 | 31 | response.should have_text(/add/) |
|
47 | 32 | response.should have_text(/easy_problem/) |
|
48 | 33 | response.should have_text(/hard_problem/) |
|
49 | 34 | end |
|
50 | 35 | |
|
51 | 36 | end |
|
52 | 37 | |
|
53 | 38 | describe MainController, "when a logged in user comes to list page, with multicontests on" do |
|
54 | 39 | integrate_views |
|
55 | 40 | |
|
56 | - include ConfigHelperMethods | |
|
41 | + include ConfigSpecHelperMethods | |
|
57 | 42 | |
|
58 | 43 | fixtures :users |
|
59 | 44 | fixtures :problems |
|
60 | 45 | fixtures :contests |
|
61 | 46 | |
|
62 | 47 | before(:each) do |
|
63 | 48 | enable_multicontest |
|
64 | 49 | end |
|
65 | 50 | |
|
66 | 51 | it "should list only available public problems to users with no contest assigned" do |
|
67 | 52 | john = users(:john) |
|
68 | 53 | get "list", {}, {:user_id => john.id} |
@@ -8,24 +8,28 | |||
|
8 | 8 | |
|
9 | 9 | @john_info = {:login => 'john', |
|
10 | 10 | :full_name => 'John John', |
|
11 | 11 | :email => 'john@space.com'} |
|
12 | 12 | @john = User.new(@john_info) |
|
13 | 13 | |
|
14 | 14 | @john_activation_key = "123456" |
|
15 | 15 | |
|
16 | 16 | @john.should_receive(:activation_key). |
|
17 | 17 | any_number_of_times. |
|
18 | 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 | 24 | get :new |
|
21 | 25 | response.should render_template('users/new') |
|
22 | 26 | end |
|
23 | 27 | |
|
24 | 28 | it "should show the new form again when user information is invalid" do |
|
25 | 29 | User.should_receive(:new).with(any_args()).and_return(@john) |
|
26 | 30 | @john.should_receive(:activated=).with(false) |
|
27 | 31 | @john.should_receive(:valid?).and_return(false) |
|
28 | 32 | @john.should_not_receive(:save) |
|
29 | 33 | |
|
30 | 34 | post :register, :login => @john_info[:login], |
|
31 | 35 | :full_name => @john_info[:full_name], |
@@ -1,42 +1,42 | |||
|
1 | 1 | |
|
2 | 2 | require File.dirname(__FILE__) + '/../spec_helper' |
|
3 | 3 | |
|
4 | - describe Configuration do | |
|
5 | - | |
|
6 | - # only work with cached configuration | |
|
7 | - class Configuration | |
|
8 | - @@cache = true | |
|
9 | - end | |
|
4 | + describe Configuration, "when using cache" do | |
|
10 | 5 | |
|
11 | 6 | before(:each) do |
|
7 | + Configuration.cache = true | |
|
12 | 8 | @int_config = mock(Configuration, |
|
13 | 9 | :id => 1, |
|
14 | 10 | :key => 'mode', |
|
15 | 11 | :value_type => 'integer', |
|
16 | 12 | :value => '30') |
|
17 | 13 | |
|
18 | 14 | @string_config = mock(Configuration, |
|
19 | 15 | :id => 2, |
|
20 | 16 | :key => 'title', |
|
21 | 17 | :value_type => 'string', |
|
22 | 18 | :value => 'Hello') |
|
23 | 19 | |
|
24 | 20 | @boolean_config = mock(Configuration, |
|
25 | 21 | :id => 3, |
|
26 | 22 | :key => 'single_user_mode', |
|
27 | 23 | :value_type => 'boolean', |
|
28 | 24 | :value => 'true') |
|
29 | 25 | end |
|
30 | 26 | |
|
27 | + after(:each) do | |
|
28 | + Configuration.cache = false | |
|
29 | + end | |
|
30 | + | |
|
31 | 31 | it "should retrieve int config" do |
|
32 | 32 | Configuration.should_receive(:find).once.with(:all). |
|
33 | 33 | and_return([@int_config, @string_config, @boolean_config]) |
|
34 | 34 | |
|
35 | 35 | Configuration.clear |
|
36 | 36 | val = Configuration.get('mode') |
|
37 | 37 | val.should == 30 |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | it "should retrieve boolean config" do |
|
41 | 41 | Configuration.should_receive(:find).once.with(:all). |
|
42 | 42 | and_return([@int_config, @string_config, @boolean_config]) |
@@ -1,14 +1,14 | |||
|
1 | - | |
|
2 | 1 |
|
|
2 | + require File.dirname(__FILE__) + '/../config_spec_helper' | |
|
3 | 3 | |
|
4 | 4 | describe User do |
|
5 | 5 | |
|
6 | 6 | before(:each) do |
|
7 | 7 | @password = "hello" |
|
8 | 8 | @salt = "123" |
|
9 | 9 | @john = stub_model(User, :salt => @salt, |
|
10 | 10 | :hashed_password => User.encrypt(@password,@salt)) |
|
11 | 11 | end |
|
12 | 12 | |
|
13 | 13 | it "should be authenticated if activated" do |
|
14 | 14 | @john.should_receive(:activated).and_return(true) |
@@ -96,24 +96,26 | |||
|
96 | 96 | |
|
97 | 97 | it "should be able to generate random password" do |
|
98 | 98 | password1 = User.random_password |
|
99 | 99 | password2 = User.random_password |
|
100 | 100 | |
|
101 | 101 | password1.should_not == password2 |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | describe User, "when requesting problem description," do |
|
107 | 107 | |
|
108 | + include ConfigSpecHelperMethods | |
|
109 | + | |
|
108 | 110 | fixtures :users |
|
109 | 111 | fixtures :problems |
|
110 | 112 | |
|
111 | 113 | before(:each) do |
|
112 | 114 | @james = users(:james) |
|
113 | 115 | @john = users(:john) |
|
114 | 116 | @jack = users(:jack) |
|
115 | 117 | @add = problems(:one) |
|
116 | 118 | @easy = problems(:easy) |
|
117 | 119 | @hard = problems(:hard) |
|
118 | 120 | end |
|
119 | 121 | |
@@ -125,45 +127,37 | |||
|
125 | 127 | @john.problem_in_user_contests?(@hard).should be_false |
|
126 | 128 | end |
|
127 | 129 | |
|
128 | 130 | it "should be able to view problem in user's contests, when multicontests is on" do |
|
129 | 131 | enable_multicontest |
|
130 | 132 | @james.can_view_problem?(@easy).should be_true |
|
131 | 133 | @jack.can_view_problem?(@easy).should be_true |
|
132 | 134 | @jack.can_view_problem?(@hard).should be_true |
|
133 | 135 | end |
|
134 | 136 | |
|
135 | 137 | it "should not be able to view problem not in user's contests, when multicontests is on" do |
|
136 | 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 | 145 | @john.can_view_problem?(@easy).should be_false |
|
138 | 146 | @john.can_view_problem?(@hard).should be_false |
|
139 | - @james.can_view_problem?(@hard).should be_false | |
|
140 | 147 | end |
|
141 | 148 | |
|
142 | 149 | it "should be able to view all available problems, when multicontests is off" do |
|
143 | 150 | disable_multicontest |
|
144 | 151 | @john.can_view_problem?(@easy).should be_true |
|
145 | 152 | @john.can_view_problem?(@hard).should be_true |
|
146 | 153 | @james.can_view_problem?(@easy).should be_true |
|
147 | 154 | @james.can_view_problem?(@hard).should be_true |
|
148 | 155 | end |
|
149 | 156 | |
|
150 | 157 | it "should be able to view public problems, when multicontests is on" do |
|
151 | 158 | enable_multicontest |
|
152 | 159 | @john.can_view_problem?(@add).should be_true |
|
153 | 160 | @james.can_view_problem?(@add).should be_true |
|
154 | 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 | 163 |
|
|
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