forked from RogueRails/starter_app
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Derek Widmayer & Sue Petersen
committed
Oct 25, 2013
1 parent
361540b
commit dbbdc88
Showing
23 changed files
with
409 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@import 'foundation_and_overrides'; | ||
|
||
@import 'stories'; | ||
@import 'projects'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ProjectsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Project < ActiveRecord::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.