Skip to content

Commit

Permalink
Card 1:
Browse files Browse the repository at this point in the history
As as User
I want to call /projects
to get all the projects for account
  • Loading branch information
marcjeanson committed Jul 13, 2011
1 parent c3aa5fd commit 76e7c2e
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/assets/javascripts/projects.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
7 changes: 7 additions & 0 deletions app/assets/stylesheets/projects.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Place all the styles related to the projects controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

body.projects {
// Place scoped styles here
}
8 changes: 8 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ProjectsController < ApplicationController
respond_to :json

def index
@projects = Project.all
respond_with(@projects)
end
end
2 changes: 2 additions & 0 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ProjectsHelper
end
2 changes: 2 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Project < ActiveRecord::Base
end
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Kanbanfu::Application.routes.draw do
resources :projects, :defaults => { :format => :json }

# The priority is based upon order of creation:
# first created -> highest priority.

Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20110712145406_create_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
t.integer :id
t.string :name
t.text :description
t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 0) do
ActiveRecord::Schema.define(:version => 20110712145406) do

create_table "projects", :force => true do |t|
t.string "name"
t.text "description"
t.datetime "created_at"
t.datetime "updated_at"
end

end
18 changes: 18 additions & 0 deletions features/projects.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: Projects API

As as User
I want to call /projects
to get all the projects for account

Scenario: Listing projects
Given I have the projects:
| id | name | description |
| 1 | Blazing Saddles | To ruin a western town, a corrupt political boss appoints a black sheriff, who promptly becomes his most formidable adversary.|
| 2 | Spaceballs | Planet Spaceball's President Skroob sends Lord Dark Helmet to steal Planet Druidia's abundant supply of air to replenish their own, and only Lone Starr can stop them.|
| 3 | Young Frankenstein| Dr. Frankenstein's grandson, after years of living down the family reputation, inherits granddad's castle and repeats the experiments.|
When I call API "/projects"
Then the JSON response should have 3 projects
And the JSON should have the following:
| 0 | {"id": 1, "name": "Blazing Saddles", "description": "To ruin a western town, a corrupt political boss appoints a black sheriff, who promptly becomes his most formidable adversary."} |
| 1 | {"id": 2, "name": "Spaceballs", "description": "Planet Spaceball's President Skroob sends Lord Dark Helmet to steal Planet Druidia's abundant supply of air to replenish their own, and only Lone Starr can stop them."} |
| 2 | {"id": 3, "name": "Young Frankenstein", "description": "Dr. Frankenstein's grandson, after years of living down the family reputation, inherits granddad's castle and repeats the experiments."} |
3 changes: 3 additions & 0 deletions features/step_definitions/projects_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Given /^I have the projects:$/ do |table|
table.hashes.each { |project| Project.create project }
end
17 changes: 17 additions & 0 deletions spec/controllers/projects_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe ProjectsController do

before(:each) do
@projects = (1..10).collect {|i| stub_model(Project, :id => i, :name => "project_#{i}", :description => "description_#{i}") }
end

describe 'GET on index via JSON' do
it 'renders the projects page' do
Project.stub(:all).and_return(@projects)
get :index, :format => :json
response.body.should eq(@projects.to_json)
end
end

end
5 changes: 5 additions & 0 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe Project do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 76e7c2e

Please sign in to comment.