Skip to content

Commit

Permalink
tests for controller variable decoration
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Nov 30, 2011
1 parent 8a8bea5 commit aac7959
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spec/fake_app/authors/index.html.erb
@@ -0,0 +1,4 @@
<% @authors.each do |author| %>
<%= author.name %>
<%= author.reverse_name %>
<% end %>
2 changes: 2 additions & 0 deletions spec/fake_app/authors/show.html.erb
@@ -0,0 +1,2 @@
<%= @author.name %>
<%= @author.capitalized_name %>
29 changes: 29 additions & 0 deletions spec/fake_app/fake_app.rb
Expand Up @@ -29,6 +29,35 @@ class Book < ActiveRecord::Base
# helpers
module ApplicationHelper; end

# decorators
module AuthorDecorator
def reverse_name
name.reverse
end

def capitalized_name
name.capitalize
end
end

# controllers
class ApplicationController < ActionController::Base
self.append_view_path File.dirname(__FILE__)
end
class AuthorsController < ApplicationController
def index
if params[:variable_type] == 'array'
@authors = Author.all
else
@authors = Author.scoped
end
end

def show
@author = Author.find params[:id]
end
end

# migrations
class CreateAllTables < ActiveRecord::Migration
def self.up
Expand Down
29 changes: 29 additions & 0 deletions spec/requests/controller_ivar_spec.rb
@@ -0,0 +1,29 @@
require 'spec_helper'

feature 'decorating controller ivar' do
background do
@matz = Author.create! :name => 'matz'
Author.create! :name => 'takahashim'
end
after do
Author.delete_all
end

scenario 'decorating a model object in ivar' do
visit "/authors/#{@matz.id}"
page.should have_content 'matz'
page.should have_content 'matz'.capitalize
end

scenario 'decorating model scope in ivar' do
visit '/authors'
page.should have_content 'takahashim'
page.should have_content 'takahashim'.reverse
end

scenario "decorating models' array in ivar" do
visit '/authors?variable_type=array'
page.should have_content 'takahashim'
page.should have_content 'takahashim'.reverse
end
end

0 comments on commit aac7959

Please sign in to comment.