Skip to content
Browse files

Added updating projects functionality

  • Loading branch information...
1 parent ed6910a commit a4c77a7f5f49620a374e70825c94e4428e961864 @wycats committed Apr 28, 2011
View
2 Gemfile
@@ -13,6 +13,7 @@ gem 'sqlite3'
# Asset template engines
gem 'sass', '~> 3.1.0.alpha'
gem 'coffee-script'
+gem 'dynamic_form'
# Use unicorn as the web server
# gem 'unicorn'
@@ -31,5 +32,6 @@ group :test do
gem 'cucumber-rails'
gem 'capybara'
gem 'database_cleaner'
+ gem 'factory_girl'
end
View
4 Gemfile.lock
@@ -101,8 +101,10 @@ GEM
culerity (0.2.15)
database_cleaner (0.6.7)
diff-lcs (1.1.2)
+ dynamic_form (1.1.4)
erubis (2.7.0)
execjs (0.2.0)
+ factory_girl (1.3.3)
ffi (1.0.7)
rake (>= 0.8.7)
gherkin (2.3.6)
@@ -168,6 +170,8 @@ DEPENDENCIES
coffee-script
cucumber-rails
database_cleaner
+ dynamic_form
+ factory_girl
rack!
rails!
rspec-rails (~> 2.3)
View
24 app/controllers/projects_controller.rb
@@ -1,5 +1,6 @@
class ProjectsController < ApplicationController
def index
+ @projects = Project.scoped
end
def new
@@ -8,8 +9,27 @@ def new
def create
@project = Project.new(params[:project])
- @project.save
- redirect_to @project, :notice => "Project has been created."
+ if @project.save
+ redirect_to @project, :notice => "Project has been created."
+ else
+ flash[:alert] = "Project has not been created."
+ render :action => "new"
+ end
+ end
+
+ def edit
+ @project = Project.find(params[:id])
+ end
+
+ def update
+ @project = Project.find(params[:id])
+
+ if @project.update_attributes(params[:project])
+ redirect_to @project, :notice => "Project has been updated."
+ else
+ flash[:alert] = "Project has not been updated."
+ render :action => "edit"
+ end
end
def show
View
2 app/models/project.rb
@@ -1,2 +1,4 @@
class Project < ActiveRecord::Base
+ validates :name, :presence => true
end
+
View
1 app/views/projects/_form.html.erb
@@ -1,4 +1,5 @@
<%= form_for(@project) do |f| %>
+ <%= f.error_messages %>
<p>
<%= f.label :name %>
<%= f.text_field :name %>
View
3 app/views/projects/edit.html.erb
@@ -0,0 +1,3 @@
+<h2>Edit project</h2>
+<%= render "form" %>
+
View
8 app/views/projects/index.html.erb
@@ -1 +1,9 @@
<%= link_to "New Project", new_project_path %>
+
+<h2>Projects</h2>
+<ul>
+ <% @projects.each do |project| %>
+ <li><%= link_to project.name, project %></li>
+ <% end %>
+</ul>
+
View
5 app/views/projects/show.html.erb
@@ -1,2 +1,7 @@
<% title(@project.name, "Projects") %>
<h2><%= @project.name %></h2>
+
+<menu>
+ <%= link_to "Edit", edit_project_path(@project) %>
+</menu>
+
View
17 config/application.rb
@@ -48,3 +48,20 @@ class Application < Rails::Application
config.assets.enabled = true
end
end
+
+module Rack
+ # Rack::Utils contains a grab-bag of useful methods for writing web
+ # applications adopted from all kinds of Ruby libraries.
+
+ module Utils
+ # Performs URI escaping so that you can construct proper
+ # query strings faster. Use this rather than the cgi.rb
+ # version since it's faster. (Stolen from Camping).
+ def escape(s)
+ s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/) {
+ '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
+ }.tr(' ', '+')
+ end
+ module_function :escape
+ end
+end
View
4 factories/project_factory.rb
@@ -0,0 +1,4 @@
+Factory.define :project do |project|
+ project.name 'Ticketee'
+end
+
View
10 features/creating_projects.feature
@@ -3,12 +3,20 @@ Feature: Creating projects
As a user
I want to create them easily
- Scenario: Creating a project
+ Background:
Given I am on the homepage
When I follow "New Project"
+
+ Scenario: Creating a project
And I fill in "Name" with "TextMate 2"
And I press "Create Project"
Then I should see "Project has been created."
And I should be on the project page for "TextMate 2"
And I should see "TextMate 2 - Projects - Ticketee"
+ Scenario: Creating a project without a name
+ And I press "Create Project"
+ Then I should see "Project has not been created."
+ And I should see "Name can't be blank"
+
+
View
22 features/editing_projects.feature
@@ -0,0 +1,22 @@
+Feature: Editing Projects
+ In order to update project information
+ As a user
+ I want to be able to do that through an interface
+
+ Background:
+ Given there is a project called "TextMate 2"
+ And I am on the homepage
+ When I follow "TextMate 2"
+ And I follow "Edit"
+
+ Scenario: Updating a project
+ And I fill in "Name" with "TextMate 2 beta"
+ And I press "Update Project"
+ Then I should see "Project has been updated."
+ Then I should be on the project page for "TextMate 2 beta"
+
+ Scenario: Updating a project with invalid attributes is bad
+ And I fill in "Name" with ""
+ And I press "Update Project"
+ Then I should see "Project has not been updated."
+
View
4 features/step_definitions/seed_steps.rb
@@ -0,0 +1,4 @@
+Given /^there is a project called "([^\"]*)"$/ do |name|
+ Factory(:project, :name => name)
+end
+
View
4 features/support/factory.rb
@@ -0,0 +1,4 @@
+Dir[Rails.root + "factories/*.rb"].each do |file|
+ require file
+end
+
View
11 features/viewing_projects.feature
@@ -0,0 +1,11 @@
+Feature: Viewing projects
+ In order to assign tickets to a project
+ As a user
+ I want to be able to see a list of available projects
+
+ Scenario: Listing all projects
+ Given there is a project called "TextMate 2"
+ And I am on the homepage
+ When I follow "TextMate 2"
+ Then I should be on the project page for "TextMate 2"
+

0 comments on commit a4c77a7

Please sign in to comment.
Something went wrong with that request. Please try again.