Forum: Ruby on Rails How to remove duplication for similar behaviour?

Posted by guirec c. (guirec_c)
on 2012-12-03 16:04
(Received via mailing list)
Hello,

On a website I created the is two commentable model, "project" and
"actuality". You can view pages here :
http://comment-my-projects.herokuapp.com/projects/... 
and
here :
http://comment-my-projects.herokuapp.com/projects/...
in french for the momeent).

At the end of each page there is a form to create a new comment and a 
list
for all comments. They have the same behaviour and they use the same
partials. My problem is for specs. I created two specs. Here :
https://github.com/GCorbel/comment-my-projects/blo...
here :
https://github.com/GCorbel/comment-my-projects/blo....
There is a duplication and I want, if it's possible, to have only one 
spec
for this.

I tried to create an engine but I'm not satisfied. The behaviour is 
really
related to my application. For example, I have this inherited routes 
like
this :

  resources :actualities do
    resources :comments
  end

  resources :projects do
    resources :comments
  end


If I try to put only "resources :comments" it break my controller's 
code.
To find the related model I must to add the class name into the params. 
I
didn't find another solution and I think it's uggly.

Do you have and Idea? Is it better to have two specs for a similar 
feature
or is it better to remove an spec and keep the other?

Thanks for your help!
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.