Sha256: 9407f5931e82c181eaa06bf925a8db1cdc56154fb0f072b0e4d64dcb151c10db
Contents?: true
Size: 1.21 KB
Versions: 4
Compression:
Stored size: 1.21 KB
Contents
require 'test_helper' class RenderTest < ActionController::TestCase include Roar::Rails::TestCase class SingersController < ActionController::Base module SingerRepresenter include Roar::JSON property :name, :as => :title end module SingersRepresenter include Representable::JSON::Collection items :extend => SingerRepresenter end include Roar::Rails::ControllerAdditions include Roar::Rails::ControllerAdditions::Render represents :json, :entity => SingerRepresenter, :collection => SingersRepresenter def show singer = Musician.new("Bumi") render :json => singer, status: 201 end def index singers = [Musician.new("Bumi"), Musician.new("Iggy")] render :json => singers, status: 201 end end tests SingersController test "should use Representer for #render" do get :show, :id => "bumi", :format => :json assert_equal response.body, '{"title":"Bumi"}' assert_equal 201, response.status end test "should use Representer for #render on a model collection" do get :index, :format => :json assert_equal response.body, '[{"title":"Bumi"},{"title":"Iggy"}]' assert_equal 201, response.status end end
Version data entries
4 entries across 4 versions & 2 rubygems