rabl-rails/test/non_restful_response_test.rb

35 lines
1022 B
Ruby
Raw Normal View History

2012-03-15 14:12:52 +00:00
require 'test_helper'
class NonRestfulResponseTest < ActiveSupport::TestCase
setup do
2012-04-20 14:28:34 +00:00
RablRails::Library.reset_instance
2012-04-15 16:17:49 +00:00
2012-03-15 14:12:52 +00:00
@user = User.new(1, 'foo', 'male')
@user.stub_chain(:posts, :count).and_return(10)
@user.stub(:respond_to?).with(:each).and_return(false)
2012-04-15 16:17:49 +00:00
2012-03-15 14:12:52 +00:00
@context = Context.new
@context.stub(:instance_variable_get).with(:@user).and_return(@user)
@context.stub(:instance_variable_get).with(:@virtual_path).and_return('user/show')
@context.stub(:instance_variable_get).with(:@_assigns).and_return({'user' => @user})
2012-04-15 16:17:49 +00:00
@context.stub(:lookup_context)
2012-03-15 14:12:52 +00:00
end
2012-04-15 16:17:49 +00:00
2012-03-15 14:12:52 +00:00
test "compile and render non restful resource" do
source = %{
object false
node(:post_count) { @user.posts.count }
child(:@user => :user) do
attributes :id, :name
end
}
2012-04-15 16:17:49 +00:00
2012-07-24 10:13:01 +00:00
assert_equal(MultiJson.encode({
2012-03-15 14:12:52 +00:00
:post_count => 10,
:user => {
:id => 1,
:name => 'foo'
}
2012-04-20 14:28:34 +00:00
}), RablRails::Library.instance.get_rendered_template(source, @context))
2012-03-15 14:12:52 +00:00
end
end