Skip to content

Commit

Permalink
Listings Index
Browse files Browse the repository at this point in the history
  • Loading branch information
richrines committed Nov 14, 2013
1 parent 0203db5 commit b9dd7b3
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
ruby '2.0.0'

gem 'airbrake'
gem "active_model_serializers"
gem 'bourbon'
gem 'carrierwave'
gem 'clearance'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ GEM
erubis (~> 2.7.0)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
active_model_serializers (0.8.1)
activemodel (>= 3.0)
activemodel (4.0.0)
activesupport (= 4.0.0)
builder (~> 3.1.0)
Expand Down Expand Up @@ -221,6 +223,7 @@ PLATFORMS
ruby

DEPENDENCIES
active_model_serializers
airbrake
better_errors
binding_of_caller
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/listings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ListingsController < ActionController::Base
def index
@listings = Listing.all
render json: @listings
end
end
5 changes: 5 additions & 0 deletions app/serializers/listing_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ListingSerializer < ActiveModel::Serializer
attributes :id, :active, :address, :bath_count, :bed_count, :floor_plan,
:neighborhood, :pmc, :rent, :square_feet, :url, :uuid
has_many :listing_images
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Renter::Application.routes.draw do
resources :listings, only: [:index]
end
41 changes: 41 additions & 0 deletions spec/controllers/listings_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'spec_helper'

describe ListingsController, '#index' do
it 'returns a json response of all of the listings' do
listing_image = create(:listing_image)

xhr :get, :index

expect(response.body).to eq(
{
"listings" => [
{
"id" => listing_image.listing.id,
"active" => listing_image.listing.active,
"address" => listing_image.listing.address,
"bath_count" => listing_image.listing.bath_count,
"bed_count" => listing_image.listing.bed_count,
"floor_plan" => listing_image.listing.floor_plan,
"neighborhood" => listing_image.listing.neighborhood,
"pmc" => listing_image.listing.pmc,
"rent" => listing_image.listing.rent,
"square_feet" => listing_image.listing.square_feet,
"url" => listing_image.listing.url,
"uuid" => listing_image.listing.uuid,
"listing_images" => [
{
"id" => listing_image.id,
"created_at" => listing_image.created_at,
"updated_at" => listing_image.updated_at,
"listing_id" => listing_image.listing.id,
"image" => {
"url" => nil,
}
}
]
}
]
}
)
end
end
10 changes: 9 additions & 1 deletion spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
"user#{n}@example.com"
end

sequence :address do |n|
"#{n} Fake Street"
end

factory :listing_image do
listing
end

factory :listing do
active true
address '123 Fake Street'
address
bath_count 3.0
bed_count 2.0
floor_plan 'a1'
Expand Down

0 comments on commit b9dd7b3

Please sign in to comment.