Skip to content

Commit

Permalink
Creating toilets#show
Browse files Browse the repository at this point in the history
  • Loading branch information
tapajos committed Jul 22, 2010
1 parent 455edab commit 7a2ad88
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
6 changes: 5 additions & 1 deletion app/controllers/toilets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
class ToiletsController < ApplicationController

def index
@toilets = Toilet.all
@toilets = Toilet.all_to_json
respond_to do |format|
format.json { render :json => @toilets }
end
end

def show
@toilet = Toilet.all.detect{|toilet| toilet["lat_long"] == params["id"]}
end

end
6 changes: 5 additions & 1 deletion app/models/toilet.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Toilet

def self.all
def self.all_to_json
YAML.load(File.read("#{RAILS_ROOT}/db/toilets.yml")).map do |toilet|
result = {}
result["latitude"] = toilet["lat_long"].split(",").first.to_f
Expand All @@ -9,4 +9,8 @@ def self.all
end
end

def self.all
YAML.load(File.read("#{RAILS_ROOT}/db/toilets.yml"))
end

end
1 change: 1 addition & 0 deletions app/views/toilets/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Aqui vai ficar bem feito
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# admin.resources :products
# end

map.resources :toilets, :only => ["index"]
map.resources :toilets, :only => ["index", "show"]

# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
# map.root :controller => "toilets"
Expand Down
4 changes: 3 additions & 1 deletion db/toilets.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
- lat_long: "-30.059140,-51.175904"
description: "Descrição do banheiro"
- lat_long: "30.059047,-51.173013"
description: "Descrição do banheiro2"
- lat_long: "-30.06031,-51.173646"
- lat_long: "-30.06031,-51.173646"
description: "Descrição do banheiro3"
- lat_long: "-30.055973,-51.174898"
11 changes: 10 additions & 1 deletion spec/controllers/toilets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@
end

it "should assign @toilets" do
assigns(:toilets).should == [{"latitude"=>-30.05914, "longitude"=>-51.175904}, {"latitude"=>30.059047, "longitude"=>-51.173013}, {"latitude"=>-30.06031, "longitude"=>-51.173646}, {"latitude"=>-30.06031, "longitude"=>-51.173646}, {"latitude"=>-30.055973, "longitude"=>-51.174898}]
assigns(:toilets).should == [{"latitude"=>-30.05914, "longitude"=>-51.175904}, {"latitude"=>30.059047, "longitude"=>-51.173013}, {"latitude"=>-30.06031, "longitude"=>-51.173646}, {"latitude"=>-30.055973, "longitude"=>-51.174898}]
end

end

describe "show" do

it "should return toilet from lat_long" do
get :show, :id => "-30.059140,-51.175904"
assigns(:toilet).should == {"lat_long"=>"-30.059140,-51.175904", "description" => "Descrição do banheiro"}
end

end

end
10 changes: 9 additions & 1 deletion spec/models/toilet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
describe ".all" do

it "should return all toilets" do
Toilet.all.should == [{"latitude"=>-30.05914, "longitude"=>-51.175904}, {"latitude"=>30.059047, "longitude"=>-51.173013}, {"latitude"=>-30.06031, "longitude"=>-51.173646}, {"latitude"=>-30.06031, "longitude"=>-51.173646}, {"latitude"=>-30.055973, "longitude"=>-51.174898}]
Toilet.all.should == [{"lat_long"=>"-30.059140,-51.175904", "description"=>"Descrição do banheiro"}, {"lat_long"=>"30.059047,-51.173013", "description"=>"Descrição do banheiro2"}, {"lat_long"=>"-30.06031,-51.173646", "description"=>"Descrição do banheiro3"}, {"lat_long"=>"-30.055973,-51.174898"}]
end

end

describe ".all_to_json" do

it "should return all toilets" do
Toilet.all_to_json.should == [{"latitude"=>-30.05914, "longitude"=>-51.175904}, {"latitude"=>30.059047, "longitude"=>-51.173013}, {"latitude"=>-30.06031, "longitude"=>-51.173646}, {"latitude"=>-30.055973, "longitude"=>-51.174898}]
end

end
Expand Down

0 comments on commit 7a2ad88

Please sign in to comment.