Skip to content
Browse files

Correct bug with empty tags

  • Loading branch information...
1 parent f7fa45b commit ce0764db05aed8dee08b3f9b1049aa8453f794f4 @msevestre msevestre committed Oct 1, 2012
Showing with 28 additions and 3 deletions.
  1. +2 −2 app/models/monologue/post.rb
  2. +1 −1 spec/models/monologue/post_spec.rb
  3. +25 −0 spec/requests/admin/tags_spec.rb
View
4 app/models/monologue/post.rb
@@ -1,7 +1,7 @@
class Monologue::Post < ActiveRecord::Base
has_many :posts_revisions, :dependent => :destroy
has_many :taggings
- has_many :tags ,:through=> :taggings,:dependent => :destroy
+ has_many :tags, :through => :taggings, :dependent => :destroy
accepts_nested_attributes_for :posts_revisions
attr_writer :tag_list
@@ -28,7 +28,7 @@ def active_revision
end
def tag!(tags)
- self.tags = tags.map do |tag|
+ self.tags = tags.select { |t| t.present? }.map do |tag|
tag.strip!
Monologue::Tag.find_or_create_by_name(tag)
end
View
2 spec/models/monologue/post_spec.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+ require 'spec_helper'
describe Monologue::Post do
before(:each) do
View
25 spec/requests/admin/tags_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+describe "tags" do
+ context "creating a post as a logged in user" do
+ before(:each) do
+ log_in
+ visit new_admin_post_path
+ fill_in "Title", :with => "title"
+ fill_in "Content", :with => "content"
+ fill_in "Published at", :with => DateTime.now
+ end
+
+ it "should be able to save a post when the tag list ends with with a comma" do
+ fill_in "Tags",:with => " rails, ruby, "
+ click_button "Save"
+ page.should have_field :tag_list ,:with => "rails, ruby"
+ end
+
+ it "should ignore an empty tag between two commas" do
+ fill_in "Tags",:with => " rails, ,ruby"
+ click_button "Save"
+ page.should have_field :tag_list ,:with => "rails, ruby"
+ end
+ end
+
+end

0 comments on commit ce0764d

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