Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

When creating tickets, attribute them to the creator.

  • Loading branch information...
commit 8ef31c02b47f2046e6c0a1b9b90415ae86a190ec 1 parent a921191
gizyh authored
3  app/controllers/tickets_controller.rb
View
@@ -1,4 +1,5 @@
class TicketsController < ApplicationController
+ before_filter :authenticate_user!, :except => [:index, :show]
before_filter :find_project
before_filter :find_ticket, :only => [:show, :edit, :update, :destroy]
def new
@@ -10,7 +11,7 @@ def show
end
def create
- @ticket = @project.tickets.build(params[:ticket])
+ @ticket = @project.tickets.build(params[:ticket].merge!(:user => current_user))
if @ticket.save
flash[:notice] = "Ticket has been created."
redirect_to [@project, @ticket]
3  app/models/ticket.rb
View
@@ -1,6 +1,7 @@
class Ticket < ActiveRecord::Base
belongs_to :project
-
+ belongs_to :user
+
validates :title, :presence => true
validates :description, :presence => true,
:length => { :minimum => 10}
1  app/views/tickets/show.html.erb
View
@@ -1,5 +1,6 @@
<div id="ticket">
<h2><%= @ticket.title %></h2>
+ <br><small>Created by <%= @ticket.user.email %></small>
<%= link_to "Edit Ticket", [:edit, @project, @ticket] %>
<%= link_to "Delete Ticket", [@project, @ticket], :method => :delete,
:confirm => "Are you sure you want to delete this ticket?" %>
6 db/migrate/20120310060856_add_user_id_to_tickets.rb
View
@@ -0,0 +1,6 @@
+class AddUserIdToTickets < ActiveRecord::Migration
+ def change
+ add_column :tickets, :user_id, :integer
+
+ end
+end
3  db/schema.rb
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120309035234) do
+ActiveRecord::Schema.define(:version => 20120310060856) do
create_table "projects", :force => true do |t|
t.string "name"
@@ -25,6 +25,7 @@
t.integer "project_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
+ t.integer "user_id"
end
add_index "tickets", ["project_id"], :name => "index_tickets_on_project_id"
9 features/creating_tickets.feature
View
@@ -5,15 +5,24 @@ I want to be able to select a project and do that
Background:
Given there is a project called "Internet Explorer"
+ And there are the following users:
+ | email | password |
+ | user@ticketee.com | password |
And I am on the homepage
When I follow "Internet Explorer"
And I follow "New Ticket"
+ Then I should see "You need to sign in or sign up before continuing."
+ When I fill in "Email" with "user@ticketee.com"
+ And I fill in "Password" with "password"
+ And I press "Sign in"
+ Then I should see "New Ticket"
Scenario: Creating a ticket
When I fill in "Title" with "Non-standards compliance"
And I fill in "Description" with "My pages are ugly!"
And I press "Create Ticket"
Then I should see "Ticket has been created."
+ Then I should see "Created by user@ticketee.com"
Scenario: Creating a ticket without valid attributes fails
When I press "Create Ticket"
12 features/deleting_tickets.feature
View
@@ -4,10 +4,14 @@ Feature: Deleting tickets
I want to press a button and make them disappear
Background:
- Given there is a project called "TextMate 2"
- And that project has a ticket:
- |title | description |
- |Make it shiny! | Gradients! Starbursts! Oh my! |
+ Given there are the following users:
+ | email | password |
+ | user@ticketee.com | password |
+ And I am signed in as them
+ And there is a project called "TextMate 2"
+ And "user@ticketee.com" has created a ticket for this porject:
+ | title | description |
+ | Make it shiny! | Gradients! Starbursts! Oh my! |
Given I am on the homepage
When I follow "TextMate 2"
And I follow "Make it shiny!"
9 features/editing_tickets.feature
View
@@ -4,14 +4,19 @@ Feature: Editing tickets
I want a form to edit the tickets
Background:
- Given there is a project called "TextMate 2"
- And that project has a ticket:
+ Given there are the following users:
+ | email | password |
+ | user@ticketee.com | password |
+ And I am signed in as them
+ And there is a project called "TextMate 2"
+ And "user@ticketee.com" has created a ticket for this porject:
| title | description |
| Make it shiny! | Gradients! Starbursts! Oh my! |
Given I am on the homepage
When I follow "TextMate 2"
And I follow "Make it shiny!"
When I follow "Edit Ticket"
+
Scenario: Updating a ticket
When I fill in "Title" with "Make it really shiny!"
And I press "Update Ticket"
7 features/signing_in.feature
View
@@ -16,9 +16,4 @@ Feature: Signing in
Given there are the following users:
| email | password |
| user@ticketee.com | password |
- And I am on the homepage
- When I follow "Sign in"
- And I fill in "Email" with "user@ticketee.com"
- And I fill in "Password" with "password"
- And I press "Sign in"
- Then I should see "Signed in successfully"
+ And I am signed in as them
7 features/step_definitions/ticket_steps.rb
View
@@ -2,4 +2,11 @@
table.hashes.each do |attributes|
@project.tickets.create!(attributes)
end
+end
+
+Given /^"([^\"]*)" has created a ticket for this porject:$/ do |email, table|
+ table.hashes.each do |attributes|
+ attributes = attributes.merge!(:user => User.find_by_email!(email))
+ @project.tickets.create!(attributes)
+ end
end
11 features/step_definitions/user_steps.rb
View
@@ -4,4 +4,15 @@
@user = User.create!(attributes)
@user.confirm! unless unconfirmed
end
+end
+
+Given /^I am signed in as them$/ do
+ steps(%Q{
+ Given I am on the homepage
+ When I follow "Sign in"
+ And I fill in "Email" with "#{@user.email}"
+ And I fill in "Password" with "password"
+ And I press "Sign in"
+ Then I should see "Signed in successfully."
+ })
end
13 features/viewing_tickets.feature
View
@@ -4,14 +4,17 @@ As a user
I want to see them on that project's page
Background:
- Given there is a project called "TextMate 2"
- And that project has a ticket:
+ Given there are the following users:
+ | email | password |
+ | user@ticketee.com | password |
+ And there is a project called "TextMate 2"
+ And "user@ticketee.com" has created a ticket for this porject:
| title | description |
| Make it shiny! | Gradients! Starbursts! Oh my! |
And there is a project called "Internet Explorer"
- And that project has a ticket:
- | title | description |
- | Standards compliance | Isn't a joke. |
+ And "user@ticketee.com" has created a ticket for this porject:
+ | title | description |
+ | Standards compliance | Isn't a joke. |
And I am on the homepage
Scenario: Viewing tickets for a given project
Please sign in to comment.
Something went wrong with that request. Please try again.