# coding: utf-8 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') # XXX Use route_for or params_from to check /c/ links better # http://rspec.rubyforge.org/rspec-rails/1.1.12/classes/Spec/Rails/Example/ControllerExampleGroup.html describe UserController, "when showing a user" do integrate_views before(:each) do load_raw_emails_data rebuild_xapian_index end it "should be successful" do get :show, :url_name => "bob_smith" response.should be_success end it "should redirect to lower case name if given one with capital letters" do get :show, :url_name => "Bob_Smith" response.should redirect_to(:controller => 'user', :action => 'show', :url_name => "bob_smith") end it "should render with 'show' template" do get :show, :url_name => "bob_smith" 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/) end it "should assign the user" do get :show, :url_name => "bob_smith" assigns[:display_user].should == users(:bob_smith_user) 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}") 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 describe UserController, "when signing in" do integrate_views def get_last_postredirect post_redirects = PostRedirect.find_by_sql("select * from post_redirects order by id desc limit 1") post_redirects.size.should == 1 post_redirects[0] end it "should show sign in / sign up page" do get :signin response.should have_tag("input#signin_token") end it "should create post redirect to / when you just go to /signin" do get :signin post_redirect = get_last_postredirect post_redirect.uri.should == "/" end it "should create post redirect to /list when you click signin on /list" do get :signin, :r => "/list" post_redirect = get_last_postredirect post_redirect.uri.should == "/list" end it "should show you the sign in page again if you get the password wrong" do get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'NOTRIGHTPASSWORD' }, :token => post_redirect.token } response.should render_template('sign') end it "should log in when you give right email/password, and redirect to where you were" do old_filters = ActionController::Routing::Routes.filters ActionController::Routing::Routes.filters = RoutingFilter::Chain.new get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' }, :token => post_redirect.token } session[:user_id].should == users(:bob_smith_user).id # response doesn't contain /en/ but redirect_to does... response.should redirect_to(:controller => 'request', :action => 'list', :post_redirect => 1) response.should_not send_email ActionController::Routing::Routes.filters = old_filters end it "should not log you in if you use an invalid PostRedirect token, and shouldn't give 500 error either" do old_filters = ActionController::Routing::Routes.filters ActionController::Routing::Routes.filters = RoutingFilter::Chain.new post_redirect = "something invalid" lambda { post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' }, :token => post_redirect } }.should_not raise_error(NoMethodError) post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' }, :token => post_redirect } response.should render_template('sign') assigns[:post_redirect].should == nil ActionController::Routing::Routes.filters = old_filters end # No idea how to test this in the test framework :( # it "should have set a long lived cookie if they picked remember me, session cookie if they didn't" do # get :signin, :r => "/list" # response.should render_template('sign') # post :signin, { :user_signin => { :email => 'bob@localhost', :password => 'jonespassword' } } # session[:user_id].should == users(:bob_smith_user).id # raise session.options.to_yaml # check cookie lasts a month # end it "should ask you to confirm your email if it isn't confirmed, after log in" do get :signin, :r => "/list" response.should render_template('sign') post_redirect = get_last_postredirect post :signin, { :user_signin => { :email => 'unconfirmed@localhost', :password => 'jonespassword' }, :token => post_r
/*
* FancyBox - jQuery Plugin
* Simple and fancy lightbox alternative
*
* Examples and documentation at: http://fancybox.net
*
* Copyright (c) 2008 - 2010 Janis Skarnelis
* That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
*
* Version: 1.3.4 (11/11/2010)
* Requires: jQuery v1.3+
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
;(function(b){var m,t,u,f,D,j,E,n,z,A,q=0,e={},o=[],p=0,d={},l=[],G=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,i,h=false,B=b.extend(b("<div/>")[0],{prop:0}),M=b.browser.msie&&b.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;G&&G.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();h=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');
F()}},I=function(){var a=o[q],c,g,k,C,P,w;N();e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));w=e.onStart(o,q,e);if(w===false)h=false;else{if(typeof w=="object")e=b.extend(e,w);k=e.title||(a.nodeName?b(a).attr("title"):a.title)||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?b(a).children("img:first"):b(a);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");c=e.href||(a.nodeName?b(a).attr("href"):a.href)||null;if(/^(?:javascript)/i.test(c)||
c=="#")c=null;if(e.type){g=e.type;if(!c)c=e.content}else if(e.content)g="html";else if(c)g=c.match(J)?"image":c.match(W)?"swf":b(a).hasClass("iframe")?"iframe":c.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){a=c