mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -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
|
self.cooked = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.white_listed_image_classes
|
||||||
|
@white_listed_image_classes ||= ['avatar']
|
||||||
|
end
|
||||||
|
|
||||||
def image_count
|
def image_count
|
||||||
return 0 unless self.raw.present?
|
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
|
end
|
||||||
|
|
||||||
def link_count
|
def link_count
|
||||||
|
|
|
@ -86,7 +86,8 @@ describe Post do
|
||||||
let(:post_no_images) { Fabricate.build(:post, post_args) }
|
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_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_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
|
it "returns 0 images for an empty post" do
|
||||||
Fabricate.build(:post).image_count.should == 0
|
Fabricate.build(:post).image_count.should == 0
|
||||||
|
@ -100,10 +101,14 @@ describe Post do
|
||||||
post_two_images.image_count.should == 2
|
post_two_images.image_count.should == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't count emoticons as images" do
|
it "doesn't count avatars as images" do
|
||||||
post_with_emoticons.image_count.should == 0
|
post_with_avatars.image_count.should == 0
|
||||||
end
|
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
|
context "validation" do
|
||||||
it "allows a new user to make a post with one image" do
|
it "allows a new user to make a post with one image" do
|
||||||
|
|
|
@ -9,6 +9,7 @@ module DiscourseEmoji
|
||||||
|
|
||||||
app.config.after_initialize do
|
app.config.after_initialize do
|
||||||
DiscoursePluginRegistry.setup(DiscourseEmoji::Plugin)
|
DiscoursePluginRegistry.setup(DiscourseEmoji::Plugin)
|
||||||
|
Post.white_listed_image_classes << "emoji"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue