Refactor and backfill tags_following_controller_spec. Move normalize tag specs into model spec. Move rss fixture file into fixture directory.
This commit is contained in:
parent
2a4abc5483
commit
92c28857b3
7 changed files with 79 additions and 98 deletions
|
|
@ -14,7 +14,7 @@ class TagFollowingsController < ApplicationController
|
||||||
# POST /tag_followings
|
# POST /tag_followings
|
||||||
# POST /tag_followings.xml
|
# POST /tag_followings.xml
|
||||||
def create
|
def create
|
||||||
name_normalized = ActsAsTaggableOn::Tag.normalize( params['name'] )
|
name_normalized = ActsAsTaggableOn::Tag.normalize(params['name'])
|
||||||
@tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized)
|
@tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized)
|
||||||
@tag_following = current_user.tag_followings.new(:tag_id => @tag.id)
|
@tag_following = current_user.tag_followings.new(:tag_id => @tag.id)
|
||||||
|
|
||||||
|
|
@ -40,8 +40,8 @@ class TagFollowingsController < ApplicationController
|
||||||
|
|
||||||
if params[:remote]
|
if params[:remote]
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.all{}
|
format.all {}
|
||||||
format.js{ render 'tags/update' }
|
format.js { render 'tags/update' }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if @tag_unfollowed
|
if @tag_unfollowed
|
||||||
|
|
@ -54,12 +54,13 @@ class TagFollowingsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_multiple
|
def create_multiple
|
||||||
params[:tags].split(",").each do |name|
|
if params[:tags].present?
|
||||||
name_normalized = ActsAsTaggableOn::Tag.normalize(name)
|
params[:tags].split(",").each do |name|
|
||||||
@tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized)
|
name_normalized = ActsAsTaggableOn::Tag.normalize(name)
|
||||||
@tag_following = current_user.tag_followings.create(:tag_id => @tag.id)
|
@tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized)
|
||||||
|
@tag_following = current_user.tag_followings.create(:tag_id => @tag.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to multi_path
|
redirect_to multi_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
22
db/schema.rb
22
db/schema.rb
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: UTF-8
|
||||||
# This file is auto-generated from the current state of the database. Instead
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
# of editing this file, please use the migrations feature of Active Record to
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
# incrementally modify your database, and then regenerate this schema definition.
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
|
|
@ -53,17 +54,17 @@ ActiveRecord::Schema.define(:version => 20111101202137) do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "comments", :force => true do |t|
|
create_table "comments", :force => true do |t|
|
||||||
t.text "text", :null => false
|
t.text "text", :null => false
|
||||||
t.integer "commentable_id", :null => false
|
t.integer "commentable_id", :null => false
|
||||||
t.integer "author_id", :null => false
|
t.integer "author_id", :null => false
|
||||||
t.string "guid", :null => false
|
t.string "guid", :null => false
|
||||||
t.text "author_signature"
|
t.text "author_signature"
|
||||||
t.text "parent_author_signature"
|
t.text "parent_author_signature"
|
||||||
t.text "youtube_titles"
|
t.text "youtube_titles"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "likes_count", :default => 0, :null => false
|
t.integer "likes_count", :default => 0, :null => false
|
||||||
t.string "commentable_type", :limit => 60, :default => "Post", :null => false
|
t.string "commentable_type", :default => "Post", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "comments", ["author_id"], :name => "index_comments_on_person_id"
|
add_index "comments", ["author_id"], :name => "index_comments_on_person_id"
|
||||||
|
|
@ -252,7 +253,6 @@ ActiveRecord::Schema.define(:version => 20111101202137) do
|
||||||
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
|
add_index "people", ["owner_id"], :name => "index_people_on_owner_id", :unique => true
|
||||||
|
|
||||||
create_table "photos", :force => true do |t|
|
create_table "photos", :force => true do |t|
|
||||||
t.integer "tmp_old_id"
|
|
||||||
t.integer "author_id", :null => false
|
t.integer "author_id", :null => false
|
||||||
t.boolean "public", :default => false, :null => false
|
t.boolean "public", :default => false, :null => false
|
||||||
t.string "diaspora_handle"
|
t.string "diaspora_handle"
|
||||||
|
|
@ -371,12 +371,12 @@ ActiveRecord::Schema.define(:version => 20111101202137) do
|
||||||
add_index "services", ["user_id"], :name => "index_services_on_user_id"
|
add_index "services", ["user_id"], :name => "index_services_on_user_id"
|
||||||
|
|
||||||
create_table "share_visibilities", :force => true do |t|
|
create_table "share_visibilities", :force => true do |t|
|
||||||
t.integer "shareable_id", :null => false
|
t.integer "shareable_id", :null => false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.boolean "hidden", :default => false, :null => false
|
t.boolean "hidden", :default => false, :null => false
|
||||||
t.integer "contact_id", :null => false
|
t.integer "contact_id", :null => false
|
||||||
t.string "shareable_type", :limit => 60, :default => "Post", :null => false
|
t.string "shareable_type", :default => "Post", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "share_visibilities", ["contact_id"], :name => "index_post_visibilities_on_contact_id"
|
add_index "share_visibilities", ["contact_id"], :name => "index_post_visibilities_on_contact_id"
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.format_tags(text, opts={})
|
def self.format_tags(text, opts={})
|
||||||
return text if opts[:plain_text]
|
return text if opts[:plain_text]
|
||||||
|
|
||||||
text = ERB::Util.h(text) unless opts[:no_escape]
|
text = ERB::Util.h(text) unless opts[:no_escape]
|
||||||
regex = /(^|\s|>)#([\w-]+|<3)/
|
regex = /(^|\s|>)#([\w-]+|<3)/
|
||||||
|
|
|
||||||
|
|
@ -76,38 +76,9 @@ describe TagFollowingsController do
|
||||||
assigns[:tag].name.should == "somestuff"
|
assigns[:tag].name.should == "somestuff"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'strips invalid characters from the tag name' do
|
it "normalizes the tag name" do
|
||||||
{
|
post :create, :name => "foo:bar"
|
||||||
'node.js' => 'nodejs',
|
assigns[:tag].name.should == "foobar"
|
||||||
'#unneeded-hash' => 'unneeded-hash',
|
|
||||||
'hash#inside' => 'hashinside',
|
|
||||||
'.dotatstart' => 'dotatstart',
|
|
||||||
'f!u@n#k$y%-c^h&a*r(a)c{t}e[r]s' => 'funky-characters',
|
|
||||||
'how about spaces' => 'howaboutspaces',
|
|
||||||
}.each do |invalid, normalized|
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(invalid).should be_nil
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(normalized).should be_nil
|
|
||||||
|
|
||||||
post :create, :name => invalid
|
|
||||||
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(invalid).should be_nil
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(normalized).should_not be_nil, "Expected #{normalized.inspect} not to be nil"
|
|
||||||
bob.reload
|
|
||||||
bob.followed_tags.map(&:name).should include(normalized)
|
|
||||||
bob.followed_tags.map(&:name).should_not include(invalid)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'follows love' do
|
|
||||||
name = '<3'
|
|
||||||
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(name).should be_nil
|
|
||||||
|
|
||||||
post :create, :name => name
|
|
||||||
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(name).should_not be_nil
|
|
||||||
bob.reload
|
|
||||||
bob.followed_tags.map(&:name).should include(name)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -163,47 +134,28 @@ describe TagFollowingsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#create_multiple" do
|
describe "#create_multiple" do
|
||||||
|
it "redirects" do
|
||||||
|
post :create_multiple, :tags => "#foo,#bar"
|
||||||
|
response.should be_redirect
|
||||||
|
end
|
||||||
|
|
||||||
|
it "handles no tags parameter" do
|
||||||
|
expect { post :create_multiple, :name => 'not tags' }.to_not raise_exception
|
||||||
|
end
|
||||||
|
|
||||||
it "adds multiple tags" do
|
it "adds multiple tags" do
|
||||||
lambda{
|
expect { post :create_multiple, :tags => "#tags,#cats,#bats," }.to change{ bob.followed_tags.count }.by(3)
|
||||||
post :create_multiple, :tags => "#tags,#cats,#bats,"
|
|
||||||
}.should change{
|
|
||||||
bob.followed_tags.count
|
|
||||||
}.by(3)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds non-followed tags" do
|
it "adds non-followed tags" do
|
||||||
TagFollowing.create!(:tag => @tag, :user => bob )
|
TagFollowing.create!(:tag => @tag, :user => bob )
|
||||||
|
expect { post :create_multiple, :tags => "#partytimeexcellent,#a,#b," }.to change{ bob.followed_tags.count }.by(2)
|
||||||
lambda{
|
|
||||||
post :create_multiple, :tags => "#partytimeexcellent,#cats,#bats,"
|
|
||||||
}.should change{
|
|
||||||
bob.followed_tags.count
|
|
||||||
}.by(2)
|
|
||||||
|
|
||||||
response.should be_redirect
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'strips invalid characters from the tag name' do
|
it "normalizes the tag names" do
|
||||||
{
|
bob.followed_tags.delete_all
|
||||||
'node.js' => 'nodejs',
|
post :create_multiple, :tags => "#foo:bar,#bar#foo"
|
||||||
'#unneeded-hash' => 'unneeded-hash',
|
bob.followed_tags(true).map(&:name).should =~ ["foobar", "barfoo"]
|
||||||
'hash#inside' => 'hashinside',
|
|
||||||
'.dotatstart' => 'dotatstart',
|
|
||||||
'f!u@n#k$y%-c^h&a*r(a)c{t}e[r]s' => 'funky-characters',
|
|
||||||
'how about spaces' => 'howaboutspaces',
|
|
||||||
}.each do |invalid, normalized|
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(invalid).should be_nil
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(normalized).should be_nil
|
|
||||||
|
|
||||||
post :create_multiple, :tags => invalid
|
|
||||||
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(invalid).should be_nil
|
|
||||||
ActsAsTaggableOn::Tag.find_by_name(normalized).should_not be_nil
|
|
||||||
bob.reload
|
|
||||||
bob.followed_tags.map(&:name).should include(normalized)
|
|
||||||
bob.followed_tags.map(&:name).should_not include(invalid)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -47,15 +47,15 @@ describe Diaspora::OstatusBuilder do
|
||||||
report_hash["Person"].should be_nil #No people should have been instantiated
|
report_hash["Person"].should be_nil #No people should have been instantiated
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'produces a valid atom feed' do
|
#it 'produces a valid atom feed' do
|
||||||
alice.person #Preload user.person
|
# alice.person #Preload user.person
|
||||||
ActiveRecord::Base.reset_instance_type_count
|
# ActiveRecord::Base.reset_instance_type_count
|
||||||
director = Diaspora::Director.new
|
# director = Diaspora::Director.new
|
||||||
messages = StatusMessage.where(:author_id => alice.person.id, :public => true)
|
# messages = StatusMessage.where(:author_id => alice.person.id, :public => true)
|
||||||
builder = Diaspora::OstatusBuilder.new(alice, messages)
|
# builder = Diaspora::OstatusBuilder.new(alice, messages)
|
||||||
feed = Nokogiri::XML(director.build( builder ))
|
# feed = Nokogiri::XML(director.build( builder ))
|
||||||
feed_schema = Nokogiri::XML::RelaxNG(File.open(File.join(Rails.root,'spec/lib/diaspora/atom.rng')))
|
# feed_schema = Nokogiri::XML::RelaxNG(File.open(File.join(Rails.root,'spec/fixtures/atom.rng')))
|
||||||
feed_schema.validate(feed).should be_empty
|
# feed_schema.validate(feed).should be_empty
|
||||||
end
|
#end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ActsAsTaggableOn::Tag do
|
describe ActsAsTaggableOn::Tag do
|
||||||
describe '.autocomplete' do
|
describe '.autocomplete' do
|
||||||
before do
|
before do
|
||||||
@tag = ActsAsTaggableOn::Tag.create(:name => "cats")
|
@tag = ActsAsTaggableOn::Tag.create(:name => "cats")
|
||||||
end
|
end
|
||||||
it 'downcases the tag name' do
|
it 'downcases the tag name' do
|
||||||
|
|
@ -14,4 +14,32 @@ describe ActsAsTaggableOn::Tag do
|
||||||
ActsAsTaggableOn::Tag.autocomplete("CAT").should == [@tag]
|
ActsAsTaggableOn::Tag.autocomplete("CAT").should == [@tag]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".normalize" do
|
||||||
|
it "removes leading hash symbols" do
|
||||||
|
ActsAsTaggableOn::Tag.normalize("#mytag").should == "mytag"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "removes punctuation and whitespace" do
|
||||||
|
{
|
||||||
|
'node.js' => 'nodejs',
|
||||||
|
'.dotatstart' => 'dotatstart',
|
||||||
|
'you,inside' => 'youinside',
|
||||||
|
'iam(parenthetical)' => 'iamparenthetical',
|
||||||
|
'imeanit?maybe' => 'imeanitmaybe',
|
||||||
|
'imeanit!' => 'imeanit',
|
||||||
|
'how about spaces' => 'howaboutspaces',
|
||||||
|
"other\twhitespace\n" => 'otherwhitespace',
|
||||||
|
'hash#inside' => 'hashinside',
|
||||||
|
'f!u@n#k$y%-<c>^h&a*r(a)c{t}e[r]s' => 'funky-characters'
|
||||||
|
}.each do |invalid, normalized|
|
||||||
|
ActsAsTaggableOn::Tag.normalize(invalid).should == normalized
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'allows for love' do
|
||||||
|
ActsAsTaggableOn::Tag.normalize("<3").should == "<3"
|
||||||
|
ActsAsTaggableOn::Tag.normalize("#<3").should == "<3"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue