Created
August 23, 2012 14:14
-
-
Save jferris/3437037 to your computer and use it in GitHub Desktop.
Testing views without helpers or decorators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <li class='<%= 'complete' if todo.complete? %>' id='<%= dom_id todo %>'> | |
| <%= todo.description %> | |
| <% if todo.completed_at? -%> | |
| <%= link_to 'Incomplete', todo_completion_path(todo), method: :delete %> | |
| <% else -%> | |
| <%= link_to 'Complete', todo_completion_path(todo), method: :post %> | |
| <% end -%> | |
| </li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <ul id='my-todos'> | |
| <%= render @todos %> | |
| </ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe 'todos/_todo.html.erb' do | |
| it 'generates a link to complete the todo when incomplete' do | |
| todo = build_stubbed(:todo) | |
| page = render_todo(todo) | |
| page.should have_css( | |
| "a[data-method='post'][href='#{todo_completion_path(todo)}']", | |
| text: 'Complete' | |
| ) | |
| end | |
| it 'generates a link to mark the todo as incomplete when complete' do | |
| todo = build_stubbed(:todo, :completed) | |
| page = render_todo(todo) | |
| page.should have_css( | |
| "a[data-method='delete'][href='#{todo_completion_path(todo)}']", | |
| text: 'Incomplete' | |
| ) | |
| end | |
| def render_todo(todo) | |
| render partial: 'todos/todo', locals: { todo: todo } | |
| Capybara.string(rendered) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment