integrations tests questions

1 view
Skip to first unread message

Michal Burak

unread,
Nov 9, 2009, 12:10:07 PM11/9/09
to rubyonra...@googlegroups.com
Hi,

--- ROUTING ---
I have roting defined as RESTful but for the below testes MyModels
controller I have a standard

map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

---- SAMPLE TEST ------

class MyIntegrationTest < ActionController::IntegrationTest
fixtures :all

test "sample test" do
login_as_quentin

get '/my_models/new' #how do I avoid hard-coded paths?
assert_response 200

assert_difference('MyModel.count') do
post '/my_models/create', :my_model => my_models(:one).attributes
#how do I avoid hard-coded paths?
assert_redirected_to '/my_models/edit_photos/' #how do i specify
ID in here?
end
end
end


The questions are in the comments for the test.

Thanks in advance.

M.
--
Posted via http://www.ruby-forum.com/.

Michal Burak

unread,
Nov 9, 2009, 12:41:00 PM11/9/09
to rubyonra...@googlegroups.com
Ok, I have the answer figured out for the quesion "how to specify ID":

assert_redirected_to '/my_models/edit_photos/' +
assigns(:my_model).id.to_s


But I still dont know how to avoid hardcoded paths.

I want to replace:

get '/foo/bar'

with something like:

get :controller => :foo, :action => :bar

so that the integrations tests are "not routes.rb dependant".

Marnen Laibow-Koser

unread,
Nov 9, 2009, 2:04:05 PM11/9/09
to rubyonra...@googlegroups.com
Michal Burak wrote:
[...]

> The questions are in the comments for the test.

In my opinion, integration tests are a bit clumsy. Cucumber features
will be easier to work with, and will also address the issues you were
asking about.

>
> Thanks in advance.
>
> M.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

Michal Burak

unread,
Nov 9, 2009, 3:30:34 PM11/9/09
to rubyonra...@googlegroups.com
Marnen Laibow-Koser wrote:
> In my opinion, integration tests are a bit clumsy. Cucumber features
> will be easier to work with, and will also address the issues you were
> asking about.
>
>>
>> Thanks in advance.
>>
>> M.

Looks nice, I'll check it deeper. Thanks.

My fiend found another simpler solution:
http://programmers-blog.com/2009/11/09/rails-integration-tests-hardcoded-routes-problem

Reply all
Reply to author
Forward
0 new messages