Apparently I have a unique situation that I can’t find help with anywhere. I’m trying to extend my sign up process to create extra models in my database. Here is a basic flow of what I’d like to do:
- User Signs up with Email/Password (along with other model values)
- System creates a ‘User’ model
- System creates a ‘Profile’ model
- System creates a ‘Company’ model
- System creates an ‘Account’ model
The biggest challenge is that I’m using Devise and I can’t seem to figure out a way to test this functionality with Rspec. Here is a quick view of me simply trying to test the ‘Sign Up’ method (which does not work:
describe "New Users" do
describe "signing up" do
it "should create a new user" do
lambda do
post :sign_up, :user => Factory.attributes_for(:user)
response.should be_success
end.should change(User, :count).by(1)
end
end
end
I get the following error:
1) UsersController New Users signing up should create a new user
Failure/Error: post :sign_up, :user => Factory.attributes_for(:user)
ActionController::RoutingError:
No route matches {:user=>{:email=>"test@user.com", :password=>"secret", :password_confirmation=>"secret"}, :controller=>"users", :action=>"sign_up"}
# ./spec/controllers/users_controller_spec.rb:14:in `block (5 levels) in <top (required)>'
# ./spec/controllers/users_controller_spec.rb:13:in `block (4 levels) in <top (required)>'
The Devise routes configure my user sign up routes as follows:
new_user_registration GET /users/sign_up(.:format) {:action=>"new", :controller=>"devise/registrations"}
I’ve been pulling my hair out with this, and can’t seem to find any help in this area. Perhaps I’m approaching it wrong, but I want to configure all the aspects of setting up a user’s account (ie. their company defaults, profile settings, etc..) on the initial sign up form. First I need to just figure out how to test the sign up process.
Thanks in advance!
First of all the routes you should link to is, because devise are using a POST method for sign-up:
Maybe you can try pass there syntax such as:
EDIT
Ok then, I maybe figure out how to solve the route problem, I added a new controller:
and also added there method sign_up. Then in routes.rb I added this code:
and finally this line before the test into the test:
But I have there problem with validations, but I think it is for my app because I just made it in new branch on existing system. Hope it could help you. Nevertheless, I think this approach is quite hack or not common. I would rather go with recommended Devise approach. You can always create an user dependencies with FactoryGirl viz this link. Hope it will help you.
BTW Sry for the nonsense post about sign in:) I was tired:)