Skip to content

Commit

Permalink
tests for partial variables decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Nov 30, 2011
1 parent aac7959 commit b2aff18
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/fake_app/authors/index.html.erb
@@ -1,4 +1,16 @@
<% @authors.each do |author| %>
<%= author.name %>
<%= author.reverse_name %>
<% if params[:partial] == 'collection' %>
<%= render author.books %>
<% elsif params[:partial] == 'locals' %>
<% author.books.each do |book| %>
<%= render :partial => 'books/book_locals', :locals => {:b => book} %>
<% end %>
<% else %>
<% author.books.each do |book| %>
<%= render book %>
<% end %>
<% end %>
<% end %>
2 changes: 2 additions & 0 deletions spec/fake_app/books/_book.html.erb
@@ -0,0 +1,2 @@
<%= book.title %>
<%= book.reverse_title %>
2 changes: 2 additions & 0 deletions spec/fake_app/books/_book_locals.html.erb
@@ -0,0 +1,2 @@
<%= b.title %>
<%= b.upcased_title %>
9 changes: 9 additions & 0 deletions spec/fake_app/fake_app.rb
Expand Up @@ -39,6 +39,15 @@ def capitalized_name
name.capitalize
end
end
module BookDecorator
def reverse_title
title.reverse
end

def upcased_title
title.upcase
end
end

# controllers
class ApplicationController < ActionController::Base
Expand Down
31 changes: 31 additions & 0 deletions spec/requests/partial_spec.rb
@@ -0,0 +1,31 @@
require 'spec_helper'

feature 'decorating partial object' do
background do
Author.create! :name => 'aamine'
nari = Author.create! :name => 'nari'
nari.books.create! :title => 'the gc book'
end
after do
Book.delete_all
Author.delete_all
end

scenario 'decorating implicit @object' do
visit '/authors'
page.should have_content 'the gc book'
page.should have_content 'the gc book'.reverse
end

scenario 'decorating implicit @collection' do
visit '/authors?partial=collection'
page.should have_content 'the gc book'
page.should have_content 'the gc book'.reverse
end

scenario 'decorating objects in @locals' do
visit '/authors?partial=locals'
page.should have_content 'the gc book'
page.should have_content 'the gc book'.upcase
end
end

0 comments on commit b2aff18

Please sign in to comment.