I have following route:
GET /confirm/:token(.:format) Confirmations#confirm
Controller:
class ConfirmationsController < ApplicationController
# GET /confirm/<token>
def confirm
@user = User.find_by_email_token(params[:token])
if @user
@user.confirmed = true
@user.email_token = nil
@user.save!
sign_in @user
redirect_to root_url, flash: { success: "Welcome <#{@user.email}>, your address has been verified." }
elsif
redirect_to root_url, flash: { error: "Error: could not find matching user record." }
end
end
end
And this simple confirmations_controller_spec.rb:
require 'spec_helper'
describe ConfirmationsController do
let(:user) { FactoryGirl.create(:user, email_token: "some_token") }
describe "Get confirm" do
it "confirms user with valid email_token" do
get :confirm, token: "some_token"
assigns(:user).should eq(user)
user.reload.email_token.should be_nil
end
it "does not confirm user with invalid email_token"
end
end
but it fails:
1) ConfirmationsController Get confirm confirms user with valid email_token
Failure/Error: get :confirm, token: "some_token"
ActionController::RoutingError:
No route matches {:token=>"some_token", :controller=>"confirmations", :action=>"confirm"}
# ./spec/controllers/confirmations_controller_spec.rb:9:in `block (3 levels) in <top (required)>'
Anyone see what (could be multiple things) I screwed up?
BTW- I’m using a get request here (as opposed to put) because it’s being initiated from a text based email so we can’t, to my understanding, use a put request…
In your rake routes,
Confirmationsshould not have a capital letter.Can you define the route like so in
config/routes.rb: