gist:275616 · GitHub, which works fine when account is an
independent model, however I want:
an account to be a property of user, ( and created and associated when
a user is)
when the user goes to /account/edit it should on edit the account of
the logged in user -
I can make rails do this, but I’m utterly baffled how I should alter
this test to represent this new behaviour
I have a user Factory like this:
Factory.define :user do |user|
user.email { Factory.next :email }
user.password { “password” }
user.password_confirmation { “password” }
user.association :account
end
So maybe my set up should create one of those? Although that doesn’t
sound right if its an AccountController…
Either way, I’m confused, I am trying to do the right thing by all
this TDD, but its not making it easy…
Why? Cucumber features are generally nicer to work with than controller
tests.
which works fine when account is an
independent model, however I want:
an account to be a property of user, ( and created and associated when
a user is)
when the user goes to /account/edit it should on edit the account of
the logged in user -
Which authentication library are you using? They tend to have
instructions on testing. Generally, you’ll need to stub the
current_user method.
I can make rails do this, but I’m utterly baffled how I should alter
this test to represent this new behaviour
I have a user Factory like this:
Factory.define :user do |user|
user.email { Factory.next :email }
user.password { “password” }
user.password_confirmation { “password” }
user.association :account
end
So maybe my set up should create one of those? Although that doesn’t
sound right if its an AccountController…
The point of factories is to create the object you need, with all
associations. You need an Account with associated User.
Either way, I’m confused, I am trying to do the right thing by all
this TDD, but its not making it easy…
No, you’re not making it easy. The principle is to just create the
objects and stubs you need for your test. Often you can do this by
noticing where Rails is throwing errors.
I have a similar problem as I’m just getting into this BDD business. I
want to write a Cucumber test that refers to the current user by using
“I”. For example:
Given I am logged in as “noobie”
And I have 0 self-esteem
How do I make the connection between I and noobie. It’s easy but ugly to
figure out a workaround tho.
I have a similar problem as I’m just getting into this BDD business. I
want to write a Cucumber test that refers to the current user by using
“I”. For example:
Given I am logged in as “noobie”
And I have 0 self-esteem
How do I make the connection between I and noobie.
You don’t, really: “I” in a Cucumber step usually doesn’t refer to
anything specific. What you want is probably to use current_user or
whatever equivalent method your authentication library provides:
Given /I am logged in as “([^”]+)/ do |username|
login_as User.find_by_username(username) # or whatever method your
authentication library says you should use
end
Given /I have \d+ self-esteem/ do |n|
current_user.self_esteem = 0
end
If memory serves, the Cucumber docs deal with almost this exact case.
You might want to review them.
It’s easy but ugly to
figure out a workaround tho.
Given /I am logged in as “([^”]+)/ do |username|
login_as User.find_by_username(username) # or whatever method your
authentication library says you should use
end
Given /I have \d+ self-esteem/ do |n|
current_user.self_esteem = 0
end
This is something I’ve tried but it fails because of:
Given I am logged in as “admin” #
features/step_definitions/manage_logins_steps.rb:11
undefined method current_user' for #<ActionController::Integration::Session:0x7f08cb98> (NoMethodError) ./features/step_definitions/manage_logins_steps.rb:19:in/^I am
logged in as “([^”]*)"$/’
features/topside_menu.feature:13:in `Given I am logged in as
“admin”’
current_user is defined in the ApplicationController class and it’s set
as a helper_method, but apparently it’s still not visible in the Webrat
steps.
If memory serves, the Cucumber docs deal with almost this exact case.
You might want to review them.
Given /I am logged in as “([^”]+)/ do |username|
login_as User.find_by_username(username) # or whatever method your
authentication library says you should use
end
Given /I have \d+ self-esteem/ do |n|
current_user.self_esteem = 0
end
This is something I’ve tried but it fails because of:
Given I am logged in as “admin” #
features/step_definitions/manage_logins_steps.rb:11
undefined method current_user' for #<ActionController::Integration::Session:0x7f08cb98> (NoMethodError) ./features/step_definitions/manage_logins_steps.rb:19:in /^I am
logged in as “([^"]*)”$/’
features/topside_menu.feature:13:in `Given I am logged in as
“admin”’
current_user is defined in the ApplicationController class and it’s set
as a helper_method, but apparently it’s still not visible in the Webrat
steps.
So write a function somewhere in features/support that defines it.
If memory serves, the Cucumber docs deal with almost this exact case.
You might want to review them.