Given I am signed up
And an app exists with user: me
And a component exists with name: "Component name to update", app:
that app
to
Given I am signed up
And a component exists with name: "Component name to update", app:
mine
(component belongs_to an app and app belongs_to a user).
My factories are as follows:
Factory.define :app do |a|
a.name 'App X'
a.url 'http://example.com'
a.association :user
end
Factory.define :mine, :parent => :app do |u|
u.name "Andy's App"
u.user :me
end
Factory.define :me, :parent => :user do |u|
u.name 'Andy'
u.email_address 'an...@example.com'
end
Factory.define :component do |c|
c.sequence(:name) {|n| "Component #{n}" }
c.association :app
end
but when I try run the shorter version is seems that app isn't being
set, since the validation fails with "App can't be blank".
Any ideas what could be going wrong?
Andy
Given a company exists with name: "my awesome company"
And a user exists with email: "f...@example.com", password: "insecure",
company: that company
And I log in with....
But it doesn't seem to b making the association, as
current_user.company is nil according to ruby debug, but it is working
fine in my controller spec. What is the correct (or simpler) way to do
this. Thanks
On Jan 17, 8:29 am, Andy Wate <andywa...@gmail.com> wrote:
> Hi, I'm trying to find a way shorten
>
> Given I am signed up
> And an app exists with user: me
> And a component exists with name: "Component name to update", app:
> that app
>
> to
>
> Given I am signed up
> And a component exists with name: "Component name to update", app:
> mine
>
> (component belongs_to an app and app belongs_to a user).
>
> My factories are as follows:
>
> Factory.define :app do |a|
> a.name 'App X'
> a.url 'http://example.com'
> a.association :user
> end
>
> Factory.define :mine, :parent => :app do |u|
> u.name "Andy's App"
> u.user :me
> end
>
> Factory.define :me, :parent => :user do |u|
> u.name 'Andy'
> u.email_address 'a...@example.com'
Andy
Scenario: Creating a client adds them to a user's company
Given a user "joe" has registered with "joe....@example.com",
"test01"
And a company "My Company" exists with name: "My Awesome Company"
And I login with "joe....@example.com", "test01"
And I am on the list of clients
When I follow "Add New Client"
When I fill in "Name" with "My Fav Client"
And I press "Create"
Then a client should exist with name: "My Fav Client"
And a client should be in the company's clients
The error
And I press "Create"
undefined method `clients' for nil:NilClass
The controller
def create
@client = Client.new(params[:client])
current_user.company.clients << @client
if current_user.save
flash[:notice] = "Added: #{@client.name}"
redirect_to clients_url
else
render :action => :new
end
end
The Factories
Factory.define :user do |f|
f.first_name "John"
f.last_name "Smith"
f.password "test123"
f.password_confirmation {|u| u.password}
f.email "f...@example.com"
end
Factory.define :client do |f|
f.name "My Fav Client"
end
Factory.define :company do |f|
f.name "My Company"
end
Factory.define :account do |f|
end
I am like new-born baby new to Rspec, Cucumber, Pickle (get it Ian...
"newborn"? Lame joke...) So any pointers on redo-ing anything would be
greatly appreciated.
Thanks
Frank