Skip to content

Commit

Permalink
added destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Ramallo + Galen Sanford committed Jan 28, 2012
1 parent df62ff5 commit d0e857b
Show file tree
Hide file tree
Showing 17 changed files with 450 additions and 1 deletion.
83 changes: 83 additions & 0 deletions app/controllers/destinations_controller.rb
@@ -0,0 +1,83 @@
class DestinationsController < ApplicationController
# GET /destinations
# GET /destinations.xml
def index
@destinations = Destination.all

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @destinations }
end
end

# GET /destinations/1
# GET /destinations/1.xml
def show
@destination = Destination.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @destination }
end
end

# GET /destinations/new
# GET /destinations/new.xml
def new
@destination = Destination.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @destination }
end
end

# GET /destinations/1/edit
def edit
@destination = Destination.find(params[:id])
end

# POST /destinations
# POST /destinations.xml
def create
@destination = Destination.new(params[:destination])

respond_to do |format|
if @destination.save
format.html { redirect_to(@destination, :notice => 'Destination was successfully created.') }
format.xml { render :xml => @destination, :status => :created, :location => @destination }
else
format.html { render :action => "new" }
format.xml { render :xml => @destination.errors, :status => :unprocessable_entity }
end
end
end

# PUT /destinations/1
# PUT /destinations/1.xml
def update
@destination = Destination.find(params[:id])

respond_to do |format|
if @destination.update_attributes(params[:destination])
format.html { redirect_to(@destination, :notice => 'Destination was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @destination.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /destinations/1
# DELETE /destinations/1.xml
def destroy
@destination = Destination.find(params[:id])
@destination.destroy

respond_to do |format|
format.html { redirect_to(destinations_url) }
format.xml { head :ok }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/destinations_helper.rb
@@ -0,0 +1,2 @@
module DestinationsHelper
end
2 changes: 2 additions & 0 deletions app/models/destination.rb
@@ -0,0 +1,2 @@
class Destination < ActiveRecord::Base
end
11 changes: 11 additions & 0 deletions app/views/destinations/index.html.haml
@@ -0,0 +1,11 @@
%h1 Destinations

%ul
-@destinations.each do |destination|
%li
= link_to destination.title, destination_path(destination)


- if current_user.admin?
= link_to t('.new') , new_destination_path

3 changes: 3 additions & 0 deletions config/locales/diaspora/en.yml
Expand Up @@ -1055,6 +1055,9 @@ en:
xrd_fetch_failed: "there was an error getting the xrd from account %{account}"
not_enabled: "webfinger does not seem to be enabled for %{account}'s host"
no_person_constructed: "No person could be constructed from this hcard."
destinations:
index:
new: "New destination"



2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -15,6 +15,8 @@
end
end

resources :destinations

resources :places do
resources :photos
end
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20120128024410_create_destinations.rb
@@ -0,0 +1,15 @@
class CreateDestinations < ActiveRecord::Migration
def self.up
create_table :destinations do |t|
t.text :summary
t.string :title
t.string :photo_url

t.timestamps
end
end

def self.down
drop_table :destinations
end
end
10 changes: 9 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120127191343) do
ActiveRecord::Schema.define(:version => 20120128024410) do

create_table "account_deletions", :force => true do |t|
t.string "diaspora_handle"
Expand Down Expand Up @@ -128,6 +128,14 @@
t.string "website"
end

create_table "destinations", :force => true do |t|
t.text "summary"
t.string "title"
t.string "photo_url"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "invitations", :force => true do |t|
t.text "message"
t.integer "sender_id"
Expand Down
164 changes: 164 additions & 0 deletions spec/controllers/destinations_controller_spec.rb
@@ -0,0 +1,164 @@
require 'spec_helper'

# This spec was generated by rspec-rails when you ran the scaffold generator.
# It demonstrates how one might use RSpec to specify the controller code that
# was generated by Rails when you ran the scaffold generator.
#
# It assumes that the implementation code is generated by the rails scaffold
# generator. If you are using any extension libraries to generate different
# controller code, this generated spec may or may not pass.
#
# It only uses APIs available in rails and/or rspec-rails. There are a number
# of tools you can use to make these specs even more expressive, but we're
# sticking to rails and rspec-rails APIs to keep things simple and stable.
#
# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec. Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.

describe DestinationsController do

# This should return the minimal set of attributes required to create a valid
# Destination. As you add validations to Destination, be sure to
# update the return value of this method accordingly.
def valid_attributes
{}
end

# This should return the minimal set of values that should be in the session
# in order to pass any filters (e.g. authentication) defined in
# DestinationsController. Be sure to keep this updated too.
def valid_session
{}
end

describe "GET index" do
it "assigns all destinations as @destinations" do
destination = Destination.create! valid_attributes
get :index, {}, valid_session
assigns(:destinations).should eq([destination])
end
end

describe "GET show" do
it "assigns the requested destination as @destination" do
destination = Destination.create! valid_attributes
get :show, {:id => destination.to_param}, valid_session
assigns(:destination).should eq(destination)
end
end

describe "GET new" do
it "assigns a new destination as @destination" do
get :new, {}, valid_session
assigns(:destination).should be_a_new(Destination)
end
end

describe "GET edit" do
it "assigns the requested destination as @destination" do
destination = Destination.create! valid_attributes
get :edit, {:id => destination.to_param}, valid_session
assigns(:destination).should eq(destination)
end
end

describe "POST create" do
describe "with valid params" do
it "creates a new Destination" do
expect {
post :create, {:destination => valid_attributes}, valid_session
}.to change(Destination, :count).by(1)
end

it "assigns a newly created destination as @destination" do
post :create, {:destination => valid_attributes}, valid_session
assigns(:destination).should be_a(Destination)
assigns(:destination).should be_persisted
end

it "redirects to the created destination" do
post :create, {:destination => valid_attributes}, valid_session
response.should redirect_to(Destination.last)
end
end

describe "with invalid params" do
it "assigns a newly created but unsaved destination as @destination" do
# Trigger the behavior that occurs when invalid params are submitted
Destination.any_instance.stub(:save).and_return(false)
post :create, {:destination => {}}, valid_session
assigns(:destination).should be_a_new(Destination)
end

it "re-renders the 'new' template" do
# Trigger the behavior that occurs when invalid params are submitted
Destination.any_instance.stub(:save).and_return(false)
post :create, {:destination => {}}, valid_session
response.should render_template("new")
end
end
end

describe "PUT update" do
describe "with valid params" do
it "updates the requested destination" do
destination = Destination.create! valid_attributes
# Assuming there are no other destinations in the database, this
# specifies that the Destination created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
Destination.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
put :update, {:id => destination.to_param, :destination => {'these' => 'params'}}, valid_session
end

it "assigns the requested destination as @destination" do
destination = Destination.create! valid_attributes
put :update, {:id => destination.to_param, :destination => valid_attributes}, valid_session
assigns(:destination).should eq(destination)
end

it "redirects to the destination" do
destination = Destination.create! valid_attributes
put :update, {:id => destination.to_param, :destination => valid_attributes}, valid_session
response.should redirect_to(destination)
end
end

describe "with invalid params" do
it "assigns the destination as @destination" do
destination = Destination.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Destination.any_instance.stub(:save).and_return(false)
put :update, {:id => destination.to_param, :destination => {}}, valid_session
assigns(:destination).should eq(destination)
end

it "re-renders the 'edit' template" do
destination = Destination.create! valid_attributes
# Trigger the behavior that occurs when invalid params are submitted
Destination.any_instance.stub(:save).and_return(false)
put :update, {:id => destination.to_param, :destination => {}}, valid_session
response.should render_template("edit")
end
end
end

describe "DELETE destroy" do
it "destroys the requested destination" do
destination = Destination.create! valid_attributes
expect {
delete :destroy, {:id => destination.to_param}, valid_session
}.to change(Destination, :count).by(-1)
end

it "redirects to the destinations list" do
destination = Destination.create! valid_attributes
delete :destroy, {:id => destination.to_param}, valid_session
response.should redirect_to(destinations_url)
end
end

end
15 changes: 15 additions & 0 deletions spec/helpers/destinations_helper_spec.rb
@@ -0,0 +1,15 @@
require 'spec_helper'

# Specs in this file have access to a helper object that includes
# the DestinationsHelper. For example:
#
# describe DestinationsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe DestinationsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions spec/models/destination_spec.rb
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Destination do
pending "add some examples to (or delete) #{__FILE__}"
end
11 changes: 11 additions & 0 deletions spec/requests/destinations_spec.rb
@@ -0,0 +1,11 @@
require 'spec_helper'

describe "Destinations" do
describe "GET /destinations" do
it "works! (now write some real specs)" do
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
get destinations_path
response.status.should be(200)
end
end
end
35 changes: 35 additions & 0 deletions spec/routing/destinations_routing_spec.rb
@@ -0,0 +1,35 @@
require "spec_helper"

describe DestinationsController do
describe "routing" do

it "routes to #index" do
get("/destinations").should route_to("destinations#index")
end

it "routes to #new" do
get("/destinations/new").should route_to("destinations#new")
end

it "routes to #show" do
get("/destinations/1").should route_to("destinations#show", :id => "1")
end

it "routes to #edit" do
get("/destinations/1/edit").should route_to("destinations#edit", :id => "1")
end

it "routes to #create" do
post("/destinations").should route_to("destinations#create")
end

it "routes to #update" do
put("/destinations/1").should route_to("destinations#update", :id => "1")
end

it "routes to #destroy" do
delete("/destinations/1").should route_to("destinations#destroy", :id => "1")
end

end
end

0 comments on commit d0e857b

Please sign in to comment.