Skip to content

Commit

Permalink
Users can tag tikcets upon creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin4ipsum committed May 22, 2012
1 parent 8be8c13 commit 4f656da
Show file tree
Hide file tree
Showing 11 changed files with 1,403 additions and 1,338 deletions.
1 change: 1 addition & 0 deletions app/controllers/tickets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def new
def create
@ticket = @project.tickets.build(params[:ticket].merge!(:user => current_user))
if @ticket.save
@ticket.tag!(params[:tags])
flash[:notice] = "Ticket has been created."
redirect_to [@project, @ticket]
else
Expand Down
2 changes: 2 additions & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Tag < ActiveRecord::Base
end
10 changes: 10 additions & 0 deletions app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@ class Ticket < ActiveRecord::Base
has_many :assets
accepts_nested_attributes_for :assets
has_many :comments
has_and_belongs_to_many :tags

validates :title, :presence => true
validates :description, presence: true,
length: { minimum: 10 }

def tag!(tags)
tags = tags.split(" ").map do |tag|
Tag.find_or_create_by_name(tag)
end

self.tags << tags
end


end
1 change: 1 addition & 0 deletions app/views/tags/_tag.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span class='tag'><%= tag.name %></span>
5 changes: 5 additions & 0 deletions app/views/tickets/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<%= f.label :description %>
<%= f.text_area :description %>
</p>

<p>
<%= label_tag :tags %>
<%= text_field_tag :tags, params[:tags] %>
</p>

<% number = 0 %>
<div id="files">
Expand Down
27 changes: 14 additions & 13 deletions app/views/tickets/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<div id='ticket'>
<h2><%= @ticket.title %></h2>
<br><small>Created by <%= @ticket.user.email %></small>
<%= render @ticket.state if @ticket.state %>
<%= simple_format(@ticket.description) %>
<h2><%= @ticket.title %></h2>
<br><small>Created by <%= @ticket.user.email %></small>
<%= render @ticket.state if @ticket.state %>
<%= simple_format(@ticket.description) %>
<div id='tags'><%= render @ticket.tags %></div>

<% if @ticket.assets.exists? %>
<h3>Attached Files</h3>
<h3>Attached Files</h3>
<div class="assets">
<% @ticket.assets.each do |asset| %>
<p>
<%= link_to File.basename(asset.asset_file_name), asset.asset.url %>
</p>
<p>
<small><%= number_to_human_size(asset.asset.size) %></small>
</p>
<% end %>
<% @ticket.assets.each do |asset| %>
<p>
<%= link_to File.basename(asset.asset_file_name), asset.asset.url %>
</p>
<p>
<small><%= number_to_human_size(asset.asset.size) %></small>
</p>
<% end %>
</div>
<% end %>
Expand Down
2,656 changes: 1,335 additions & 1,321 deletions chromedriver.log

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions db/migrate/20120522184816_create_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateTags < ActiveRecord::Migration
def change
create_table :tags do |t|
t.string :name
end
end

create_table :tags_tickets, :id => false do |t|
t.integer :tag_id, :ticket_id
end

end
11 changes: 10 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 to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120518213238) do
ActiveRecord::Schema.define(:version => 20120522184816) do

create_table "assets", :force => true do |t|
t.string "asset_file_name"
Expand Down Expand Up @@ -57,6 +57,15 @@
t.boolean "default"
end

create_table "tags", :force => true do |t|
t.string "name"
end

create_table "tags_tickets", :id => false, :force => true do |t|
t.integer "tag_id"
t.integer "ticket_id"
end

create_table "tickets", :force => true do |t|
t.string "title"
t.text "description"
Expand Down
11 changes: 8 additions & 3 deletions features/creating_tickets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ Scenario: Creating a ticket with an attachment
And I should see "spin.txt" within "#ticket .assets"
When I follow "speed.txt"




Scenario: Creating a ticket with tags
When I fill in "Title" with "Non-standards compliance"
And I fill in "Description" with "My pages are ugly!"
And I fill in "Tags" with "browser visual"
And I press "Create Ticket"
Then I should see "Ticket has been created."
And I should see "browser" within "#ticket #tags"
And I should see "visual" within "#ticket #tags"
5 changes: 5 additions & 0 deletions spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

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

0 comments on commit 4f656da

Please sign in to comment.