Skip to content

Commit

Permalink
rails 3 swollen method replaced with render
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Aug 30, 2010
1 parent e3e6eb4 commit f9e7304
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
5 changes: 4 additions & 1 deletion lib/restfulie/server/action_controller/base.rb
Expand Up @@ -36,7 +36,10 @@ def include_restfulie?
def render(options = nil, extra_options = {}, &block)
if options && atom = options[:atom]
response.content_type ||= Mime::ATOM
render_for_text(atom.respond_to?(:to_atom) ? atom.to_atom.to_xml : atom.to_xml, options[:status])
representation = atom.respond_to?(:to_atom) ? atom.to_atom.to_xml : atom.to_xml
options[:text] = representation
options[:atom] = nil
render options
else
super
end
Expand Down
15 changes: 15 additions & 0 deletions tests/app/controllers/render_controller.rb
@@ -0,0 +1,15 @@
class RenderController < ApplicationController
include Restfulie::Server::ActionController::Base

def index
render :atom => [AtomifiedModel.new, AtomifiedModel.new, AtomifiedModel.new]
end

def show
render :atom => AtomifiedModel.new
end

def show_with_mock
render :atom => object
end
end
2 changes: 2 additions & 0 deletions tests/app/helpers/render_helper.rb
@@ -0,0 +1,2 @@
module RenderHelper
end
25 changes: 2 additions & 23 deletions tests/spec/controllers/integration/controller_base_spec.rb
@@ -1,31 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require "action_controller"

class BaseController < ::ActionController::Base
include Restfulie::Server::ActionController::Base

def index
render :atom => [AtomifiedModel.new, AtomifiedModel.new, AtomifiedModel.new]
end

def show
render :atom => AtomifiedModel.new
end

def show_with_mock
render :atom => object
end
end

ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end

describe Restfulie::Server::ActionController::Base, :type => :controller do
tests BaseController
describe RenderController do

before(:each) do
@object = mock("ModelWithToAtom")
@object = Object.new
@controller.stub!(:object).and_return(@object)
end

Expand Down
14 changes: 14 additions & 0 deletions tests/spec/helpers/render_helper_spec.rb
@@ -0,0 +1,14 @@
require 'spec_helper'

# Specs in this file have access to a helper object that includes
# the RenderHelper. For example:
#
# describe RenderHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe RenderHelper do
end
6 changes: 5 additions & 1 deletion tests/spec/support/atomified_model.rb
Expand Up @@ -15,7 +15,11 @@ def to_atom(options={})
entry.id = "entry1"
entry.title = "entry"
entry.updated = Time.parse("2010-05-03T16:29:26Z")
entry.published = Time.parse("2010-05-03T16:29:26Z")
entry.published = published_at
entry
end

def published_at
Time.parse("2010-05-03T16:29:26Z")
end
end

0 comments on commit f9e7304

Please sign in to comment.