Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Users can add tags when adding a comment

  • Loading branch information...
commit 28397e7782c355ec11425527b96ac95c997c3bfc 1 parent 4f656da
@Lin4ipsum authored
View
1  app/controllers/comments_controller.rb
@@ -8,6 +8,7 @@ def create
end
@comment = @ticket.comments.build(params[:comment].merge(:user => current_user))
if @comment.save
+ @ticket.tag!(params[:tags])
flash[:notice] = "Comment has been created."
redirect_to [@ticket.project, @ticket]
else
View
13 app/models/ticket.rb
@@ -11,13 +11,12 @@ class Ticket < ActiveRecord::Base
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
+ def tag!(tags)
+ tags = tags.split(" ").map do |tag|
+ Tag.find_or_create_by_name(tag)
+ end
+ self.tags << tags
+ end
end
View
3  app/views/comments/_form.html.erb
@@ -12,7 +12,10 @@
<%= f.select :state_id , @states.map { |s| [s.name, s.id] },
:selected => @ticket.state_id %>
</p>
+
<% end %>
+ <%= render "tags/form" %>
+
<%= f.submit %>
<% end %>
View
4 app/views/tags/_form.html.erb
@@ -0,0 +1,4 @@
+<p>
+ <%= label_tag :tags %>
+ <%= text_field_tag :tags, params[:tags] %>
+</p>
View
4 app/views/tags/_tag.html.erb
@@ -1 +1,3 @@
-<span class='tag'><%= tag.name %></span>
+<span class='tag'><%= tag.name %></span>
+
+
View
11 app/views/tickets/_form.html.erb
@@ -1,5 +1,6 @@
<%= form_for [@project, @ticket], :html => { :multipart => true} do |f| %>
<%= f.error_messages %>
+
<p>
<%= f.label :title %>
<%= f.text_field :title %>
@@ -9,13 +10,10 @@
<%= f.label :description %>
<%= f.text_area :description %>
</p>
-
- <p>
- <%= label_tag :tags %>
- <%= text_field_tag :tags, params[:tags] %>
- </p>
- <% number = 0 %>
+ <%= render "tags/form" %>
+
+ <% number = 0 %>
<div id="files">
<%= render :partial => "files/form",
:locals => { :number => number } %>
@@ -23,4 +21,5 @@
<%= link_to "Add another file", 'javascript:', :id => "add_another_file" %>
<%= f.submit %>
+
<% end %>
View
2,649 chromedriver.log
1,332 additions, 1,317 deletions not shown
View
10 features/creating_comments.feature
@@ -45,4 +45,12 @@ Scenario: Changing a ticket's state
Scenario: A user without permission cannot change the state
When I follow "Change a ticket's state"
Then I should not see the "#comment_state_id" element
-
+
+Scenario: Adding a tag to a ticket
+ When I follow "Change a ticket's state"
+ Then I should not see "bug" within "#ticket #tags"
+ And I fill in "Text" with "Adding the bug tag"
+ And I fill in "Tags" with "bug"
+ And I press "Create Comment"
+ Then I should see "Comment has been created"
+ Then I should see "bug" within "#ticket #tags"
View
7 spec/controllers/comments_controller_spec.rb
@@ -17,9 +17,10 @@
sign_in(:user, user)
end
it "cannot transition a state by passing through state_id" do
- post :create, {:comment => { :text => "Hacked!",
- :state_id => state.id},
- :ticket_id => ticket.id }
+ post :create, { :tags => "",
+ :comment => { :text => "Hacked!",
+ :state_id => state.id },
+ :ticket_id => ticket.id }
ticket.reload
ticket.state.should eql(nil)
end
Please sign in to comment.
Something went wrong with that request. Please try again.