Skip to content

Commit

Permalink
added a project model
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Widmayer & Sue Petersen committed Oct 25, 2013
1 parent 361540b commit dbbdc88
Show file tree
Hide file tree
Showing 23 changed files with 409 additions and 5 deletions.
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://coffeescript.org/
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import 'foundation_and_overrides';

@import 'stories';
@import 'projects';
16 changes: 16 additions & 0 deletions app/assets/stylesheets/projects.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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/
.project {
border: 1px solid #333;
}
.project-name {
border-right: 1px solid #333;
div {
padding: 6px;
text-align: center;
&:first-child {
border-bottom: 1px solid #333;
}
}
}
58 changes: 58 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
class ProjectsController < ApplicationController
before_action :set_project, only: [:show, :edit, :update, :destroy]

# GET /projects
def index
@projects = Project.all
end

# GET /projects/1
def show
end

# GET /projects/new
def new
@project = Project.new
end

# GET /projects/1/edit
def edit
end

# POST /projects
def create
@project = Project.new(project_params)

if @project.save
redirect_to @project, notice: 'Project was successfully created.'
else
render action: 'new'
end
end

# PATCH/PUT /projects/1
def update
if @project.update(project_params)
redirect_to @project, notice: 'Project was successfully updated.'
else
render action: 'edit'
end
end

# DELETE /projects/1
def destroy
@project.destroy
redirect_to projects_url, notice: 'Project was successfully destroyed.'
end

private
# Use callbacks to share common setup or constraints between actions.
def set_project
@project = Project.find(params[:id])
end

# Only allow a trusted parameter "white list" through.
def project_params
params.require(:project).permit(:name)
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
21 changes: 21 additions & 0 deletions app/views/projects/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%= form_for(@project) do |f| %>
<% if @project.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2>

<ul>
<% @project.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/projects/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing project</h1>

<%= render 'form' %>

<%= link_to 'Show', @project %> |
<%= link_to 'Back', projects_path %>
17 changes: 17 additions & 0 deletions app/views/projects/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h1>Listing projects</h1>
<div class="project-list">
<% @projects.each do |project| %>
<div class="project row">
<div class="project-name small-8 columns">
<div class="row" title="business value">
<%= link_to project.name, edit_project_path(project) %>
</div>
</div>
<div class="small-4 columns">
<%= link_to 'Destroy', project, method: :delete, data: { confirm: 'Are you sure?' } %>
</div>
</div>
<% end %>
</div>

<%= link_to 'New Project', new_project_path %>
5 changes: 5 additions & 0 deletions app/views/projects/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New project</h1>

<%= render 'form' %>

<%= link_to 'Back', projects_path %>
9 changes: 9 additions & 0 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Name:</strong>
<%= @project.name %>
</p>

<%= link_to 'Edit', edit_project_path(@project) %> |
<%= link_to 'Back', projects_path %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
StarterApp::Application.routes.draw do
resources :projects

resources :users

resources :stories do
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20131025172152_create_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateProjects < ActiveRecord::Migration
def change
create_table :projects do |t|
t.string :name

t.timestamps
end
end
end
8 changes: 7 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20131025170945) do
ActiveRecord::Schema.define(version: 20131025172152) do

create_table "comments", force: true do |t|
t.integer "story_id"
Expand All @@ -21,6 +21,12 @@
t.datetime "updated_at"
end

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

create_table "stories", force: true do |t|
t.string "goal"
t.string "stakeholder"
Expand Down
10 changes: 10 additions & 0 deletions features/project/create_project.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature:
In order to group stories
As a user
I want to create a project

Scenario: Create a project
Given I am on the new project page
When I enter the project details
And I save the project
Then I should see a success message
4 changes: 4 additions & 0 deletions features/step_definitions/global_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@

When /^I click "([^\"]*)"$/ do |link|
click_link(link)
end

Then(/^I should see a success message$/) do
expect(page).to have_content 'success'
end
11 changes: 11 additions & 0 deletions features/step_definitions/project/create_project_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Given(/^I am on the new project page$/) do
visit new_project_path
end

When(/^I enter the project details$/) do
step %{I fill in "Name" with "foo"}
end

When(/^I save the project$/) do
step %{I press "Create Project"}
end
4 changes: 0 additions & 4 deletions features/step_definitions/story/create_story_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@

When(/^I save the story$/) do
step %{I press "Submit"}
end

Then(/^I should see a success message$/) do
expect(page).to have_content 'success'
end
160 changes: 160 additions & 0 deletions spec/controllers/projects_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
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 ProjectsController do

# This should return the minimal set of attributes required to create a valid
# Project. As you add validations to Project, be sure to
# adjust the attributes here as well.
let(:valid_attributes) { { "name" => "MyString" } }

# 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
# ProjectsController. Be sure to keep this updated too.
let(:valid_session) { {} }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

it "redirects to the projects list" do
project = Project.create! valid_attributes
delete :destroy, {:id => project.to_param}, valid_session
response.should redirect_to(projects_url)
end
end

end
Loading

0 comments on commit dbbdc88

Please sign in to comment.