Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems testing edit action for user_controller #2

Closed
wikimatze opened this issue Mar 20, 2014 · 1 comment
Closed

Problems testing edit action for user_controller #2

wikimatze opened this issue Mar 20, 2014 · 1 comment

Comments

@wikimatze
Copy link
Collaborator

The controller:

JobVacancy::App.controllers :users do
   before :edit, :update  do
     redirect('/login') unless signed_in?
     @user = User.find_by_id(params[:id])
     redirect('/login') unless current_user?(@user)
   end

  get :edit, :map => '/users/:id/edit' do
    @user = User.find_by_id(params[:id])
    render 'users/edit'
  end

  put :update, :map => '/users/:id' do
    @user = User.find_by_id(params[:id])

    unless @user
      flash[:error] = "User is not registered in our platform."
      render 'users/edit'
    end

    if @user.update_attributes(params[:user])
      flash[:notice] = "You have updated your profile."
      render 'users/edit'
    else
      flash[:error] = "Your profile was not updated."
      render 'users/edit'
    end
  end
end

The spec

require 'spec_helper'

describe "UsersController" do
  describe "GET edit" do
    let(:user) { build(:user) }

    it "render the view for editing a user" do
      User.should_receive(:find_by_id).at_least(:once).with(anything()).and_return(user)

      get "/users/#{user.id}/edit"
      # I come to this point but the last response is not okay but and routing error, as you can see in the output next to this code example

      require 'pry'; binding.pry

      last_response.should be_ok
    end
  end
end

The output of the last_response is:

#<Rack::MockResponse:0xbad94ad0
 @block=nil,
 @body=
  ["<!DOCTYPE html>\n<html>\n<head>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n  <title>Padr
 @body_string=nil,
 @chunked=false,
 @errors=
  "Padrino::Routing::UnrecognizedException - route mapping for url(:\"users edit\") could not be found!:\n\t/home/wikimatze/.g
 @header=
  {"Content-Type"=>"text/html",
   "Content-Length"=>"233416",
   "Set-Cookie"=>
    "rack.session=BAh7CUkiD3Nlc3Npb25faWQGOgZFVEkiRTQyOTAyNDQ0MGU4MmM3MDgxZWZk%0AZjRjZGQwODFjMWFmOTEwMGFkMWVhZjI5OTk2NjM2MTE5M
 @length=233416,
 @original_headers=
  {"Content-Type"=>"text/html",
   "Content-Length"=>"233416",

I even turned of the the csrf protection in config/apps.rb

Padrino.configure_apps do
  # enable :sessions
#  set :session_secret, '6a3ec199b53b002a3bfaf60ec746b9182c095950b41f182790a81a0e36d96884'
#  set :protection, true
#  set :protect_from_csrf, true
end

It is working if I run the application.

MatzFan added a commit to MatzFan/job-vacancy that referenced this issue Dec 15, 2014
@MatzFan
Copy link
Contributor

MatzFan commented Dec 15, 2014

just sent PR to fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants