diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 80 | ||||
-rw-r--r-- | spec/fixtures/public_bodies.yml | 19 | ||||
-rw-r--r-- | spec/fixtures/users.yml | 10 |
3 files changed, 102 insertions, 7 deletions
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 1195db34f..41ff2b6b6 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -17,10 +17,84 @@ describe RequestController, "when listing all requests" do # XXX probably should load more than one page of requests into db here :) get :list - assigns[:info_requests] == [ - info_requests(:fancy_dog_request), - info_requests(:naughty_chicken_request) + assigns[:info_requests].should == [ + info_requests(:naughty_chicken_request), # reverse-chronological order + info_requests(:fancy_dog_request) ] end +end + +describe RequestController, "when showing one request" do + fixtures :info_requests + + it "should be successful" do + get :show, :id => 101 + response.should be_success + end + + it "should render with 'show' template" do + get :show, :id => 101 + response.should render_template('show') + end + + it "should assign the request" do + get :show, :id => 101 + assigns[:info_request].should == info_requests(:fancy_dog_request) + end +end + +# XXX do this for invalid ids +# it "should render 404 file" do +# response.should render_template("#{RAILS_ROOT}/public/404.html") +# response.headers["Status"].should == "404 Not Found" +# end + +describe RequestController, "when creating a new request" do + fixtures :info_requests, :public_bodies, :users + + it "should render with 'new' template" do + get :new + response.should render_template('new') + end + + it "should accept a public body parameter posted from the front page" do + post :new, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id } + assigns[:info_request].public_body.should == public_bodies(:geraldine_public_body) + response.should render_template('new') + end + + it "should give an error and render 'new' template when a summary isn't given" do + post :create, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id + }, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." } + response.should render_template('new') + end + + it "should redirect to sign in page when input is good and nobody is logged in" do + post :create, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id, + :title => "Why is your quango called Geraldine?"}, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." } + response.should redirect_to(:controller => 'user', :action => 'signin') + end + it "should create the request and outgoing message and redirec to request page when input is good and somebody is logged in" do + session[:user] = users(:bob_smith_user) + post :create, :info_request => { :public_body_id => public_bodies(:geraldine_public_body).id, + :title => "Why is your quango called Geraldine?"}, + :outgoing_message => { :body => "This is a silly letter. It is too short to be interesting." } + ir_array = InfoRequest.find(:all, :conditions => ["title = ?", "Why is your quango called Geraldine?"]) + ir_array.size.should == 1 + ir = ir_array[0] + ir.outgoing_messages.size.should == 1 + om = ir.outgoing_messages[0] + om.body.should == "This is a silly letter. It is too short to be interesting." + response.should redirect_to(:controller => 'request', :action => 'show', :id => ir.id) + end end + + + + + + + diff --git a/spec/fixtures/public_bodies.yml b/spec/fixtures/public_bodies.yml index fe0b8b4f4..c8d95afc6 100644 --- a/spec/fixtures/public_bodies.yml +++ b/spec/fixtures/public_bodies.yml @@ -1,12 +1,23 @@ -new_public_body: +geraldine_public_body: name: The Geraldine Quango updated_at: 2007-10-24 10:51:01.161639 last_edit_comment: Mark named this stupid quango. - complaint_email: "" - request_email: francis@flourish.org + complaint_email: geraldine-complaints@localhost + request_email: geraldine-requests@localhost id: "2" version: "1" - last_edit_editor: "*unknown*" + last_edit_editor: "mark" short_name: TGQ created_at: 2007-10-24 10:51:01.161639 +humpadink_public_body: + name: "Department for Humpadinking" + updated_at: 2007-10-25 10:51:01.161639 + last_edit_comment: Not sure what this new department does. + complaint_email: humpadink-complaints@localhost + request_email: humpadink-requests@localhost + id: "3" + version: "1" + last_edit_editor: "francis" + short_name: DfH + created_at: 2007-10-25 10:51:01.161639 diff --git a/spec/fixtures/users.yml b/spec/fixtures/users.yml new file mode 100644 index 000000000..c28c67de2 --- /dev/null +++ b/spec/fixtures/users.yml @@ -0,0 +1,10 @@ +bob_smith_user: + id: "1" + name: Bob Smith + email: bob@localhost + salt: "-6116981980.392287733335677" + hashed_password: 6b7cd45a5f35fd83febc0452a799530398bfb6e8 # jonespassword + updated_at: 2007-10-31 10:39:15.491593 + created_at: 2007-10-31 10:39:15.491593 + + |