Permalink
Browse files

Merge pull request #105 from msevestre/master

Correct bug with empty tags and add some tests
  • Loading branch information...
2 parents 6b8a6d7 + 7e55566 commit 132bde7f7c80977ba03451e773f37843b1906c6f @jipiboily committed Oct 3, 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
@@ -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!
if tag.present?
Monologue::Tag.find_or_create_by_name(tag)
@@ -1,4 +1,4 @@
-require 'spec_helper'
+ require 'spec_helper'
describe Monologue::Post do
before(:each) do
@@ -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 132bde7

Please sign in to comment.