aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/user_controller_spec.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2014-01-29 16:10:52 +0000
committerLouise Crow <louise.crow@gmail.com>2014-01-29 16:10:52 +0000
commit184ffeccb7f4579b481db9b7744aa9baed70562f (patch)
tree67c023b029a699a1e727ef6becdc0832e82ea1c5 /spec/controllers/user_controller_spec.rb
parente44c8b875fd4ad46b954ef9c31bdb6f0366dcb9e (diff)
parent79b2f672aeae394a2c195d89b70bda27bb3201a4 (diff)
Merge branch 'feature/batch-requests' into rails-3-develop
Conflicts: config/general.yml-example spec/factories.rb
Diffstat (limited to 'spec/controllers/user_controller_spec.rb')
-rw-r--r--spec/controllers/user_controller_spec.rb95
1 files changed, 65 insertions, 30 deletions
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 0033309a5..cf361d898 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -30,55 +30,90 @@ describe UserController, "when redirecting a show request to a canonical url" do
end
describe UserController, "when showing a user" do
- render_views
+
before(:each) do
- load_raw_emails_data
- get_fixtures_xapian_index
+ @user = FactoryGirl.create(:user)
end
it "should be successful" do
- get :show, :url_name => "bob_smith"
+ get :show, :url_name => @user.url_name
response.should be_success
end
it "should render with 'show' template" do
- get :show, :url_name => "bob_smith"
+ get :show, :url_name => @user.url_name
response.should render_template('show')
end
- it "should distinguish between 'my profile' and 'my requests' for logged in users" do
- session[:user_id] = users(:bob_smith_user).id
- get :show, :url_name => "bob_smith", :view => 'requests'
- response.body.should_not include("Change your password")
- response.body.should match(/Your [0-9]+ Freedom of Information requests/)
- get :show, :url_name => "bob_smith", :view => 'profile'
- response.body.should include("Change your password")
- response.body.should_not match(/Your [0-9]+ Freedom of Information requests/)
+ it "should assign the user" do
+ get :show, :url_name => @user.url_name
+ assigns[:display_user].should == @user
end
- it "should assign the user" do
- get :show, :url_name => "bob_smith"
- assigns[:display_user].should == users(:bob_smith_user)
+ context "when viewing the user's own profile" do
+
+ render_views
+
+ def make_request
+ get :show, {:url_name => @user.url_name, :view => 'profile'}, {:user_id => @user.id}
+ end
+
+ it 'should not show requests, or batch requests, but should show account options' do
+ make_request
+ response.body.should_not match(/Freedom of Information requests made by you/)
+ assigns[:show_batches].should be_false
+ response.body.should include("Change your password")
+ end
+
end
- it "should search the user's contributions" do
- get :show, :url_name => "bob_smith"
- assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
- :conditions => "user_id = #{users(:bob_smith_user).id}")
+ context "when viewing a user's own requests" do
+
+ render_views
+
+ def make_request
+ get :show, {:url_name => @user.url_name, :view => 'requests'}, {:user_id => @user.id}
+ end
+
+ it 'should show requests, batch requests, but no account options' do
+ make_request
+ response.body.should match(/Freedom of Information requests made by you/)
+ assigns[:show_batches].should be_true
+ response.body.should_not include("Change your password")
+ end
- get :show, :url_name => "bob_smith", :user_query => "money"
- assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [
- info_requests(:naughty_chicken_request),
- info_requests(:another_boring_request),
- ]
end
- it "should not show unconfirmed users" do
- begin
- get :show, :url_name => "unconfirmed_user"
- rescue => e
+end
+
+describe UserController, "when showing a user" do
+
+ context 'when using fixture data' do
+
+ before do
+ load_raw_emails_data
+ get_fixtures_xapian_index
end
- e.should be_an_instance_of(ActiveRecord::RecordNotFound)
+
+ it "should search the user's contributions" do
+ get :show, :url_name => "bob_smith"
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
+ :conditions => "user_id = #{users(:bob_smith_user).id}")
+
+ get :show, :url_name => "bob_smith", :user_query => "money"
+ assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ [
+ info_requests(:naughty_chicken_request),
+ info_requests(:another_boring_request),
+ ]
+ end
+
+ it "should not show unconfirmed users" do
+ begin
+ get :show, :url_name => "unconfirmed_user"
+ rescue => e
+ end
+ e.should be_an_instance_of(ActiveRecord::RecordNotFound)
+ end
end
end