mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
emoji should not be coupled into the core
avatars were being counted and should not have been for basic users
This commit is contained in:
parent
bdba0a78c4
commit
99526c33da
3 changed files with 23 additions and 6 deletions
|
@ -115,10 +115,21 @@ class Post < ActiveRecord::Base
|
|||
self.cooked = nil
|
||||
end
|
||||
|
||||
def self.white_listed_image_classes
|
||||
@white_listed_image_classes ||= ['avatar']
|
||||
end
|
||||
|
||||
def image_count
|
||||
return 0 unless self.raw.present?
|
||||
cooked_document.search("img.emoji").remove
|
||||
cooked_document.search("img").count
|
||||
|
||||
cooked_document.search("img").reject{ |t|
|
||||
dom_class = t["class"]
|
||||
if dom_class
|
||||
(Post.white_listed_image_classes & dom_class.split(" ")).count > 0
|
||||
else
|
||||
false
|
||||
end
|
||||
}.count
|
||||
end
|
||||
|
||||
def link_count
|
||||
|
|
|
@ -86,7 +86,8 @@ describe Post do
|
|||
let(:post_no_images) { Fabricate.build(:post, post_args) }
|
||||
let(:post_one_image) { Fabricate.build(:post, post_args.merge(raw: "![sherlock](http://bbc.co.uk/sherlock.jpg)")) }
|
||||
let(:post_two_images) { Fabricate.build(:post, post_args.merge(raw: "<img src='http://discourse.org/logo.png'> <img src='http://bbc.co.uk/sherlock.jpg'>")) }
|
||||
let(:post_with_emoticons) { Fabricate.build(:post, post_args.merge(raw: '<img alt="smiley" title=":smiley:" src="/assets/emoji/smiley.png" class="emoji"> <img alt="wink" title=":wink:" src="/assets/emoji/wink.png" class="emoji">')) }
|
||||
let(:post_with_avatars) { Fabricate.build(:post, post_args.merge(raw: '<img alt="smiley" title=":smiley:" src="/assets/emoji/smiley.png" class="avatar"> <img alt="wink" title=":wink:" src="/assets/emoji/wink.png" class="avatar">')) }
|
||||
let(:post_with_two_classy_images) { Fabricate.build(:post, post_args.merge(raw: "<img src='http://discourse.org/logo.png' class='classy'> <img src='http://bbc.co.uk/sherlock.jpg' class='classy'>")) }
|
||||
|
||||
it "returns 0 images for an empty post" do
|
||||
Fabricate.build(:post).image_count.should == 0
|
||||
|
@ -100,10 +101,14 @@ describe Post do
|
|||
post_two_images.image_count.should == 2
|
||||
end
|
||||
|
||||
it "doesn't count emoticons as images" do
|
||||
post_with_emoticons.image_count.should == 0
|
||||
it "doesn't count avatars as images" do
|
||||
post_with_avatars.image_count.should == 0
|
||||
end
|
||||
|
||||
it "doesn't count whitelisted images" do
|
||||
Post.stubs(:white_listed_image_classes).returns(["classy"])
|
||||
post_with_two_classy_images.image_count.should == 0
|
||||
end
|
||||
|
||||
context "validation" do
|
||||
it "allows a new user to make a post with one image" do
|
||||
|
|
|
@ -9,8 +9,9 @@ module DiscourseEmoji
|
|||
|
||||
app.config.after_initialize do
|
||||
DiscoursePluginRegistry.setup(DiscourseEmoji::Plugin)
|
||||
Post.white_listed_image_classes << "emoji"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue