Created
July 20, 2012 14:31
-
-
Save Govinda-Fichtner/3151041 to your computer and use it in GitHub Desktop.
Strange behaviour with response.body in rspec controller tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
require "spec_helper" | |
describe Api::V1::ImagesController do | |
context "on GET to :index" do | |
before do | |
FactoryGirl.create_list(Image, 2) | |
end | |
it "should find the strange rabl behaviour" do | |
get :index, :format => :json | |
response_images = JSON.parse(response.body) | |
response_images.should == [{"image"=>{}}] | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::V1::ImagesController < Api::V1::BaseController | |
def index | |
respond_with(@images = Image.all) | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
collection @images | |
extends 'api/v1/images/show' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object @image | |
attributes :id, | |
:file_width, | |
:file_height, | |
:file_file_size, | |
:file_content_type, | |
:file_resolution, | |
:file_colorspace, | |
:file_depth, | |
:file_aspect_ratio, | |
:file_chromaticity, | |
:file_created_at, | |
:description, | |
:tags, | |
:campaigns, | |
:origin_reference, | |
:licence_note, | |
:licence_expiration_at, | |
:last_used_at, | |
:created_at, | |
:updated_at | |
node :file_name do |i| | |
i.filename | |
end | |
node :status do |i| | |
i.status == 0 ? I18n.t("images_edit.statuses.inactive") : I18n.t("images_edit.statuses.active") | |
end | |
node :client, :if => lambda { |i| i.client.present? } do |i| | |
i.client.name | |
end | |
node :licencetype do |i| | |
i.licencetype.present? ? I18n.t("licencetype.licencetypes.#{i.licencetype.name}") : nil | |
end | |
node :origin do |i| | |
i.origin.present? ? I18n.t("origin.origins.#{i.origin.name}") : nil | |
end | |
node :category do |i| | |
I18n.t("image_categories.#{i.category}") | |
end | |
node(:user_id, :if => lambda { |i| i.category == 'user_images' }) do |i| | |
i.user_id | |
end | |
node(:image_type, :if => lambda { |i| i.category == 'user_images' }) do |i| | |
i.image_type.present? ? i.image_type.name : nil | |
end | |
node :thumb_url do |i| | |
api_v1_thumb_image_download_url(i) | |
end | |
node :preview_url do |i| | |
api_v1_preview_image_download_url(i) | |
end | |
node :original_url do |i| | |
api_v1_original_image_download_url(i) | |
end | |
node :original_fs_path do |i| | |
i.file.current_path | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment