mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Merge branch 'whitespace-cleanese' of git://github.com/goshakkk/discourse
Conflicts: lib/oneboxer.rb lib/oneboxer/whitelist.rb spec/controllers/robots_txt_controller_spec.rb
This commit is contained in:
commit
1221c393a3
383 changed files with 4225 additions and 2226 deletions
|
@ -7,7 +7,7 @@ describe CategoryList do
|
|||
let(:category_list) { CategoryList.new(user) }
|
||||
|
||||
context "with no categories" do
|
||||
|
||||
|
||||
it "has no categories" do
|
||||
category_list.categories.should be_blank
|
||||
end
|
||||
|
@ -35,7 +35,7 @@ describe CategoryList do
|
|||
it "contains the topic in featured_topics" do
|
||||
category.featured_topics.should == [topic]
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -73,7 +73,7 @@ describe CategoryList do
|
|||
|
||||
it "should contain our topic" do
|
||||
category.featured_topics.should == [topic]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -3,24 +3,24 @@ require 'content_buffer'
|
|||
|
||||
describe ContentBuffer do
|
||||
|
||||
it "handles deletion across lines properly" do
|
||||
it "handles deletion across lines properly" do
|
||||
c = ContentBuffer.new("a\nbc\nc")
|
||||
c.apply_transform!(start: {row: 0, col: 0}, finish: {col: 1, row: 1}, operation: :delete)
|
||||
c.to_s.should == "c\nc"
|
||||
end
|
||||
it "handles deletion inside lines properly" do
|
||||
it "handles deletion inside lines properly" do
|
||||
c = ContentBuffer.new("hello world")
|
||||
c.apply_transform!(start: {row: 0, col: 1}, finish: {col: 4, row: 0}, operation: :delete)
|
||||
c.to_s.should == "ho world"
|
||||
end
|
||||
|
||||
it "handles inserts inside lines properly" do
|
||||
|
||||
it "handles inserts inside lines properly" do
|
||||
c = ContentBuffer.new("hello!")
|
||||
c.apply_transform!(start: {row: 0, col: 5}, operation: :insert, text: " world")
|
||||
c.to_s.should == "hello world!"
|
||||
end
|
||||
|
||||
it "handles multiline inserts" do
|
||||
it "handles multiline inserts" do
|
||||
c = ContentBuffer.new("hello!")
|
||||
c.apply_transform!(start: {row: 0, col: 5}, operation: :insert, text: "\nworld")
|
||||
c.to_s.should == "hello\nworld!"
|
||||
|
|
|
@ -66,7 +66,7 @@ EXPECTED
|
|||
@post = Fabricate(:post_with_images)
|
||||
end
|
||||
|
||||
it "adds a topic image if there's one in the post" do
|
||||
it "adds a topic image if there's one in the post" do
|
||||
@post.topic.reload
|
||||
@post.topic.image_url.should == "/path/to/img.jpg"
|
||||
end
|
||||
|
@ -79,31 +79,31 @@ EXPECTED
|
|||
end
|
||||
end
|
||||
|
||||
context 'link convertor' do
|
||||
before do
|
||||
context 'link convertor' do
|
||||
before do
|
||||
SiteSetting.stubs(:crawl_images?).returns(true)
|
||||
end
|
||||
|
||||
let :post_with_img do
|
||||
|
||||
let :post_with_img do
|
||||
Fabricate.build(:post, cooked: '<p><img src="http://hello.com/image.png"></p>')
|
||||
end
|
||||
|
||||
let :cpp_for_post do
|
||||
let :cpp_for_post do
|
||||
CookedPostProcessor.new(post_with_img)
|
||||
end
|
||||
|
||||
it 'convert img tags to links if they are sized down' do
|
||||
it 'convert img tags to links if they are sized down' do
|
||||
cpp_for_post.expects(:get_size).returns([2000,2000]).twice
|
||||
cpp_for_post.post_process
|
||||
cpp_for_post.post_process
|
||||
cpp_for_post.html.should =~ /a href/
|
||||
end
|
||||
|
||||
it 'does not convert img tags to links if they are small' do
|
||||
it 'does not convert img tags to links if they are small' do
|
||||
cpp_for_post.expects(:get_size).returns([200,200]).twice
|
||||
cpp_for_post.post_process
|
||||
cpp_for_post.post_process
|
||||
(cpp_for_post.html !~ /a href/).should be_true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
context 'image_dimensions' do
|
||||
|
@ -126,7 +126,7 @@ EXPECTED
|
|||
SiteSetting.expects(:crawl_images?).returns(true)
|
||||
FastImage.expects(:size).with(@url)
|
||||
cpp.image_dimensions(@url)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,14 +2,14 @@ require 'spec_helper'
|
|||
require_dependency 'current_user'
|
||||
|
||||
describe CurrentUser do
|
||||
it "allows us to lookup a user from our environment" do
|
||||
it "allows us to lookup a user from our environment" do
|
||||
token = EmailToken.generate_token
|
||||
user = Fabricate.build(:user)
|
||||
User.expects(:where).returns([user])
|
||||
CurrentUser.lookup_from_env("HTTP_COOKIE" => "_t=#{token};").should == user
|
||||
end
|
||||
|
||||
# it "allows us to lookup a user from our app" do
|
||||
# it "allows us to lookup a user from our app" do
|
||||
# end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'discourse_plugin_registry'
|
|||
describe DiscoursePluginRegistry do
|
||||
|
||||
let(:registry) { DiscoursePluginRegistry.new }
|
||||
|
||||
|
||||
context '#stylesheets' do
|
||||
it 'defaults to an empty Set' do
|
||||
DiscoursePluginRegistry.stylesheets = nil
|
||||
|
@ -37,7 +37,7 @@ describe DiscoursePluginRegistry do
|
|||
|
||||
it "won't add the same file twice" do
|
||||
lambda { registry.register_css('hello.css') }.should_not change(registry.stylesheets, :size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context '.register_js' do
|
||||
|
@ -51,7 +51,7 @@ describe DiscoursePluginRegistry do
|
|||
|
||||
it "won't add the same file twice" do
|
||||
lambda { registry.register_js('hello.js') }.should_not change(registry.javascripts, :size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context '.register_archetype' do
|
||||
|
|
|
@ -48,7 +48,7 @@ describe Discourse do
|
|||
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@ require 'spec_helper'
|
|||
require 'distributed_hash'
|
||||
|
||||
describe DiscoursePluginRegistry do
|
||||
# it 'should sync the sets across instances' do
|
||||
# it 'should sync the sets across instances' do
|
||||
# h1 = DistributedHash.new(:hash)
|
||||
# h2 = DistributedHash.new(:hash)
|
||||
|
||||
# h1[:hello] = "world"
|
||||
# h1[:hello] = "world"
|
||||
# h2[:hello].should == "world"
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ describe EmailSender do
|
|||
|
||||
context 'with a valid message' do
|
||||
|
||||
let(:message) do
|
||||
let(:message) do
|
||||
message = Mail::Message.new to: 'eviltrout@test.domain',
|
||||
body: '**hello**'
|
||||
message.stubs(:deliver)
|
||||
|
@ -67,22 +67,22 @@ describe EmailSender do
|
|||
email_sender.send
|
||||
end
|
||||
|
||||
it 'makes the message multipart' do
|
||||
it 'makes the message multipart' do
|
||||
message.should be_multipart
|
||||
end
|
||||
|
||||
it 'has a html part' do
|
||||
it 'has a html part' do
|
||||
message.parts.detect {|p| p.content_type == "text/html; charset=UTF-8"}.should be_true
|
||||
end
|
||||
|
||||
context 'html part' do
|
||||
let(:html_part) { message.parts.detect {|p| p.content_type == "text/html; charset=UTF-8"} }
|
||||
|
||||
it 'has a html part' do
|
||||
it 'has a html part' do
|
||||
html_part.should be_present
|
||||
end
|
||||
|
||||
it 'has run markdown on the body' do
|
||||
it 'has run markdown on the body' do
|
||||
html_part.body.to_s.should == "<p><strong>hello</strong></p>"
|
||||
end
|
||||
|
||||
|
@ -95,7 +95,7 @@ describe EmailSender do
|
|||
end
|
||||
|
||||
context 'with a user' do
|
||||
let(:message) do
|
||||
let(:message) do
|
||||
message = Mail::Message.new to: 'eviltrout@test.domain', body: 'test body'
|
||||
message.stubs(:deliver)
|
||||
message
|
||||
|
|
|
@ -11,11 +11,11 @@ describe Email do
|
|||
it 'should treat a bad email as invalid' do
|
||||
Email.is_valid?('sam@sam').should be_false
|
||||
end
|
||||
|
||||
|
||||
it 'should allow museum tld' do
|
||||
Email.is_valid?('sam@nic.museum').should be_true
|
||||
end
|
||||
|
||||
|
||||
it 'should not think a word is an email' do
|
||||
Email.is_valid?('sam').should be_false
|
||||
end
|
||||
|
|
|
@ -45,7 +45,7 @@ describe Guardian do
|
|||
Guardian.new(user).post_can_act?(post, :like, taken_actions: {PostActionType.Types[:like] => 1}).should be_false
|
||||
end
|
||||
|
||||
it "returns false when you already flagged a post" do
|
||||
it "returns false when you already flagged a post" do
|
||||
Guardian.new(user).post_can_act?(post, :off_topic, taken_actions: {PostActionType.Types[:spam] => 1}).should be_false
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,7 @@ describe Guardian do
|
|||
end
|
||||
|
||||
|
||||
describe "can_clear_flags" do
|
||||
describe "can_clear_flags" do
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:user) { post.user }
|
||||
let(:moderator) { Fabricate(:moderator) }
|
||||
|
@ -97,7 +97,7 @@ describe Guardian do
|
|||
|
||||
it "returns false when the user is nil" do
|
||||
Guardian.new(nil).can_send_private_message?(user).should be_false
|
||||
end
|
||||
end
|
||||
|
||||
it "returns false when the target user is nil" do
|
||||
Guardian.new(user).can_send_private_message?(nil).should be_false
|
||||
|
@ -320,7 +320,7 @@ describe Guardian do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
it "allows new posts from moderators" do
|
||||
Guardian.new(moderator).can_create?(Post, topic).should be_true
|
||||
end
|
||||
|
@ -341,8 +341,8 @@ describe Guardian do
|
|||
end
|
||||
|
||||
describe 'a Post' do
|
||||
|
||||
let (:guardian) do
|
||||
|
||||
let (:guardian) do
|
||||
Guardian.new(user)
|
||||
end
|
||||
|
||||
|
@ -361,14 +361,14 @@ describe Guardian do
|
|||
|
||||
it "allows voting if the user has performed a different action" do
|
||||
guardian.post_can_act?(post,:vote,taken_actions: {PostActionType.Types[:like] => 1}).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "isn't allowed on archived topics" do
|
||||
topic.archived = true
|
||||
Guardian.new(user).post_can_act?(post,:like).should be_false
|
||||
end
|
||||
|
||||
|
||||
|
||||
describe 'multiple voting' do
|
||||
|
||||
it "isn't allowed if the user voted and the topic doesn't allow multiple votes" do
|
||||
|
@ -490,7 +490,7 @@ describe Guardian do
|
|||
|
||||
it 'returns true when trying to edit yourself' do
|
||||
Guardian.new(user).can_edit?(user).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns false as a moderator' do
|
||||
Guardian.new(moderator).can_edit?(user).should be_false
|
||||
|
@ -527,7 +527,7 @@ describe Guardian do
|
|||
Guardian.new(admin).can_moderate?(topic).should be_true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -578,7 +578,7 @@ describe Guardian do
|
|||
Guardian.new(admin).can_move_posts?(topic).should be_true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -735,11 +735,11 @@ describe Guardian do
|
|||
end
|
||||
|
||||
it 'wont allow an admin to grant their own access' do
|
||||
Guardian.new(admin).can_grant_admin?(admin).should be_false
|
||||
Guardian.new(admin).can_grant_admin?(admin).should be_false
|
||||
end
|
||||
|
||||
it "allows an admin to grant a regular user access" do
|
||||
Guardian.new(admin).can_grant_admin?(user).should be_true
|
||||
Guardian.new(admin).can_grant_admin?(user).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -753,11 +753,11 @@ describe Guardian do
|
|||
end
|
||||
|
||||
it 'wont allow an admin to revoke their own access' do
|
||||
Guardian.new(admin).can_revoke_admin?(admin).should be_false
|
||||
Guardian.new(admin).can_revoke_admin?(admin).should be_false
|
||||
end
|
||||
|
||||
it "allows an admin to revoke another admin's access" do
|
||||
Guardian.new(admin).can_revoke_admin?(another_admin).should be_true
|
||||
Guardian.new(admin).can_revoke_admin?(another_admin).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -771,15 +771,15 @@ describe Guardian do
|
|||
end
|
||||
|
||||
it 'wont allow an admin to grant their own access' do
|
||||
Guardian.new(admin).can_grant_moderation?(admin).should be_false
|
||||
Guardian.new(admin).can_grant_moderation?(admin).should be_false
|
||||
end
|
||||
|
||||
it 'wont allow an admin to grant it to an already moderator' do
|
||||
Guardian.new(admin).can_grant_moderation?(moderator).should be_false
|
||||
Guardian.new(admin).can_grant_moderation?(moderator).should be_false
|
||||
end
|
||||
|
||||
it "allows an admin to grant a regular user access" do
|
||||
Guardian.new(admin).can_grant_moderation?(user).should be_true
|
||||
Guardian.new(admin).can_grant_moderation?(user).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -793,11 +793,11 @@ describe Guardian do
|
|||
end
|
||||
|
||||
it 'wont allow an moderator to revoke their own moderator' do
|
||||
Guardian.new(moderator).can_revoke_moderation?(moderator).should be_false
|
||||
Guardian.new(moderator).can_revoke_moderation?(moderator).should be_false
|
||||
end
|
||||
|
||||
it "allows an admin to revoke a moderator's access" do
|
||||
Guardian.new(admin).can_revoke_moderation?(moderator).should be_true
|
||||
Guardian.new(admin).can_revoke_moderation?(moderator).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -818,4 +818,4 @@ describe Guardian do
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ describe ImageSizer do
|
|||
it 'resizes the height retaining the aspect ratio' do
|
||||
@h.should == 102
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
|
||||
|
||||
describe '#target_users' do
|
||||
|
||||
|
||||
context 'disabled digests' do
|
||||
let!(:user_no_digests) { Fabricate(:user, email_digests: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) }
|
||||
|
||||
|
@ -19,7 +19,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
|
||||
it "doesn't return users who have been emailed recently" do
|
||||
Jobs::EnqueueDigestEmails.new.target_users.include?(user_emailed_recently).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'visited the site today' do
|
||||
|
@ -27,7 +27,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
|
||||
it "doesn't return users who have been emailed recently" do
|
||||
Jobs::EnqueueDigestEmails.new.target_users.include?(user_visited_today).should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ describe Jobs::FeatureTopicUsers do
|
|||
topic.reload.featured_user_ids.include?(coding_horror.id).should be_true
|
||||
end
|
||||
|
||||
it "will not feature the second poster if we supply their post to be ignored" do
|
||||
it "will not feature the second poster if we supply their post to be ignored" do
|
||||
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id, except_post_id: second_post.id)
|
||||
topic.reload.featured_user_ids.include?(coding_horror.id).should be_false
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ describe Jobs::Base do
|
|||
it 'converts to an indifferent access hash' do
|
||||
Jobs::Base.any_instance.expects(:execute).with(instance_of(HashWithIndifferentAccess))
|
||||
Jobs::Base.new.perform('hello' => 'world', 'sync_exec' => true)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'jobs/process_post'
|
|||
describe Jobs::ProcessPost do
|
||||
|
||||
it "returns when the post cannot be found" do
|
||||
lambda { Jobs::ProcessPost.new.perform(post_id: 1, sync_exec: true) }.should_not raise_error
|
||||
lambda { Jobs::ProcessPost.new.perform(post_id: 1, sync_exec: true) }.should_not raise_error
|
||||
end
|
||||
|
||||
context 'with a post' do
|
||||
|
@ -29,7 +29,7 @@ describe Jobs::ProcessPost do
|
|||
CookedPostProcessor.any_instance.expects(:dirty?).returns(false)
|
||||
Post.any_instance.expects(:update_column).never
|
||||
Jobs::ProcessPost.new.execute(post_id: @post.id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ describe Jobs::SendSystemMessage do
|
|||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it "should call SystemMessage.create" do
|
||||
it "should call SystemMessage.create" do
|
||||
SystemMessage.any_instance.expects(:create).with('welcome_invite')
|
||||
Jobs::SendSystemMessage.new.execute(user_id: user.id, message_type: 'welcome_invite')
|
||||
Jobs::SendSystemMessage.new.execute(user_id: user.id, message_type: 'welcome_invite')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@ describe Jobs::UserEmail do
|
|||
it "doesn't call the mailer when the user is missing" do
|
||||
UserNotifications.expects(:digest).never
|
||||
Jobs::UserEmail.new.execute(type: :digest, user_id: 1234)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'to_address' do
|
||||
|
@ -34,12 +34,12 @@ describe Jobs::UserEmail do
|
|||
EmailSender.any_instance.expects(:send)
|
||||
Jobs::UserEmail.new.execute(type: :authorize_email, user_id: user.id, to_address: 'jake@adventuretime.ooo')
|
||||
mailer.to.should == ['jake@adventuretime.ooo']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "recently seen" do
|
||||
let(:post) { Fabricate(:post, user: user) }
|
||||
|
||||
|
||||
it "doesn't send an email to a user that's been recently seen" do
|
||||
user.update_column(:last_seen_at, 9.minutes.ago)
|
||||
EmailSender.any_instance.expects(:send).never
|
||||
|
@ -48,7 +48,7 @@ describe Jobs::UserEmail do
|
|||
end
|
||||
|
||||
context 'args' do
|
||||
|
||||
|
||||
it 'passes a token as an argument when a token is present' do
|
||||
UserNotifications.expects(:forgot_password).with(user, {email_token: 'asdfasdf'}).returns(mailer)
|
||||
EmailSender.any_instance.expects(:send)
|
||||
|
@ -88,7 +88,7 @@ describe Jobs::UserEmail do
|
|||
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ describe MultisiteI18n do
|
|||
context "with a value for the multisite key" do
|
||||
it "returns the overwritten value" do
|
||||
MultisiteI18n.site_translate('other_site', 'test').should == "overwritten i18n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when we call t, it uses the current site" do
|
||||
|
@ -34,4 +34,4 @@ describe MultisiteI18n do
|
|||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,15 +9,15 @@ describe Oneboxer::AmazonOnebox do
|
|||
@o = Oneboxer::AmazonOnebox.new("http://www.amazon.com/Ruby-Programming-Language-David-Flanagan/dp/0596516177")
|
||||
FakeWeb.register_uri(:get, @o.translate_url, :response => fixture_file('oneboxer/amazon.response'))
|
||||
end
|
||||
|
||||
|
||||
it "translates the URL" do
|
||||
@o.translate_url.should == "http://www.amazon.com/gp/aw/d/0596516177"
|
||||
end
|
||||
|
||||
|
||||
it "generates the expected onebox for Amazon" do
|
||||
@o.onebox.should == expected_amazon_result
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def expected_amazon_result
|
||||
<<EXPECTED
|
||||
|
@ -41,4 +41,4 @@ The Ruby Programming Language is the authoritative guide to Ruby ...
|
|||
</div>
|
||||
EXPECTED
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,16 +4,16 @@ require 'spec_helper'
|
|||
require 'oneboxer'
|
||||
require 'oneboxer/android_app_store_onebox'
|
||||
|
||||
describe Oneboxer::AndroidAppStoreOnebox do
|
||||
describe Oneboxer::AndroidAppStoreOnebox do
|
||||
before(:each) do
|
||||
@o = Oneboxer::AndroidAppStoreOnebox.new("https://play.google.com/store/apps/details?id=com.moosoft.parrot")
|
||||
FakeWeb.register_uri(:get, @o.translate_url, :response => fixture_file('oneboxer/android.response'))
|
||||
end
|
||||
|
||||
|
||||
it "generates the expected onebox for Android App Store" do
|
||||
@o.onebox.should == expected_android_app_store_result
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def expected_android_app_store_result
|
||||
<<EXPECTED
|
||||
|
@ -38,4 +38,4 @@ private
|
|||
</div>
|
||||
EXPECTED
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,11 +9,11 @@ describe Oneboxer::AppleAppOnebox do
|
|||
@o = Oneboxer::AppleAppOnebox.new("https://itunes.apple.com/us/app/minecraft-pocket-edition-lite/id479651754")
|
||||
FakeWeb.register_uri(:get, @o.translate_url, :response => fixture_file('oneboxer/apple.response'))
|
||||
end
|
||||
|
||||
|
||||
it "generates the expected onebox for Apple app" do
|
||||
@o.onebox.should == expected_apple_app_result
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def expected_apple_app_result
|
||||
<<EXPECTED
|
||||
|
@ -35,4 +35,4 @@ private
|
|||
</div>
|
||||
EXPECTED
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,18 +4,18 @@ require 'spec_helper'
|
|||
require 'oneboxer'
|
||||
require 'oneboxer/flickr_onebox'
|
||||
|
||||
describe Oneboxer::FlickrOnebox do
|
||||
describe Oneboxer::FlickrOnebox do
|
||||
before(:each) do
|
||||
@o = Oneboxer::FlickrOnebox.new("http://www.flickr.com/photos/jaimeiniesta/3303881265")
|
||||
FakeWeb.register_uri(:get, @o.translate_url, :response => fixture_file('oneboxer/flickr.response'))
|
||||
end
|
||||
|
||||
|
||||
it "generates the expected onebox for Flickr" do
|
||||
@o.onebox.should == expected_flickr_result
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def expected_flickr_result
|
||||
"<a href='http://www.flickr.com/photos/jaimeiniesta/3303881265' target='_blank'><img src='http://farm4.staticflickr.com/3419/3303881265_c6924748e8_z.jpg' alt=''></a>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,8 +2,8 @@ require 'spec_helper'
|
|||
require 'oneboxer'
|
||||
require 'oneboxer/gist_onebox'
|
||||
|
||||
describe Oneboxer::GistOnebox do
|
||||
it "does not trip on user names" do
|
||||
describe Oneboxer::GistOnebox do
|
||||
it "does not trip on user names" do
|
||||
o = Oneboxer::GistOnebox.new('https://gist.github.com/aaa/4599619')
|
||||
o.translate_url.should == 'https://api.github.com/gists/4599619'
|
||||
end
|
||||
|
|
|
@ -10,11 +10,11 @@ describe Oneboxer::WikipediaOnebox do
|
|||
FakeWeb.register_uri(:get, @o.translate_url, :response => fixture_file('oneboxer/wikipedia.response'))
|
||||
FakeWeb.register_uri(:get, 'http://en.m.wikipedia.org/wiki/Ruby', :response => fixture_file('oneboxer/wikipedia_redirected.response'))
|
||||
end
|
||||
|
||||
|
||||
it "generates the expected onebox for Wikipedia" do
|
||||
@o.onebox.should == expected_wikipedia_result
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def expected_wikipedia_result
|
||||
<<EXPECTED
|
||||
|
@ -36,4 +36,4 @@ private
|
|||
</div>
|
||||
EXPECTED
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
require 'spec_helper'
|
||||
require 'oneboxer'
|
||||
|
||||
describe "Dynamic Oneboxer" do
|
||||
describe "Dynamic Oneboxer" do
|
||||
class DummyDynamicOnebox < Oneboxer::BaseOnebox
|
||||
matcher do
|
||||
matcher do
|
||||
/^https?:\/\/dummy2.localhost/
|
||||
end
|
||||
|
||||
|
||||
def onebox
|
||||
"dummy2!"
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ describe Oneboxer do
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
before do
|
||||
Oneboxer.add_onebox DummyOnebox
|
||||
@dummy_onebox_url = "http://dummy.localhost/dummy-object"
|
||||
|
@ -72,7 +72,7 @@ describe Oneboxer do
|
|||
|
||||
end
|
||||
|
||||
context 'without caching' do
|
||||
context 'without caching' do
|
||||
it 'calls the onebox method of our matched class' do
|
||||
Oneboxer.onebox_nocache(@dummy_onebox_url).should == 'dummy!'
|
||||
end
|
||||
|
@ -108,7 +108,7 @@ describe Oneboxer do
|
|||
end
|
||||
|
||||
it "created a OneboxRender record with the url" do
|
||||
@onebox_render.url.should == @dummy_onebox_url
|
||||
@onebox_render.url.should == @dummy_onebox_url
|
||||
end
|
||||
|
||||
it "associated the render with a post" do
|
||||
|
@ -157,11 +157,11 @@ describe Oneboxer do
|
|||
element.is_a?(Nokogiri::XML::Element).should be_true
|
||||
url.should == 'http://discourse.org'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ describe PostCreator do
|
|||
it 'passes the image sizes through' do
|
||||
Post.any_instance.expects(:image_sizes=).with(image_sizes)
|
||||
creator_with_image_sizes.create
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -74,7 +74,7 @@ describe PostCreator do
|
|||
|
||||
it "passes through the reply_to_post_number" do
|
||||
creator.create.reply_to_post_number.should == 4
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -89,11 +89,11 @@ describe PostCreator do
|
|||
target_usernames: [target_user1.username, target_user2.username].join(','))
|
||||
end
|
||||
|
||||
it 'has the right archetype' do
|
||||
it 'has the right archetype' do
|
||||
post.topic.archetype.should == Archetype.private_message
|
||||
end
|
||||
|
||||
it 'has the right count (me and 2 other users)' do
|
||||
it 'has the right count (me and 2 other users)' do
|
||||
post.topic.topic_allowed_users.count.should == 3
|
||||
end
|
||||
end
|
||||
|
|
|
@ -117,7 +117,7 @@ describe PostRevisor do
|
|||
|
||||
describe 'category topic' do
|
||||
|
||||
let!(:category) do
|
||||
let!(:category) do
|
||||
category = Fabricate(:category)
|
||||
category.update_column(:topic_id, topic.id)
|
||||
category
|
||||
|
@ -156,7 +156,7 @@ describe PostRevisor do
|
|||
|
||||
it "updates the description of the category" do
|
||||
category.description.should == new_description
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when updating back to the original paragraph' do
|
||||
|
|
|
@ -3,55 +3,55 @@ require 'pretty_text'
|
|||
|
||||
describe PrettyText do
|
||||
|
||||
describe "Cooking" do
|
||||
describe "Cooking" do
|
||||
it "should support github style code blocks" do
|
||||
PrettyText.cook("```
|
||||
test
|
||||
```").should == "<pre><code class=\"lang-auto\">test \n</code></pre>"
|
||||
end
|
||||
|
||||
it "should support quoting [] " do
|
||||
it "should support quoting [] " do
|
||||
PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"][sam][/quote]").should =~ /\[sam\]/
|
||||
end
|
||||
|
||||
it "produces a quote even with new lines in it" do
|
||||
PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd\n[/quote]").should == "<p></p><aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">\n <div class=\"quote-controls\"></div>\n <img width=\"20\" height=\"20\" src=\"/users/eviltrout/avatar/40?__ws=http%3A%2F%2Ftest.localhost\" class=\"avatar \" title=\"\">\n EvilTrout\n said:\n </div>\n <blockquote>ddd</blockquote>\n</aside><p></p>"
|
||||
it "produces a quote even with new lines in it" do
|
||||
PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd\n[/quote]").should == "<p></p><aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">\n <div class=\"quote-controls\"></div>\n <img width=\"20\" height=\"20\" src=\"/users/eviltrout/avatar/40?__ws=http%3A%2F%2Ftest.localhost\" class=\"avatar \" title=\"\">\n EvilTrout\n said:\n </div>\n <blockquote>ddd</blockquote>\n</aside><p></p>"
|
||||
end
|
||||
|
||||
it "should produce a quote" do
|
||||
PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd[/quote]").should == "<p></p><aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">\n <div class=\"quote-controls\"></div>\n <img width=\"20\" height=\"20\" src=\"/users/eviltrout/avatar/40?__ws=http%3A%2F%2Ftest.localhost\" class=\"avatar \" title=\"\">\n EvilTrout\n said:\n </div>\n <blockquote>ddd</blockquote>\n</aside><p></p>"
|
||||
it "should produce a quote" do
|
||||
PrettyText.cook("[quote=\"EvilTrout, post:123, topic:456, full:true\"]ddd[/quote]").should == "<p></p><aside class=\"quote\" data-post=\"123\" data-topic=\"456\" data-full=\"true\"><div class=\"title\">\n <div class=\"quote-controls\"></div>\n <img width=\"20\" height=\"20\" src=\"/users/eviltrout/avatar/40?__ws=http%3A%2F%2Ftest.localhost\" class=\"avatar \" title=\"\">\n EvilTrout\n said:\n </div>\n <blockquote>ddd</blockquote>\n</aside><p></p>"
|
||||
end
|
||||
|
||||
it "trims spaces on quote params" do
|
||||
PrettyText.cook("[quote=\"EvilTrout, post:555, topic: 666\"]ddd[/quote]").should == "<p></p><aside class=\"quote\" data-post=\"555\" data-topic=\"666\"><div class=\"title\">\n <div class=\"quote-controls\"></div>\n <img width=\"20\" height=\"20\" src=\"/users/eviltrout/avatar/40?__ws=http%3A%2F%2Ftest.localhost\" class=\"avatar \" title=\"\">\n EvilTrout\n said:\n </div>\n <blockquote>ddd</blockquote>\n</aside><p></p>"
|
||||
PrettyText.cook("[quote=\"EvilTrout, post:555, topic: 666\"]ddd[/quote]").should == "<p></p><aside class=\"quote\" data-post=\"555\" data-topic=\"666\"><div class=\"title\">\n <div class=\"quote-controls\"></div>\n <img width=\"20\" height=\"20\" src=\"/users/eviltrout/avatar/40?__ws=http%3A%2F%2Ftest.localhost\" class=\"avatar \" title=\"\">\n EvilTrout\n said:\n </div>\n <blockquote>ddd</blockquote>\n</aside><p></p>"
|
||||
end
|
||||
|
||||
|
||||
it "should handle 3 mentions in a row" do
|
||||
it "should handle 3 mentions in a row" do
|
||||
PrettyText.cook('@hello @hello @hello').should == "<p><span class=\"mention\">@hello</span> <span class=\"mention\">@hello</span> <span class=\"mention\">@hello</span></p>"
|
||||
end
|
||||
|
||||
it "should not do weird @ mention stuff inside a pre block" do
|
||||
|
||||
it "should not do weird @ mention stuff inside a pre block" do
|
||||
|
||||
PrettyText.cook("```
|
||||
a @test
|
||||
```").should == "<pre><code class=\"lang-auto\">a @test \n</code></pre>"
|
||||
|
||||
|
||||
end
|
||||
|
||||
it "should sanitize the html" do
|
||||
PrettyText.cook("<script>alert(42)</script>").should == "alert(42)"
|
||||
end
|
||||
|
||||
it "should escape html within the code block" do
|
||||
|
||||
it "should escape html within the code block" do
|
||||
|
||||
PrettyText.cook("```text
|
||||
<header>hello</header>
|
||||
```").should == "<pre><code class=\"text\"><header>hello</header> \n</code></pre>"
|
||||
end
|
||||
|
||||
it "should support language choices" do
|
||||
|
||||
it "should support language choices" do
|
||||
|
||||
PrettyText.cook("```ruby
|
||||
test
|
||||
```").should == "<pre><code class=\"ruby\">test \n</code></pre>"
|
||||
|
@ -70,81 +70,81 @@ test
|
|||
PrettyText.cook("[spoiler]hello[/spoiler]").should == "<p><span class=\"spoiler\">hello</span></p>"
|
||||
end
|
||||
|
||||
it "should only detect ``` at the begining of lines" do
|
||||
it "should only detect ``` at the begining of lines" do
|
||||
PrettyText.cook(" ```\n hello\n ```")
|
||||
.should == "<pre><code>```\nhello\n```\n</code></pre>"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "rel nofollow" do
|
||||
before do
|
||||
before do
|
||||
SiteSetting.stubs(:add_rel_nofollow_to_user_content).returns(true)
|
||||
SiteSetting.stubs(:exclude_rel_nofollow_domains).returns("foo.com,bar.com")
|
||||
end
|
||||
|
||||
it "should inject nofollow in all user provided links" do
|
||||
it "should inject nofollow in all user provided links" do
|
||||
PrettyText.cook('<a href="http://cnn.com">cnn</a>').should =~ /nofollow/
|
||||
end
|
||||
|
||||
it "should not inject nofollow in all local links" do
|
||||
(PrettyText.cook("<a href='#{Discourse.base_url}/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
|
||||
it "should not inject nofollow in all local links" do
|
||||
(PrettyText.cook("<a href='#{Discourse.base_url}/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
end
|
||||
|
||||
it "should not inject nofollow in all subdomain links" do
|
||||
(PrettyText.cook("<a href='#{Discourse.base_url.sub('http://', 'http://bla.')}/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
|
||||
it "should not inject nofollow in all subdomain links" do
|
||||
(PrettyText.cook("<a href='#{Discourse.base_url.sub('http://', 'http://bla.')}/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
end
|
||||
|
||||
it "should not inject nofollow for foo.com" do
|
||||
(PrettyText.cook("<a href='http://foo.com/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
(PrettyText.cook("<a href='http://foo.com/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
end
|
||||
|
||||
|
||||
it "should not inject nofollow for bar.foo.com" do
|
||||
(PrettyText.cook("<a href='http://bar.foo.com/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
(PrettyText.cook("<a href='http://bar.foo.com/test.html'>cnn</a>") !~ /nofollow/).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe "Excerpt" do
|
||||
it "should preserve links" do
|
||||
describe "Excerpt" do
|
||||
it "should preserve links" do
|
||||
PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>",100).should == "<a href='http://cnn.com'>cnn</a>"
|
||||
end
|
||||
|
||||
it "should dump images" do
|
||||
it "should dump images" do
|
||||
PrettyText.excerpt("<img src='http://cnn.com/a.gif'>",100).should == "[image]"
|
||||
end
|
||||
|
||||
it "should keep alt tags" do
|
||||
|
||||
it "should keep alt tags" do
|
||||
PrettyText.excerpt("<img src='http://cnn.com/a.gif' alt='car' title='my big car'>",100).should == "[car]"
|
||||
end
|
||||
|
||||
it "should keep title tags" do
|
||||
|
||||
it "should keep title tags" do
|
||||
PrettyText.excerpt("<img src='http://cnn.com/a.gif' title='car'>",100).should == "[car]"
|
||||
end
|
||||
|
||||
it "should deal with special keys properly" do
|
||||
it "should deal with special keys properly" do
|
||||
PrettyText.excerpt("<pre><b></pre>",100).should == ""
|
||||
end
|
||||
|
||||
it "should truncate stuff properly" do
|
||||
it "should truncate stuff properly" do
|
||||
PrettyText.excerpt("hello world",5).should == "hello…"
|
||||
end
|
||||
|
||||
it "should insert a space between to Ps" do
|
||||
it "should insert a space between to Ps" do
|
||||
PrettyText.excerpt("<p>a</p><p>b</p>",5).should == "a b "
|
||||
end
|
||||
|
||||
it "should strip quotes" do
|
||||
it "should strip quotes" do
|
||||
PrettyText.excerpt("<aside class='quote'><p>a</p><p>b</p></aside>boom",5).should == "boom"
|
||||
end
|
||||
|
||||
it "should not count the surrounds of a link" do
|
||||
it "should not count the surrounds of a link" do
|
||||
PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>",3).should == "<a href='http://cnn.com'>cnn</a>"
|
||||
end
|
||||
|
||||
it "should truncate links" do
|
||||
it "should truncate links" do
|
||||
PrettyText.excerpt("<a href='http://cnn.com'>cnn</a>",2).should == "<a href='http://cnn.com'>cn…</a>"
|
||||
end
|
||||
|
||||
it "should be able to extract links" do
|
||||
it "should be able to extract links" do
|
||||
PrettyText.extract_links("<a href='http://cnn.com'>http://bla.com</a>").to_a.should == ["http://cnn.com"]
|
||||
end
|
||||
|
||||
|
@ -156,7 +156,7 @@ test
|
|||
PrettyText.extract_links("<aside class=\"quote\" data-topic=\"1234\" data-post=\"4567\">aside</aside>").to_a.should == ["/t/topic/1234/4567"]
|
||||
end
|
||||
|
||||
it "should not preserve tags in code blocks" do
|
||||
it "should not preserve tags in code blocks" do
|
||||
PrettyText.excerpt("<pre><code class='handlebars'><h3>Hours</h3></code></pre>",100).should == "<h3>Hours</h3>"
|
||||
end
|
||||
|
||||
|
@ -166,12 +166,12 @@ test
|
|||
end
|
||||
|
||||
|
||||
describe "apply cdn" do
|
||||
describe "apply cdn" do
|
||||
it "should detect bare links to images and apply a CDN" do
|
||||
PrettyText.apply_cdn("<a href='/hello.png'>hello</a><img src='/a.jpeg'>","http://a.com").should ==
|
||||
"<a href=\"http://a.com/hello.png\">hello</a><img src=\"http://a.com/a.jpeg\">"
|
||||
end
|
||||
it "should not touch non images" do
|
||||
it "should not touch non images" do
|
||||
PrettyText.apply_cdn("<a href='/hello'>hello</a>","http://a.com").should ==
|
||||
"<a href=\"/hello\">hello</a>"
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe RateLimiter do
|
|||
before do
|
||||
RateLimiter.stubs(:disabled?).returns(true)
|
||||
rate_limiter.performed!
|
||||
rate_limiter.performed!
|
||||
rate_limiter.performed!
|
||||
end
|
||||
|
||||
it "returns true for can_perform?" do
|
||||
|
@ -26,7 +26,7 @@ describe RateLimiter do
|
|||
context 'enabled' do
|
||||
before do
|
||||
RateLimiter.stubs(:disabled?).returns(false)
|
||||
rate_limiter.clear!
|
||||
rate_limiter.clear!
|
||||
end
|
||||
|
||||
context 'never done' do
|
||||
|
@ -93,7 +93,7 @@ describe RateLimiter do
|
|||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'score_calculator'
|
|||
describe ScoreCalculator do
|
||||
|
||||
before do
|
||||
@post = Fabricate(:post, reads: 111)
|
||||
@post = Fabricate(:post, reads: 111)
|
||||
@topic = @post.topic
|
||||
end
|
||||
|
||||
|
@ -23,14 +23,14 @@ describe ScoreCalculator do
|
|||
|
||||
it "won't update the site settings when the site settings don't match" do
|
||||
ScoreCalculator.new(reads: 3).calculate
|
||||
@topic.reload
|
||||
@topic.reload
|
||||
@topic.has_best_of.should be_false
|
||||
end
|
||||
|
||||
it "removes the best_of flag if the topic no longer qualifies" do
|
||||
@topic.update_column(:has_best_of, true)
|
||||
ScoreCalculator.new(reads: 3).calculate
|
||||
@topic.reload
|
||||
@topic.reload
|
||||
@topic.has_best_of.should be_false
|
||||
end
|
||||
|
||||
|
@ -40,7 +40,7 @@ describe ScoreCalculator do
|
|||
SiteSetting.expects(:best_of_score_threshold).returns(100)
|
||||
|
||||
ScoreCalculator.new(reads: 3).calculate
|
||||
@topic.reload
|
||||
@topic.reload
|
||||
@topic.has_best_of.should be_true
|
||||
end
|
||||
|
||||
|
|
|
@ -11,24 +11,24 @@ describe Search do
|
|||
nil
|
||||
end
|
||||
|
||||
context 'post indexing observer' do
|
||||
before do
|
||||
context 'post indexing observer' do
|
||||
before do
|
||||
@category = Fabricate(:category, name: 'america')
|
||||
@topic = Fabricate(:topic, title: 'sam test topic', category: @category)
|
||||
@post = Fabricate(:post, topic: @topic, raw: 'this <b>fun test</b> <img src="bla" title="my image">')
|
||||
@indexed = Topic.exec_sql("select search_data from posts_search where id = #{@post.id}").first["search_data"]
|
||||
end
|
||||
it "should include body in index" do
|
||||
it "should include body in index" do
|
||||
@indexed.should =~ /fun/
|
||||
end
|
||||
it "should include title in index" do
|
||||
it "should include title in index" do
|
||||
@indexed.should =~ /sam/
|
||||
end
|
||||
it "should include category in index" do
|
||||
it "should include category in index" do
|
||||
@indexed.should =~ /america/
|
||||
end
|
||||
|
||||
it "should pick up on title updates" do
|
||||
it "should pick up on title updates" do
|
||||
@topic.title = "harpi is the new title"
|
||||
@topic.save!
|
||||
@indexed = Topic.exec_sql("select search_data from posts_search where id = #{@post.id}").first["search_data"]
|
||||
|
@ -37,28 +37,28 @@ describe Search do
|
|||
end
|
||||
end
|
||||
|
||||
context 'user indexing observer' do
|
||||
before do
|
||||
context 'user indexing observer' do
|
||||
before do
|
||||
@user = Fabricate(:user, username: 'fred', name: 'bob jones')
|
||||
@indexed = User.exec_sql("select search_data from users_search where id = #{@user.id}").first["search_data"]
|
||||
end
|
||||
|
||||
it "should pick up on username" do
|
||||
it "should pick up on username" do
|
||||
@indexed.should =~ /fred/
|
||||
end
|
||||
|
||||
it "should pick up on name" do
|
||||
it "should pick up on name" do
|
||||
@indexed.should =~ /jone/
|
||||
end
|
||||
end
|
||||
|
||||
context 'category indexing observer' do
|
||||
before do
|
||||
context 'category indexing observer' do
|
||||
before do
|
||||
@category = Fabricate(:category, name: 'america')
|
||||
@indexed = Topic.exec_sql("select search_data from categories_search where id = #{@category.id}").first["search_data"]
|
||||
end
|
||||
|
||||
it "should pick up on name" do
|
||||
it "should pick up on name" do
|
||||
@indexed.should =~ /america/
|
||||
end
|
||||
|
||||
|
@ -103,9 +103,9 @@ describe Search do
|
|||
context 'topics' do
|
||||
let!(:topic) { Fabricate(:topic) }
|
||||
|
||||
context 'searching the OP' do
|
||||
context 'searching the OP' do
|
||||
|
||||
let!(:post) { Fabricate(:post, topic: topic, user: topic.user) }
|
||||
let!(:post) { Fabricate(:post, topic: topic, user: topic.user) }
|
||||
let(:result) { first_of_type(Search.query('hello'), 'topic') }
|
||||
|
||||
it 'returns a result' do
|
||||
|
@ -118,7 +118,7 @@ describe Search do
|
|||
|
||||
it 'has a url for the post' do
|
||||
result['url'].should == topic.relative_url
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -138,7 +138,7 @@ describe Search do
|
|||
|
||||
it 'has a url for the topic' do
|
||||
result['url'].should == "/category/#{category.slug}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -147,7 +147,7 @@ describe Search do
|
|||
|
||||
let!(:user) { Fabricate(:user, username: 'amazing', email: 'amazing@amazing.com') }
|
||||
let!(:category) { Fabricate(:category, name: 'amazing category', user: user) }
|
||||
|
||||
|
||||
|
||||
context 'user filter' do
|
||||
let(:results) { Search.query('amazing', 'user') }
|
||||
|
|
|
@ -17,11 +17,11 @@ describe Slug do
|
|||
Slug.for('evil#trout').should == 'evil-trout'
|
||||
end
|
||||
|
||||
it 'handles a.b.c properly' do
|
||||
it 'handles a.b.c properly' do
|
||||
Slug.for("a.b.c").should == "a-b-c"
|
||||
end
|
||||
|
||||
it 'handles double dots right' do
|
||||
it 'handles double dots right' do
|
||||
Slug.for("a....b.....c").should == "a-b-c"
|
||||
end
|
||||
|
||||
|
|
|
@ -4,12 +4,12 @@ require_dependency 'sql_builder'
|
|||
|
||||
describe SqlBuilder do
|
||||
|
||||
describe "attached" do
|
||||
before do
|
||||
describe "attached" do
|
||||
before do
|
||||
@builder = Post.sql_builder("select * from posts /*where*/ /*limit*/")
|
||||
end
|
||||
|
||||
it "should find a post by id" do
|
||||
it "should find a post by id" do
|
||||
p = Fabricate(:post)
|
||||
@builder.where('id = :id and topic_id = :topic_id', id: p.id, topic_id: p.topic_id)
|
||||
p2 = @builder.exec.first
|
||||
|
@ -18,18 +18,18 @@ describe SqlBuilder do
|
|||
end
|
||||
end
|
||||
|
||||
describe "detached" do
|
||||
before do
|
||||
describe "detached" do
|
||||
before do
|
||||
@builder = SqlBuilder.new("select * from (select :a A union all select :b) as X /*where*/ /*order_by*/ /*limit*/ /*offset*/")
|
||||
end
|
||||
|
||||
it "should allow for 1 param exec" do
|
||||
@builder.exec(a: 1, b: 2).values[0][0].should == '1'
|
||||
it "should allow for 1 param exec" do
|
||||
@builder.exec(a: 1, b: 2).values[0][0].should == '1'
|
||||
end
|
||||
|
||||
it "should allow for a single where" do
|
||||
it "should allow for a single where" do
|
||||
@builder.where(":a = 1")
|
||||
@builder.exec(a: 1, b: 2).values[0][0].should == '1'
|
||||
@builder.exec(a: 1, b: 2).values[0][0].should == '1'
|
||||
end
|
||||
|
||||
it "should allow where chaining" do
|
||||
|
|
|
@ -8,7 +8,7 @@ describe SystemMessage do
|
|||
context 'send' do
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:system_message) { SystemMessage.new(user) }
|
||||
let(:system_message) { SystemMessage.new(user) }
|
||||
let(:post) { system_message.create(:welcome_invite) }
|
||||
let(:topic) { post.topic }
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ describe TextSentinel do
|
|||
TextSentinel.new(valid_string, min_entropy: 16).should be_valid
|
||||
end
|
||||
|
||||
it "enforces the minimum entropy" do
|
||||
it "enforces the minimum entropy" do
|
||||
TextSentinel.new(valid_string, min_entropy: 17).should_not be_valid
|
||||
end
|
||||
|
||||
|
@ -110,7 +110,7 @@ describe TextSentinel do
|
|||
it "doesn't except junk symbols as a string" do
|
||||
TextSentinel.new("[[[").should_not be_valid
|
||||
TextSentinel.new("<<<").should_not be_valid
|
||||
TextSentinel.new("{{$!").should_not be_valid
|
||||
TextSentinel.new("{{$!").should_not be_valid
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -36,10 +36,10 @@ describe TopicQuery do
|
|||
end
|
||||
|
||||
context 'categorized' do
|
||||
let(:category) { Fabricate(:category) }
|
||||
let!(:topic_no_cat) { Fabricate(:topic) }
|
||||
let(:category) { Fabricate(:category) }
|
||||
let!(:topic_no_cat) { Fabricate(:topic) }
|
||||
let!(:topic_in_cat) { Fabricate(:topic, category: category) }
|
||||
|
||||
|
||||
it "returns the topic without a category when filtering uncategorized" do
|
||||
topic_query.list_uncategorized.topics.should == [topic_no_cat]
|
||||
end
|
||||
|
@ -89,12 +89,12 @@ describe TopicQuery do
|
|||
end
|
||||
end
|
||||
|
||||
context 'user with auto_track_topics list_unread' do
|
||||
before do
|
||||
context 'user with auto_track_topics list_unread' do
|
||||
before do
|
||||
user.auto_track_topics_after_msecs = 0
|
||||
user.save
|
||||
end
|
||||
|
||||
|
||||
it 'only contains the partially read topic' do
|
||||
topic_query.list_unread.topics.should == [partially_read]
|
||||
end
|
||||
|
@ -107,7 +107,7 @@ describe TopicQuery do
|
|||
context 'list_read' do
|
||||
it 'contain both topics ' do
|
||||
topic_query.list_read.topics.should =~ [fully_read, partially_read]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -122,7 +122,7 @@ describe TopicQuery do
|
|||
end
|
||||
|
||||
context 'with a favorited topic' do
|
||||
|
||||
|
||||
before do
|
||||
topic.toggle_star(user, true)
|
||||
end
|
||||
|
@ -147,7 +147,7 @@ describe TopicQuery do
|
|||
end
|
||||
|
||||
context 'with a new topic' do
|
||||
let!(:new_topic) { Fabricate(:topic, user: creator, bumped_at: 10.minutes.ago) }
|
||||
let!(:new_topic) { Fabricate(:topic, user: creator, bumped_at: 10.minutes.ago) }
|
||||
let(:topics) { topic_query.list_new.topics }
|
||||
|
||||
|
||||
|
@ -156,7 +156,7 @@ describe TopicQuery do
|
|||
end
|
||||
|
||||
it "contains no new topics for a user that has missed the window" do
|
||||
user.new_topic_duration_minutes = 5
|
||||
user.new_topic_duration_minutes = 5
|
||||
user.save
|
||||
new_topic.created_at = 10.minutes.ago
|
||||
new_topic.save
|
||||
|
@ -168,7 +168,7 @@ describe TopicQuery do
|
|||
new_topic.notify_muted!(user)
|
||||
end
|
||||
|
||||
it "returns an empty set" do
|
||||
it "returns an empty set" do
|
||||
topics.should be_blank
|
||||
end
|
||||
|
||||
|
@ -181,9 +181,9 @@ describe TopicQuery do
|
|||
topics.should == [new_topic]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
context 'list_posted' do
|
||||
|
@ -219,8 +219,8 @@ describe TopicQuery do
|
|||
let!(:new_topic) { Fabricate(:post, user: creator).topic }
|
||||
|
||||
it "should return the new topic" do
|
||||
TopicQuery.new.list_suggested_for(topic).topics.should == [new_topic]
|
||||
end
|
||||
TopicQuery.new.list_suggested_for(topic).topics.should == [new_topic]
|
||||
end
|
||||
end
|
||||
|
||||
context "anonymously browswing with invisible, closed and archived" do
|
||||
|
@ -231,7 +231,7 @@ describe TopicQuery do
|
|||
let!(:invisible_topic) { Fabricate(:topic, user: creator, visible: false) }
|
||||
|
||||
it "should omit the closed/archived/invisbiel topics from suggested" do
|
||||
TopicQuery.new.list_suggested_for(topic).topics.should == [regular_topic]
|
||||
TopicQuery.new.list_suggested_for(topic).topics.should == [regular_topic]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -247,7 +247,7 @@ describe TopicQuery do
|
|||
context 'with some existing topics' do
|
||||
let!(:partially_read) { Fabricate(:post, user: creator).topic }
|
||||
let!(:new_topic) { Fabricate(:post, user: creator).topic }
|
||||
let!(:fully_read) { Fabricate(:post, user: creator).topic }
|
||||
let!(:fully_read) { Fabricate(:post, user: creator).topic }
|
||||
let!(:closed_topic) { Fabricate(:topic, user: creator, closed: true) }
|
||||
let!(:archived_topic) { Fabricate(:topic, user: creator, archived: true) }
|
||||
let!(:invisible_topic) { Fabricate(:topic, user: creator, visible: false) }
|
||||
|
@ -274,7 +274,7 @@ describe TopicQuery do
|
|||
suggested_topics.should == [partially_read.id, new_topic.id, fully_read.id]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ describe TopicView do
|
|||
lambda { topic_view }.should raise_error(Discourse::InvalidAccess)
|
||||
end
|
||||
|
||||
it "raises NotLoggedIn if the user isn't logged in and is trying to view a private message" do
|
||||
it "raises NotLoggedIn if the user isn't logged in and is trying to view a private message" do
|
||||
Topic.any_instance.expects(:private_message?).returns(true)
|
||||
lambda { TopicView.new(topic.id, nil) }.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
@ -105,16 +105,16 @@ describe TopicView do
|
|||
end
|
||||
end
|
||||
|
||||
it 'allows admins to see deleted posts' do
|
||||
it 'allows admins to see deleted posts' do
|
||||
post_number = p3.post_number
|
||||
p3.destroy
|
||||
admin = Fabricate(:admin)
|
||||
topic_view = TopicView.new(topic.id, admin)
|
||||
topic_view = TopicView.new(topic.id, admin)
|
||||
topic_view.posts.count.should == 3
|
||||
topic_view.highest_post_number.should == post_number
|
||||
end
|
||||
|
||||
it 'does not allow non admins to see deleted posts' do
|
||||
|
||||
it 'does not allow non admins to see deleted posts' do
|
||||
p3.destroy
|
||||
topic_view.posts.count.should == 2
|
||||
end
|
||||
|
@ -138,7 +138,7 @@ describe TopicView do
|
|||
it "is allows users to see likes" do
|
||||
topic_view.post_action_visibility.include?(PostActionType.Types[:like]).should be_true
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
context '.read?' do
|
||||
|
@ -185,7 +185,7 @@ describe TopicView do
|
|||
|
||||
it 'is the inital load' do
|
||||
near_topic_view.should be_initial_load
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -231,7 +231,7 @@ describe TopicView do
|
|||
|
||||
it "isn't the inital load" do
|
||||
topic_view.should_not be_initial_load
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -264,7 +264,7 @@ describe TopicView do
|
|||
SiteSetting.stubs(:posts_per_page).returns(20)
|
||||
|
||||
post_numbers = ((1..20).to_a << [100, 105] << (110..150).to_a).flatten
|
||||
TopicView.any_instance.stubs(:post_numbers).returns(post_numbers)
|
||||
TopicView.any_instance.stubs(:post_numbers).returns(post_numbers)
|
||||
end
|
||||
|
||||
it "will return posts even if the post required is missing" do
|
||||
|
|
|
@ -18,19 +18,19 @@ describe Unread do
|
|||
@topic_user.stubs(:last_read_post_number).returns(13)
|
||||
@topic_user.stubs(:seen_post_count).returns(13)
|
||||
@unread.unread_posts.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
it 'should have 6 unread posts if the user has seen all but 6 posts' do
|
||||
@topic_user.stubs(:last_read_post_number).returns(5)
|
||||
@topic_user.stubs(:seen_post_count).returns(11)
|
||||
@topic_user.stubs(:seen_post_count).returns(11)
|
||||
@unread.unread_posts.should == 6
|
||||
end
|
||||
end
|
||||
|
||||
it 'should have 0 unread posts if the user has seen more posts than exist (deleted)' do
|
||||
@topic_user.stubs(:last_read_post_number).returns(100)
|
||||
@topic_user.stubs(:seen_post_count).returns(13)
|
||||
@unread.unread_posts.should == 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'new_posts' do
|
||||
|
@ -48,7 +48,7 @@ describe Unread do
|
|||
@topic_user.stubs(:seen_post_count).returns(10)
|
||||
@unread.new_posts.should == 3
|
||||
end
|
||||
|
||||
|
||||
it 'has 0 new posts if the user has read 10 posts but is not tracking' do
|
||||
@topic_user.stubs(:seen_post_count).returns(10)
|
||||
@topic_user.stubs(:notification_level).returns(TopicUser::NotificationLevel::REGULAR)
|
||||
|
@ -58,7 +58,7 @@ describe Unread do
|
|||
it 'has 0 new posts if the user read more posts than exist (deleted)' do
|
||||
@topic_user.stubs(:seen_post_count).returns(16)
|
||||
@unread.new_posts.should == 0
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ describe Admin::EmailLogsController do
|
|||
let!(:user) { log_in(:admin) }
|
||||
|
||||
context '.index' do
|
||||
before do
|
||||
before do
|
||||
xhr :get, :index
|
||||
end
|
||||
|
||||
|
@ -26,7 +26,7 @@ describe Admin::EmailLogsController do
|
|||
context 'with an email address' do
|
||||
|
||||
it 'enqueues a test email job' do
|
||||
Jobs.expects(:enqueue).with(:test_email, to_address: 'eviltrout@test.domain')
|
||||
Jobs.expects(:enqueue).with(:test_email, to_address: 'eviltrout@test.domain')
|
||||
xhr :post, :test, email_address: 'eviltrout@test.domain'
|
||||
end
|
||||
|
||||
|
@ -34,4 +34,4 @@ describe Admin::EmailLogsController do
|
|||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ describe Admin::ExportController do
|
|||
it "is a subclass of AdminController" do
|
||||
(Admin::ExportController < Admin::AdminController).should be_true
|
||||
end
|
||||
|
||||
|
||||
context 'while logged in as an admin' do
|
||||
before do
|
||||
@user = log_in(:admin)
|
||||
|
@ -54,4 +54,4 @@ describe Admin::ExportController do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,10 +23,10 @@ describe Admin::FlagsController do
|
|||
it 'returns a valid json payload when some thing is flagged' do
|
||||
p = Fabricate(:post)
|
||||
u = Fabricate(:user)
|
||||
|
||||
|
||||
PostAction.act(u, p, PostActionType.Types[:spam])
|
||||
xhr :get, :index
|
||||
|
||||
|
||||
data = ::JSON.parse(response.body)
|
||||
data["users"].length == 2
|
||||
data["posts"].length == 1
|
||||
|
@ -34,4 +34,4 @@ describe Admin::FlagsController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -50,12 +50,12 @@ describe Admin::ImpersonateController do
|
|||
it "also works with an email address" do
|
||||
xhr :post, :create, username_or_email: user.email
|
||||
session[:current_user_id].should == user.id
|
||||
end
|
||||
end
|
||||
|
||||
it "also works with a name" do
|
||||
xhr :post, :create, username_or_email: user.name
|
||||
session[:current_user_id].should == user.id
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -20,16 +20,16 @@ describe Admin::SiteCustomizationsController do
|
|||
it 'returns JSON' do
|
||||
xhr :get, :index
|
||||
::JSON.parse(response.body).should be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context ' .create' do
|
||||
it 'returns success' do
|
||||
it 'returns success' do
|
||||
xhr :post, :create, site_customization: {name: 'my test name'}
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'returns json' do
|
||||
|
||||
it 'returns json' do
|
||||
xhr :post, :create, site_customization: {name: 'my test name'}
|
||||
::JSON.parse(response.body).should be_present
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ describe Admin::SiteSettingsController do
|
|||
it 'returns JSON' do
|
||||
xhr :get, :index
|
||||
::JSON.parse(response.body).should be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'update' do
|
||||
|
@ -40,4 +40,4 @@ describe Admin::SiteSettingsController do
|
|||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ describe Admin::UsersController do
|
|||
it 'returns JSON' do
|
||||
xhr :get, :index
|
||||
::JSON.parse(response.body).should be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context '.show' do
|
||||
|
@ -81,7 +81,7 @@ describe Admin::UsersController do
|
|||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it 'updates the admin flag' do
|
||||
it 'updates the admin flag' do
|
||||
xhr :put, :revoke_admin, user_id: @another_admin.id
|
||||
@another_admin.reload
|
||||
@another_admin.should_not be_admin
|
||||
|
@ -99,12 +99,12 @@ describe Admin::UsersController do
|
|||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it "returns a 404 if the username doesn't exist" do
|
||||
it "returns a 404 if the username doesn't exist" do
|
||||
xhr :put, :grant_admin, user_id: 123123
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it 'updates the admin flag' do
|
||||
it 'updates the admin flag' do
|
||||
xhr :put, :grant_admin, user_id: @another_user.id
|
||||
@another_user.reload
|
||||
@another_user.should be_admin
|
||||
|
@ -122,7 +122,7 @@ describe Admin::UsersController do
|
|||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it 'updates the moderator flag' do
|
||||
it 'updates the moderator flag' do
|
||||
xhr :put, :revoke_moderation, user_id: @moderator.id
|
||||
@moderator.reload
|
||||
@moderator.has_trust_level?(:moderator).should_not be_true
|
||||
|
@ -140,12 +140,12 @@ describe Admin::UsersController do
|
|||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it "returns a 404 if the username doesn't exist" do
|
||||
it "returns a 404 if the username doesn't exist" do
|
||||
xhr :put, :grant_moderation, user_id: 123123
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it 'updates the moderator flag' do
|
||||
it 'updates the moderator flag' do
|
||||
xhr :put, :grant_moderation, user_id: @another_user.id
|
||||
@another_user.reload
|
||||
@another_user.has_trust_level?(:moderator).should be_true
|
||||
|
|
|
@ -65,19 +65,19 @@ describe CategoriesController do
|
|||
describe 'logged in' do
|
||||
before do
|
||||
@user = log_in
|
||||
@category = Fabricate(:category, user: @user)
|
||||
@category = Fabricate(:category, user: @user)
|
||||
end
|
||||
|
||||
it "raises an exception if they don't have permission to delete it" do
|
||||
Guardian.any_instance.expects(:can_delete_category?).returns(false)
|
||||
xhr :delete, :destroy, id: @category.slug
|
||||
response.should be_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
it "deletes the record" do
|
||||
Guardian.any_instance.expects(:can_delete_category?).returns(true)
|
||||
lambda { xhr :delete, :destroy, id: @category.slug}.should change(Category, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -90,7 +90,7 @@ describe CategoriesController do
|
|||
|
||||
|
||||
describe 'logged in' do
|
||||
before do
|
||||
before do
|
||||
@user = log_in(:moderator)
|
||||
@category = Fabricate(:category, user: @user)
|
||||
end
|
||||
|
@ -101,11 +101,11 @@ describe CategoriesController do
|
|||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it "requires a name" do
|
||||
it "requires a name" do
|
||||
lambda { xhr :put, :update, id: @category.slug, color: '#fff' }.should raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "requires a color" do
|
||||
it "requires a color" do
|
||||
lambda { xhr :put, :update, id: @category.slug, name: 'asdf'}.should raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
|
|
|
@ -25,19 +25,19 @@ describe ClicksController do
|
|||
context 'with a post_id' do
|
||||
it 'calls create_from' do
|
||||
TopicLinkClick.expects(:create_from).with(url: 'http://discourse.org', post_id: 123, ip: '192.168.0.1')
|
||||
xhr :get, :track, url: 'http://discourse.org', post_id: 123
|
||||
xhr :get, :track, url: 'http://discourse.org', post_id: 123
|
||||
response.should redirect_to("http://discourse.org")
|
||||
end
|
||||
|
||||
it 'redirects to the url' do
|
||||
TopicLinkClick.stubs(:create_from)
|
||||
xhr :get, :track, url: 'http://discourse.org', post_id: 123
|
||||
xhr :get, :track, url: 'http://discourse.org', post_id: 123
|
||||
response.should redirect_to("http://discourse.org")
|
||||
end
|
||||
|
||||
it 'will pass the user_id to create_from' do
|
||||
TopicLinkClick.expects(:create_from).with(url: 'http://discourse.org', post_id: 123, ip: '192.168.0.1')
|
||||
xhr :get, :track, url: 'http://discourse.org', post_id: 123
|
||||
xhr :get, :track, url: 'http://discourse.org', post_id: 123
|
||||
response.should redirect_to("http://discourse.org")
|
||||
end
|
||||
|
||||
|
@ -52,13 +52,13 @@ describe ClicksController do
|
|||
context 'with a topic_id' do
|
||||
it 'calls create_from' do
|
||||
TopicLinkClick.expects(:create_from).with(url: 'http://discourse.org', topic_id: 789, ip: '192.168.0.1')
|
||||
xhr :get, :track, url: 'http://discourse.org', topic_id: 789
|
||||
xhr :get, :track, url: 'http://discourse.org', topic_id: 789
|
||||
response.should redirect_to("http://discourse.org")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,11 +12,11 @@ describe DraftController do
|
|||
Draft.get(user, 'xyz', 0).should == 'my data'
|
||||
end
|
||||
|
||||
it 'destroys drafts when required' do
|
||||
it 'destroys drafts when required' do
|
||||
user = log_in
|
||||
Draft.set(user, 'xxx', 0, 'hi')
|
||||
delete :destroy, draft_key: 'xxx', sequence: 0
|
||||
Draft.get(user, 'xxx', 0).should be_nil
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ describe EducationController do
|
|||
end
|
||||
|
||||
context 'with a valid id' do
|
||||
|
||||
|
||||
let(:markdown_content) { "Education *markdown* content" }
|
||||
let(:html_content) {"HTML Content"}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ describe EmailController do
|
|||
|
||||
it 'sets not found' do
|
||||
assigns(:not_found).should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when logged in as the keyed user' do
|
||||
|
@ -86,7 +86,7 @@ describe EmailController do
|
|||
|
||||
it "doesn't set not found" do
|
||||
assigns(:not_found).should be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "sets not_found when the key didn't match anything" do
|
||||
|
|
|
@ -25,7 +25,7 @@ describe ExcerptController do
|
|||
xhr :get, :show, url: @url
|
||||
end
|
||||
|
||||
it 'returns a valid status' do
|
||||
it 'returns a valid status' do
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
|
@ -44,7 +44,7 @@ describe ExcerptController do
|
|||
xhr :get, :show, url: @url
|
||||
end
|
||||
|
||||
it 'returns a valid status' do
|
||||
it 'returns a valid status' do
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
|
@ -63,7 +63,7 @@ describe ExcerptController do
|
|||
xhr :get, :show, url: @url
|
||||
end
|
||||
|
||||
it 'returns a valid status' do
|
||||
it 'returns a valid status' do
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@ describe InvitesController do
|
|||
}.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
||||
context 'while logged in' do
|
||||
context 'while logged in' do
|
||||
let!(:user) { log_in }
|
||||
let!(:invite) { Fabricate(:invite, invited_by: user) }
|
||||
let(:another_invite) { Fabricate(:invite, email: 'anotheremail@address.com') }
|
||||
|
||||
|
||||
|
||||
it 'raises an error when the email is missing' do
|
||||
lambda { delete :destroy }.should raise_error(Discourse::InvalidParameters)
|
||||
|
@ -46,13 +46,13 @@ describe InvitesController do
|
|||
get :show, id: "doesn't exist"
|
||||
end
|
||||
|
||||
it "redirects to the root" do
|
||||
it "redirects to the root" do
|
||||
response.should redirect_to("/")
|
||||
end
|
||||
end
|
||||
|
||||
it "should not change the session" do
|
||||
it "should not change the session" do
|
||||
session[:current_user_id].should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -64,13 +64,13 @@ describe InvitesController do
|
|||
get :show, id: deleted_invite.invite_key
|
||||
end
|
||||
|
||||
it "redirects to the root" do
|
||||
it "redirects to the root" do
|
||||
response.should redirect_to("/")
|
||||
end
|
||||
end
|
||||
|
||||
it "should not change the session" do
|
||||
it "should not change the session" do
|
||||
session[:current_user_id].should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -78,7 +78,7 @@ describe InvitesController do
|
|||
context 'with a valid invite id' do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:invite) { topic.invite_by_email(topic.user, "iceking@adventuretime.ooo") }
|
||||
|
||||
|
||||
|
||||
it 'redeems the invite' do
|
||||
Invite.any_instance.expects(:redeem)
|
||||
|
@ -88,10 +88,10 @@ describe InvitesController do
|
|||
context 'when redeem returns a user' do
|
||||
let(:user) { Fabricate(:coding_horror) }
|
||||
|
||||
context 'success' do
|
||||
context 'success' do
|
||||
before do
|
||||
Invite.any_instance.expects(:redeem).returns(user)
|
||||
get :show, id: invite.invite_key
|
||||
get :show, id: invite.invite_key
|
||||
end
|
||||
|
||||
it 'logs in the user' do
|
||||
|
@ -109,13 +109,13 @@ describe InvitesController do
|
|||
Jobs.expects(:enqueue).with(:invite_email, has_key(:invite_id))
|
||||
end
|
||||
|
||||
it 'sends a welcome message if set' do
|
||||
user.send_welcome_message = true
|
||||
it 'sends a welcome message if set' do
|
||||
user.send_welcome_message = true
|
||||
user.expects(:enqueue_welcome_message).with('welcome_invite')
|
||||
get :show, id: invite.invite_key
|
||||
end
|
||||
|
||||
it "doesn't send a welcome message if not set" do
|
||||
it "doesn't send a welcome message if not set" do
|
||||
user.expects(:enqueue_welcome_message).with('welcome_invite').never
|
||||
get :show, id: invite.invite_key
|
||||
end
|
||||
|
@ -137,11 +137,11 @@ describe InvitesController do
|
|||
Invite.any_instance.expects(:redeem).returns(user)
|
||||
get :show, id: invite.invite_key
|
||||
cookies[:_access].should == 'adventure time!'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@ require 'spec_helper'
|
|||
|
||||
describe ListController do
|
||||
|
||||
# we need some data
|
||||
before do
|
||||
# we need some data
|
||||
before do
|
||||
@user = Fabricate(:coding_horror)
|
||||
@post = Fabricate(:post, :user => @user)
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ describe NotificationsController do
|
|||
context 'when logged in' do
|
||||
let!(:user) { log_in }
|
||||
|
||||
before do
|
||||
before do
|
||||
xhr :get, :index
|
||||
end
|
||||
|
||||
|
@ -16,7 +16,7 @@ describe NotificationsController do
|
|||
context 'when not logged in' do
|
||||
it 'should raise an error' do
|
||||
lambda { xhr :get, :index }.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ describe PostActionsController do
|
|||
it 'raises an error when the post_action_type_id index is missing' do
|
||||
lambda { xhr :post, :create, id: @post.id }.should raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
|
||||
it "fails when the user doesn't have permission to see the post" do
|
||||
Guardian.any_instance.expects(:can_see?).with(@post).returns(false)
|
||||
xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.Types[:like]
|
||||
|
@ -92,7 +92,7 @@ describe PostActionsController do
|
|||
context "not logged in" do
|
||||
it "should not allow them to clear flags" do
|
||||
lambda { xhr :post, :clear_flags }.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'logged in' do
|
||||
|
@ -103,21 +103,21 @@ describe PostActionsController do
|
|||
end
|
||||
|
||||
it "raises an error when the user doesn't have access" do
|
||||
Guardian.any_instance.expects(:can_clear_flags?).returns(false)
|
||||
Guardian.any_instance.expects(:can_clear_flags?).returns(false)
|
||||
xhr :post, :clear_flags, id: flagged_post.id, post_action_type_id: PostActionType.Types[:spam]
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
context "success" do
|
||||
before do
|
||||
Guardian.any_instance.expects(:can_clear_flags?).returns(true)
|
||||
Guardian.any_instance.expects(:can_clear_flags?).returns(true)
|
||||
PostAction.expects(:clear_flags!).with(flagged_post, user.id, PostActionType.Types[:spam])
|
||||
end
|
||||
|
||||
it "delegates to clear_flags" do
|
||||
it "delegates to clear_flags" do
|
||||
xhr :post, :clear_flags, id: flagged_post.id, post_action_type_id: PostActionType.Types[:spam]
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
it "works with a deleted post" do
|
||||
flagged_post.destroy
|
||||
|
@ -163,7 +163,7 @@ describe PostActionsController do
|
|||
xhr :get, :users, id: post.id, post_action_type_id: PostActionType.Types[:like]
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
|
||||
it 'succeeds' do
|
||||
xhr :get, :users, id: post.id, post_action_type_id: PostActionType.Types[:like]
|
||||
response.should be_success
|
||||
|
|
|
@ -24,18 +24,18 @@ describe PostsController do
|
|||
post.destroy
|
||||
end
|
||||
|
||||
it "can't find deleted posts as an anonymous user" do
|
||||
it "can't find deleted posts as an anonymous user" do
|
||||
xhr :get, :show, id: post.id
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it "can't find deleted posts as a regular user" do
|
||||
it "can't find deleted posts as a regular user" do
|
||||
log_in(:user)
|
||||
xhr :get, :show, id: post.id
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it "can find posts as a moderator" do
|
||||
it "can find posts as a moderator" do
|
||||
log_in(:moderator)
|
||||
xhr :get, :show, id: post.id
|
||||
response.should be_success
|
||||
|
@ -121,7 +121,7 @@ describe PostsController do
|
|||
describe 'destroy_many' do
|
||||
it 'raises an exception when not logged in' do
|
||||
lambda { xhr :delete, :destroy_many, post_ids: [123, 345] }.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when logged in' do
|
||||
|
||||
|
@ -168,7 +168,7 @@ describe PostsController do
|
|||
|
||||
let(:post) { Fabricate(:post, user: log_in) }
|
||||
let(:update_params) do
|
||||
{id: post.id,
|
||||
{id: post.id,
|
||||
post: {raw: 'edited body'},
|
||||
image_sizes: {'http://image.com/image.jpg' => {'width' => 123, 'height' => 456}}}
|
||||
end
|
||||
|
@ -180,7 +180,7 @@ describe PostsController do
|
|||
|
||||
it "raises an error when the post parameter is missing" do
|
||||
update_params.delete(:post)
|
||||
lambda {
|
||||
lambda {
|
||||
xhr :put, :update, update_params
|
||||
}.should raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
@ -217,7 +217,7 @@ describe PostsController do
|
|||
|
||||
it "raises an error if the user doesn't have permission to see the post" do
|
||||
Guardian.any_instance.expects(:can_see?).with(post).returns(false)
|
||||
xhr :put, :bookmark, post_id: post.id, bookmarked: 'true'
|
||||
xhr :put, :bookmark, post_id: post.id, bookmarked: 'true'
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
|
@ -278,7 +278,7 @@ describe PostsController do
|
|||
|
||||
it "passes title through" do
|
||||
PostCreator.expects(:new).with(user, has_entries(title: 'new topic title')).returns(post_creator)
|
||||
xhr :post, :create, post: {raw: 'hello'}, title: 'new topic title'
|
||||
xhr :post, :create, post: {raw: 'hello'}, title: 'new topic title'
|
||||
end
|
||||
|
||||
it "passes topic_id through" do
|
||||
|
@ -293,12 +293,12 @@ describe PostsController do
|
|||
|
||||
it "passes category through" do
|
||||
PostCreator.expects(:new).with(user, has_entries(category: 'cool')).returns(post_creator)
|
||||
xhr :post, :create, post: {raw: 'hello', category: 'cool'}
|
||||
xhr :post, :create, post: {raw: 'hello', category: 'cool'}
|
||||
end
|
||||
|
||||
it "passes target_usernames through" do
|
||||
PostCreator.expects(:new).with(user, has_entries(target_usernames: 'evil,trout')).returns(post_creator)
|
||||
xhr :post, :create, post: {raw: 'hello'}, target_usernames: 'evil,trout'
|
||||
xhr :post, :create, post: {raw: 'hello'}, target_usernames: 'evil,trout'
|
||||
end
|
||||
|
||||
it "passes reply_to_post_number through" do
|
||||
|
@ -309,12 +309,12 @@ describe PostsController do
|
|||
it "passes image_sizes through" do
|
||||
PostCreator.expects(:new).with(user, has_entries(image_sizes: 'test')).returns(post_creator)
|
||||
xhr :post, :create, post: {raw: 'hello'}, image_sizes: 'test'
|
||||
end
|
||||
end
|
||||
|
||||
it "passes meta_data through" do
|
||||
PostCreator.expects(:new).with(user, has_entries(meta_data: {'xyz' => 'abc'})).returns(post_creator)
|
||||
xhr :post, :create, post: {raw: 'hello'}, meta_data: {xyz: 'abc'}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ describe RequestAccessController do
|
|||
it "assigns the return path we provide" do
|
||||
get :new, return_path: '/asdf'
|
||||
assigns(:return_path).should == "/asdf"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -43,7 +43,7 @@ describe RequestAccessController do
|
|||
|
||||
it 'redirects to the return path' do
|
||||
response.should redirect_to('/the-path')
|
||||
end
|
||||
end
|
||||
|
||||
it 'sets no flash error' do
|
||||
flash[:error].should be_blank
|
||||
|
|
|
@ -10,13 +10,13 @@ describe RobotsTxtController do
|
|||
response.should render_template :index
|
||||
end
|
||||
|
||||
it "returns noindex when indexing is disallowed" do
|
||||
it "returns noindex when indexing is disallowed" do
|
||||
SiteSetting.stubs(:allow_index_in_robots_txt).returns(false)
|
||||
get :index
|
||||
response.should render_template :no_index
|
||||
end
|
||||
|
||||
it "serves noindex when in private mode regardless of the configuration" do
|
||||
end
|
||||
|
||||
it "serves noindex when in private mode regardless of the configuration" do
|
||||
SiteSetting.stubs(:allow_index_in_robots_txt).returns(true)
|
||||
SiteSetting.stubs(:restrict_access).returns(true)
|
||||
get :index
|
||||
|
|
|
@ -118,28 +118,28 @@ describe SessionController do
|
|||
end
|
||||
|
||||
context 'for a non existant username' do
|
||||
it "doesn't generate a new token for a made up username" do
|
||||
it "doesn't generate a new token for a made up username" do
|
||||
lambda { xhr :post, :forgot_password, username: 'made_up'}.should_not change(EmailToken, :count)
|
||||
end
|
||||
|
||||
it "doesn't enqueue an email" do
|
||||
it "doesn't enqueue an email" do
|
||||
Jobs.expects(:enqueue).with(:user_mail, anything).never
|
||||
xhr :post, :forgot_password, username: 'made_up'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'for an existing username' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it "generates a new token for a made up username" do
|
||||
it "generates a new token for a made up username" do
|
||||
lambda { xhr :post, :forgot_password, username: user.username}.should change(EmailToken, :count)
|
||||
end
|
||||
|
||||
it "enqueues an email" do
|
||||
it "enqueues an email" do
|
||||
Jobs.expects(:enqueue).with(:user_email, has_entries(type: :forgot_password, user_id: user.id))
|
||||
xhr :post, :forgot_password, username: user.username
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ describe StaticController do
|
|||
xhr :get, :show, :id => 'faq'
|
||||
end
|
||||
|
||||
it 'renders the static file if present' do
|
||||
it 'renders the static file if present' do
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ describe TopicsController do
|
|||
|
||||
it "has a url" do
|
||||
::JSON.parse(response.body)['url'].should be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'failure' do
|
||||
|
@ -67,7 +67,7 @@ describe TopicsController do
|
|||
::JSON.parse(response.body)['url'].should be_blank
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -96,7 +96,7 @@ describe TopicsController do
|
|||
end
|
||||
|
||||
it 'requires the enabled parameter' do
|
||||
lambda { xhr :put, :status, topic_id: @topic.id, status: 'visible' }.should raise_error(Discourse::InvalidParameters)
|
||||
lambda { xhr :put, :status, topic_id: @topic.id, status: 'visible' }.should raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it 'raises an error with a status not in the whitelist' do
|
||||
|
@ -132,7 +132,7 @@ describe TopicsController do
|
|||
|
||||
it 'deletes the forum topic user record' do
|
||||
PostTiming.expects(:destroy_for).with(@user.id, @topic.id)
|
||||
xhr :delete, :destroy_timings, topic_id: @topic.id
|
||||
xhr :delete, :destroy_timings, topic_id: @topic.id
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -140,7 +140,7 @@ describe TopicsController do
|
|||
end
|
||||
|
||||
|
||||
describe 'mute/unmute' do
|
||||
describe 'mute/unmute' do
|
||||
|
||||
it 'needs you to be logged in' do
|
||||
lambda { xhr :put, :mute, topic_id: 99}.should raise_error(Discourse::NotLoggedIn)
|
||||
|
@ -150,7 +150,7 @@ describe TopicsController do
|
|||
lambda { xhr :put, :unmute, topic_id: 99}.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
|
||||
describe 'when logged in' do
|
||||
describe 'when logged in' do
|
||||
before do
|
||||
@topic = Fabricate(:topic, user: log_in)
|
||||
end
|
||||
|
@ -158,12 +158,12 @@ describe TopicsController do
|
|||
it "changes the user's starred flag when the parameter is present" do
|
||||
Topic.any_instance.expects(:toggle_mute).with(@topic.user, true)
|
||||
xhr :put, :mute, topic_id: @topic.id, starred: 'true'
|
||||
end
|
||||
end
|
||||
|
||||
it "removes the user's starred flag when the parameter is not true" do
|
||||
Topic.any_instance.expects(:toggle_mute).with(@topic.user, false)
|
||||
xhr :put, :unmute, topic_id: @topic.id, starred: 'false'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -182,20 +182,20 @@ describe TopicsController do
|
|||
|
||||
it "ensures the user can see the topic" do
|
||||
Guardian.any_instance.expects(:can_see?).with(@topic).returns(false)
|
||||
xhr :put, :star, topic_id: @topic.id, starred: 'true'
|
||||
xhr :put, :star, topic_id: @topic.id, starred: 'true'
|
||||
response.should be_forbidden
|
||||
end
|
||||
|
||||
it "changes the user's starred flag when the parameter is present" do
|
||||
Topic.any_instance.expects(:toggle_star).with(@topic.user, true)
|
||||
xhr :put, :star, topic_id: @topic.id, starred: 'true'
|
||||
end
|
||||
end
|
||||
|
||||
it "removes the user's starred flag when the parameter is not true" do
|
||||
Topic.any_instance.expects(:toggle_star).with(@topic.user, false)
|
||||
xhr :put, :star, topic_id: @topic.id, starred: 'false'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'delete' do
|
||||
|
@ -213,7 +213,7 @@ describe TopicsController do
|
|||
Guardian.any_instance.expects(:can_delete?).with(@topic).returns(false)
|
||||
xhr :delete, :destroy, id: @topic.id
|
||||
response.should be_forbidden
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with permission' do
|
||||
|
@ -236,7 +236,7 @@ describe TopicsController do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'show' do
|
||||
describe 'show' do
|
||||
|
||||
let(:topic) { Fabricate(:post).topic }
|
||||
let!(:p1) { Fabricate(:post, user: topic.user) }
|
||||
|
@ -251,7 +251,7 @@ describe TopicsController do
|
|||
lambda { xhr :get, :show, id: topic.id }.should change(View, :count).by(1)
|
||||
end
|
||||
|
||||
it 'tracks a visit for all html requests' do
|
||||
it 'tracks a visit for all html requests' do
|
||||
current_user = log_in(:coding_horror)
|
||||
TopicUser.expects(:track_visit!).with(topic, current_user)
|
||||
get :show, id: topic.id
|
||||
|
@ -293,7 +293,7 @@ describe TopicsController do
|
|||
it 'delegates a posts_before param to TopicView#filter_posts_before' do
|
||||
TopicView.any_instance.expects(:filter_posts_before).with(p2.post_number)
|
||||
xhr :get, :show, id: topic.id, posts_before: p2.post_number
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -314,7 +314,7 @@ describe TopicsController do
|
|||
Guardian.any_instance.expects(:can_edit?).with(@topic).returns(false)
|
||||
xhr :put, :update, topic_id: @topic.id, slug: @topic.title
|
||||
response.should be_forbidden
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with permission' do
|
||||
|
@ -345,7 +345,7 @@ describe TopicsController do
|
|||
describe 'invite' do
|
||||
it "won't allow us to invite toa topic when we're not logged in" do
|
||||
lambda { xhr :post, :invite, topic_id: 1, email: 'jake@adventuretime.ooo' }.should raise_error(Discourse::NotLoggedIn)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when logged in' do
|
||||
before do
|
||||
|
@ -361,7 +361,7 @@ describe TopicsController do
|
|||
Guardian.any_instance.expects(:can_invite_to?).with(@topic).returns(false)
|
||||
xhr :post, :invite, topic_id: @topic.id, user: 'jake@adventuretime.ooo'
|
||||
response.should be_forbidden
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with permission' do
|
||||
|
@ -382,7 +382,7 @@ describe TopicsController do
|
|||
|
||||
it 'returns success JSON' do
|
||||
::JSON.parse(response.body).should == {'success' => 'OK'}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it fails and returns nil' do
|
||||
|
@ -398,7 +398,7 @@ describe TopicsController do
|
|||
|
||||
it 'returns success JSON' do
|
||||
::JSON.parse(response.body).should == {'failed' => 'FAILED'}
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
Fabricator(:post) do
|
||||
user
|
||||
topic {|attrs| Fabricate(:topic, user: attrs[:user] ) }
|
||||
raw "Hello world"
|
||||
raw "Hello world"
|
||||
end
|
||||
|
||||
Fabricator(:post_with_youtube, from: :post) do
|
||||
|
@ -17,7 +17,7 @@ Fabricator(:moderator_post, from: :post) do
|
|||
user
|
||||
topic {|attrs| Fabricate(:topic, user: attrs[:user] ) }
|
||||
post_type Post::MODERATOR_ACTION
|
||||
raw "Hello world"
|
||||
raw "Hello world"
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -4,18 +4,18 @@ Fabricator(:topic) do
|
|||
end
|
||||
|
||||
Fabricator(:deleted_topic, from: :topic) do
|
||||
deleted_at Time.now
|
||||
deleted_at Time.now
|
||||
end
|
||||
|
||||
Fabricator(:topic_allowed_user) do
|
||||
Fabricator(:topic_allowed_user) do
|
||||
end
|
||||
|
||||
Fabricator(:private_message_topic, from: :topic) do
|
||||
Fabricator(:private_message_topic, from: :topic) do
|
||||
user
|
||||
title { sequence(:title) { |i| "Private Message #{i}" } }
|
||||
archetype "private_message"
|
||||
topic_allowed_users{|t| [
|
||||
Fabricate.build(:topic_allowed_user, user_id: t[:user].id),
|
||||
topic_allowed_users{|t| [
|
||||
Fabricate.build(:topic_allowed_user, user_id: t[:user].id),
|
||||
Fabricate.build(:topic_allowed_user, user_id: Fabricate(:coding_horror).id)
|
||||
]}
|
||||
end
|
||||
|
|
|
@ -9,21 +9,21 @@ end
|
|||
|
||||
Fabricator(:coding_horror, from: :user) do
|
||||
name 'Coding Horror'
|
||||
username 'CodingHorror'
|
||||
username 'CodingHorror'
|
||||
email 'jeff@somewhere.com'
|
||||
password 'mymoreawesomepassword'
|
||||
end
|
||||
|
||||
Fabricator(:evil_trout, from: :user) do
|
||||
name 'Evil Trout'
|
||||
username 'eviltrout'
|
||||
username 'eviltrout'
|
||||
email 'eviltrout@somewhere.com'
|
||||
password 'imafish'
|
||||
end
|
||||
|
||||
Fabricator(:walter_white, from: :user) do
|
||||
name 'Walter White'
|
||||
username 'heisenberg'
|
||||
username 'heisenberg'
|
||||
email 'wwhite@bluemeth.com'
|
||||
password 'letscook'
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ describe "i18n integrity checks" do
|
|||
|
||||
it "needs an i18n key (notification_types) for each Notification type" do
|
||||
Notification.Types.keys.each do |type|
|
||||
I18n.t("notification_types.#{type}").should_not =~ /translation missing/
|
||||
I18n.t("notification_types.#{type}").should_not =~ /translation missing/
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ describe("sanitize", function(){
|
|||
|
||||
|
||||
it("strips all script tags", function(){
|
||||
var sanitized = sanitizeHtml("<div><script>alert('hi');</script></div>");
|
||||
var sanitized = sanitizeHtml("<div><script>alert('hi');</script></div>");
|
||||
|
||||
expect(sanitized)
|
||||
.toBe("<div></div>");
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
return "" + name;
|
||||
}
|
||||
});
|
||||
return expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n" +
|
||||
return expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n" +
|
||||
" bob\n bob\n said:\n </div>\n <blockquote>my quote</blockquote>\n</aside>\n<p>2</p>");
|
||||
});
|
||||
it("includes no avatar if none is found", function() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe InviteMailer do
|
||||
|
||||
|
||||
describe "send_invite" do
|
||||
let(:invite) { Fabricate(:invite) }
|
||||
subject { InviteMailer.send_invite(invite) }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe TestMailer do
|
||||
|
||||
|
||||
describe "send_test" do
|
||||
subject { TestMailer.send_test('marcheline@adventuretime.ooo') }
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe UserNotifications do
|
||||
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
describe ".signup" do
|
||||
|
@ -19,7 +19,7 @@ describe UserNotifications do
|
|||
its(:to) { should == [user.email] }
|
||||
its(:subject) { should be_present }
|
||||
its(:from) { should == [SiteSetting.notification_email] }
|
||||
its(:body) { should be_present }
|
||||
its(:body) { should be_present }
|
||||
end
|
||||
|
||||
describe '.daily_digest' do
|
||||
|
@ -37,7 +37,7 @@ describe UserNotifications do
|
|||
its(:to) { should == [user.email] }
|
||||
its(:subject) { should be_present }
|
||||
its(:from) { should == [SiteSetting.notification_email] }
|
||||
its(:body) { should be_present }
|
||||
its(:body) { should be_present }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -53,7 +53,7 @@ describe UserNotifications do
|
|||
its(:to) { should == [user.email] }
|
||||
its(:subject) { should be_present }
|
||||
its(:from) { should == [SiteSetting.notification_email] }
|
||||
its(:body) { should be_present }
|
||||
its(:body) { should be_present }
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,6 @@ describe CategoryFeaturedTopic do
|
|||
|
||||
it { should belong_to :category }
|
||||
it { should belong_to :topic }
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe CategoryFeaturedUser do
|
||||
|
||||
|
||||
it { should belong_to :category }
|
||||
it { should belong_to :user }
|
||||
|
||||
|
|
|
@ -24,9 +24,9 @@ describe Category do
|
|||
let(:category) { Fabricate.build(:category, name: SiteSetting.uncategorized_name) }
|
||||
|
||||
it "is invalid to create a category with the reserved name" do
|
||||
category.should_not be_valid
|
||||
category.should_not be_valid
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe "short name" do
|
||||
|
@ -92,7 +92,7 @@ describe Category do
|
|||
end
|
||||
|
||||
it 'creates a topic post' do
|
||||
@topic.should be_present
|
||||
@topic.should be_present
|
||||
end
|
||||
|
||||
it 'points back to itself' do
|
||||
|
@ -160,15 +160,15 @@ describe Category do
|
|||
end
|
||||
|
||||
describe 'update_stats' do
|
||||
|
||||
|
||||
before do
|
||||
@category = Fabricate(:category)
|
||||
end
|
||||
|
||||
|
||||
context 'with regular topics' do
|
||||
|
||||
before do
|
||||
@category.topics << Fabricate(:topic, user: @category.user)
|
||||
@category.topics << Fabricate(:topic, user: @category.user)
|
||||
Category.update_stats
|
||||
@category.reload
|
||||
end
|
||||
|
@ -184,13 +184,13 @@ describe Category do
|
|||
it 'updates topics_year' do
|
||||
@category.topics_year.should == 1
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
context 'with deleted topics' do
|
||||
|
||||
before do
|
||||
@category.topics << Fabricate(:deleted_topic,
|
||||
@category.topics << Fabricate(:deleted_topic,
|
||||
user: @category.user)
|
||||
Category.update_stats
|
||||
@category.reload
|
||||
|
|
|
@ -7,7 +7,7 @@ describe DraftSequence do
|
|||
DraftSequence.next!(u, 'test').should == 2
|
||||
end
|
||||
|
||||
it 'should return 0 by default' do
|
||||
it 'should return 0 by default' do
|
||||
u = Fabricate(:user)
|
||||
DraftSequence.current(u, 'test').should == 0
|
||||
end
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Draft do
|
||||
before do
|
||||
before do
|
||||
@user = Fabricate(:user)
|
||||
end
|
||||
it "can get a draft by user" do
|
||||
it "can get a draft by user" do
|
||||
Draft.set(@user, "test", 0, "data")
|
||||
Draft.get(@user, "test", 0).should == "data"
|
||||
end
|
||||
|
@ -14,19 +14,19 @@ describe Draft do
|
|||
Draft.get(Fabricate(:coding_horror), "test", 0).should be_nil
|
||||
end
|
||||
|
||||
it "should overwrite draft data correctly" do
|
||||
it "should overwrite draft data correctly" do
|
||||
Draft.set(@user, "test", 0, "data")
|
||||
Draft.set(@user, "test", 0, "new data")
|
||||
Draft.get(@user, "test", 0).should == "new data"
|
||||
end
|
||||
|
||||
it "should clear drafts on request" do
|
||||
it "should clear drafts on request" do
|
||||
Draft.set(@user, "test", 0, "data")
|
||||
Draft.clear(@user, "test", 0)
|
||||
Draft.get(@user, "test", 0).should be_nil
|
||||
end
|
||||
|
||||
it "should disregard old draft if sequence decreases" do
|
||||
it "should disregard old draft if sequence decreases" do
|
||||
Draft.set(@user, "test", 0, "data")
|
||||
Draft.set(@user, "test", 1, "hello")
|
||||
Draft.set(@user, "test", 0, "foo")
|
||||
|
@ -35,26 +35,26 @@ describe Draft do
|
|||
end
|
||||
|
||||
|
||||
context 'key expiry' do
|
||||
it 'nukes new topic draft after a topic is created' do
|
||||
context 'key expiry' do
|
||||
it 'nukes new topic draft after a topic is created' do
|
||||
u = Fabricate(:user)
|
||||
Draft.set(u, Draft::NEW_TOPIC, 0, 'my draft')
|
||||
Draft.set(u, Draft::NEW_TOPIC, 0, 'my draft')
|
||||
t = Fabricate(:topic, user: u)
|
||||
s = DraftSequence.current(u, Draft::NEW_TOPIC)
|
||||
Draft.get(u, Draft::NEW_TOPIC, s).should be_nil
|
||||
end
|
||||
|
||||
it 'nukes new pm draft after a pm is created' do
|
||||
it 'nukes new pm draft after a pm is created' do
|
||||
u = Fabricate(:user)
|
||||
Draft.set(u, Draft::NEW_PRIVATE_MESSAGE, 0, 'my draft')
|
||||
Draft.set(u, Draft::NEW_PRIVATE_MESSAGE, 0, 'my draft')
|
||||
t = Fabricate(:topic, user: u, archetype: Archetype.private_message)
|
||||
s = DraftSequence.current(t.user, Draft::NEW_PRIVATE_MESSAGE)
|
||||
Draft.get(u, Draft::NEW_PRIVATE_MESSAGE, s).should be_nil
|
||||
end
|
||||
|
||||
it 'does not nuke new topic draft after a pm is created' do
|
||||
it 'does not nuke new topic draft after a pm is created' do
|
||||
u = Fabricate(:user)
|
||||
Draft.set(u, Draft::NEW_TOPIC, 0, 'my draft')
|
||||
Draft.set(u, Draft::NEW_TOPIC, 0, 'my draft')
|
||||
t = Fabricate(:topic, user: u, archetype: Archetype.private_message)
|
||||
s = DraftSequence.current(t.user, Draft::NEW_TOPIC)
|
||||
Draft.get(u, Draft::NEW_TOPIC, s).should == 'my draft'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe EmailLog do
|
||||
|
||||
|
||||
it { should belong_to :user }
|
||||
|
||||
it { should validate_presence_of :to_address }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe EmailToken do
|
||||
|
||||
|
||||
it { should validate_presence_of :user_id }
|
||||
it { should validate_presence_of :email }
|
||||
it { should belong_to :user }
|
||||
|
@ -60,13 +60,13 @@ describe EmailToken do
|
|||
it 'returns nil when a token is expired' do
|
||||
email_token.update_column(:expired, true)
|
||||
EmailToken.confirm(email_token.token).should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns nil when a token is older than a specific time' do
|
||||
EmailToken.expects(:valid_after).returns(1.week.ago)
|
||||
email_token.update_column(:created_at, 2.weeks.ago)
|
||||
EmailToken.confirm(email_token.token).should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context 'taken email address' do
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ describe ErrorLog do
|
|||
raise "boom"
|
||||
end
|
||||
|
||||
def exception
|
||||
begin
|
||||
def exception
|
||||
begin
|
||||
boom
|
||||
rescue => e
|
||||
return e
|
||||
|
@ -29,30 +29,30 @@ describe ErrorLog do
|
|||
end
|
||||
end
|
||||
|
||||
describe "logging data" do
|
||||
describe "logging data" do
|
||||
it "is able to read the data it writes" do
|
||||
ErrorLog.clear_all!
|
||||
ErrorLog.report!(exception, controller, request, nil)
|
||||
ErrorLog.report!(exception, controller, request, nil)
|
||||
i = 0
|
||||
ErrorLog.each do |h|
|
||||
ErrorLog.each do |h|
|
||||
i += 1
|
||||
end
|
||||
end
|
||||
i.should == 2
|
||||
end
|
||||
|
||||
it "is able to skip rows" do
|
||||
it "is able to skip rows" do
|
||||
ErrorLog.clear_all!
|
||||
ErrorLog.report!(exception, controller, request, nil)
|
||||
ErrorLog.report!(exception, controller, request, nil)
|
||||
ErrorLog.report!(exception, controller, request, nil)
|
||||
ErrorLog.report!(exception, controller, request, nil)
|
||||
i = 0
|
||||
ErrorLog.skip(3) do |h|
|
||||
ErrorLog.skip(3) do |h|
|
||||
i += 1
|
||||
end
|
||||
i.should == 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ describe IncomingLink do
|
|||
before do
|
||||
@post = Fabricate(:post)
|
||||
@topic = @post.topic
|
||||
@incoming_link = IncomingLink.create(url: "/t/slug/#{@topic.id}/#{@post.post_number}",
|
||||
@incoming_link = IncomingLink.create(url: "/t/slug/#{@topic.id}/#{@post.post_number}",
|
||||
referer: "http://twitter.com")
|
||||
end
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ describe Invite do
|
|||
context 'to a topic' do
|
||||
let!(:topic) { Fabricate(:topic) }
|
||||
let(:inviter) { topic.user }
|
||||
|
||||
|
||||
context 'email' do
|
||||
it 'enqueues a job to email the invite' do
|
||||
Jobs.expects(:enqueue).with(:invite_email, has_key(:invite_id))
|
||||
|
@ -54,7 +54,7 @@ describe Invite do
|
|||
invite.destroy
|
||||
invite = topic.invite_by_email(inviter, 'iceking@adventuretime.ooo')
|
||||
invite.should be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'after created' do
|
||||
|
@ -85,7 +85,7 @@ describe Invite do
|
|||
|
||||
it 'has a different key' do
|
||||
new_invite.invite_key.should_not == @invite.invite_key
|
||||
end
|
||||
end
|
||||
|
||||
it 'has the topic relationship' do
|
||||
new_invite.topics.should == [topic]
|
||||
|
@ -120,7 +120,7 @@ describe Invite do
|
|||
it 'has references to both topics' do
|
||||
@invite.topics.should =~ [topic, another_topic]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -168,7 +168,7 @@ describe Invite do
|
|||
end
|
||||
|
||||
context 'simple invite' do
|
||||
|
||||
|
||||
let!(:user) { invite.redeem }
|
||||
|
||||
it 'returns a user record' do
|
||||
|
@ -207,7 +207,7 @@ describe Invite do
|
|||
context 'again' do
|
||||
it 'will not redeem twice' do
|
||||
invite.redeem.should == user
|
||||
end
|
||||
end
|
||||
|
||||
it "doesn't want us to send a welcome message" do
|
||||
invite.redeem.send_welcome_message.should be_false
|
||||
|
@ -276,11 +276,11 @@ describe Invite do
|
|||
it 'marks the second invite as redeemed' do
|
||||
another_invite.reload
|
||||
another_invite.should be_redeemed
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,14 +12,14 @@ describe Notification do
|
|||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
context 'a regular notification' do
|
||||
context 'a regular notification' do
|
||||
it 'increases unread_notifications' do
|
||||
lambda { Fabricate(:notification, user: user); user.reload }.should change(user, :unread_notifications)
|
||||
end
|
||||
|
||||
it "doesn't increase unread_private_messages" do
|
||||
lambda { Fabricate(:notification, user: user); user.reload }.should_not change(user, :unread_private_messages)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'a private message' do
|
||||
|
@ -29,7 +29,7 @@ describe Notification do
|
|||
|
||||
it "increases unread_private_messages" do
|
||||
lambda { Fabricate(:private_message_notification, user: user); user.reload }.should change(user, :unread_private_messages)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -46,8 +46,8 @@ describe Notification do
|
|||
let!(:notification) { Fabricate(:notification) }
|
||||
|
||||
it 'updates the notification count on destroy' do
|
||||
MessageBusObserver.any_instance.expects(:refresh_notification_count).with(instance_of(Notification))
|
||||
notification.destroy
|
||||
MessageBusObserver.any_instance.expects(:refresh_notification_count).with(instance_of(Notification))
|
||||
notification.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -58,7 +58,7 @@ describe Notification do
|
|||
it "calls email_user_mentioned on creating a notification" do
|
||||
UserEmailObserver.any_instance.expects(:email_user_mentioned).with(instance_of(Notification))
|
||||
Fabricate(:notification)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -66,11 +66,11 @@ describe Notification do
|
|||
it "calls email_user_quoted on creating a quote notification" do
|
||||
UserEmailObserver.any_instance.expects(:email_user_quoted).with(instance_of(Notification))
|
||||
Fabricate(:quote_notification)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'private message' do
|
||||
before do
|
||||
describe 'private message' do
|
||||
before do
|
||||
@topic = Fabricate(:private_message_topic)
|
||||
@post = Fabricate(:post, :topic => @topic, :user => @topic.user)
|
||||
@target = @post.topic.topic_allowed_users.reject{|a| a.user_id == @post.user_id}[0].user
|
||||
|
@ -80,7 +80,7 @@ describe Notification do
|
|||
@target.notifications.first.notification_type.should == Notification.Types[:private_message]
|
||||
end
|
||||
|
||||
it 'should not add a pm notification for the creator' do
|
||||
it 'should not add a pm notification for the creator' do
|
||||
@post.user.unread_notifications.should == 0
|
||||
end
|
||||
end
|
||||
|
@ -98,21 +98,21 @@ describe Notification do
|
|||
|
||||
describe 'data' do
|
||||
let(:notification) { Fabricate.build(:notification) }
|
||||
|
||||
|
||||
it 'should have a data hash' do
|
||||
notification.data_hash.should be_present
|
||||
end
|
||||
|
||||
|
||||
it 'should have the data within the json' do
|
||||
notification.data_hash[:poison].should == 'ivy'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'mark_posts_read' do
|
||||
it "marks multiple posts as read if needed" do
|
||||
describe 'mark_posts_read' do
|
||||
it "marks multiple posts as read if needed" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
notifications = (1..3).map do |i|
|
||||
notifications = (1..3).map do |i|
|
||||
Notification.create!(read: false, user_id: user.id, topic_id: 2, post_number: i, data: '[]', notification_type: 1)
|
||||
end
|
||||
Notification.create!(read: true, user_id: user.id, topic_id: 2, post_number: 4, data: '[]', notification_type: 1)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe OneboxRender do
|
||||
|
||||
|
||||
it { should validate_presence_of :url }
|
||||
it { should validate_presence_of :cooked }
|
||||
it { should validate_presence_of :expires_at }
|
||||
it { should validate_presence_of :expires_at }
|
||||
it { should have_many :post_onebox_renders }
|
||||
it { should have_many :posts }
|
||||
|
||||
|
|
|
@ -11,11 +11,11 @@ describe PostAction do
|
|||
let(:post) { Fabricate(:post) }
|
||||
let(:bookmark) { PostAction.new(user_id: post.user_id, post_action_type_id: PostActionType.Types[:bookmark] , post_id: post.id) }
|
||||
|
||||
describe "flag counts" do
|
||||
describe "flag counts" do
|
||||
before do
|
||||
PostAction.update_flagged_posts_count
|
||||
end
|
||||
it "starts of with 0 flag counts" do
|
||||
end
|
||||
it "starts of with 0 flag counts" do
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
end
|
||||
|
||||
|
@ -27,13 +27,13 @@ describe PostAction do
|
|||
PostAction.flagged_posts_count.should == 0
|
||||
end
|
||||
|
||||
it "should reset counts when a topic is deleted" do
|
||||
it "should reset counts when a topic is deleted" do
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:off_topic])
|
||||
post.topic.destroy
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
end
|
||||
|
||||
it "should reset counts when a post is deleted" do
|
||||
|
||||
it "should reset counts when a post is deleted" do
|
||||
post2 = Fabricate(:post, topic_id: post.topic_id)
|
||||
PostAction.act(codinghorror, post2, PostActionType.Types[:off_topic])
|
||||
post2.destroy
|
||||
|
@ -50,16 +50,16 @@ describe PostAction do
|
|||
lambda { bookmark.save; post.topic.reload }.should change(post.topic, :bookmark_count).by(1)
|
||||
end
|
||||
|
||||
|
||||
describe 'when a user likes something' do
|
||||
it 'should increase the post counts when a user likes' do
|
||||
|
||||
describe 'when a user likes something' do
|
||||
it 'should increase the post counts when a user likes' do
|
||||
lambda {
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:like])
|
||||
post.reload
|
||||
}.should change(post, :like_count).by(1)
|
||||
end
|
||||
|
||||
it 'should increase the forum topic like count when a user likes' do
|
||||
|
||||
it 'should increase the forum topic like count when a user likes' do
|
||||
lambda {
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:like])
|
||||
post.topic.reload
|
||||
|
@ -69,15 +69,15 @@ describe PostAction do
|
|||
end
|
||||
|
||||
|
||||
describe 'when a user votes for something' do
|
||||
it 'should increase the vote counts when a user likes' do
|
||||
describe 'when a user votes for something' do
|
||||
it 'should increase the vote counts when a user likes' do
|
||||
lambda {
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:vote])
|
||||
post.reload
|
||||
}.should change(post, :vote_count).by(1)
|
||||
end
|
||||
|
||||
it 'should increase the forum topic vote count when a user votes' do
|
||||
|
||||
it 'should increase the forum topic vote count when a user votes' do
|
||||
lambda {
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:vote])
|
||||
post.topic.reload
|
||||
|
@ -97,13 +97,13 @@ describe PostAction do
|
|||
end
|
||||
|
||||
it 'reduces the bookmark count of the post' do
|
||||
lambda {
|
||||
lambda {
|
||||
post.reload
|
||||
}.should change(post, :bookmark_count).by(-1)
|
||||
end
|
||||
|
||||
it 'reduces the bookmark count of the forum topic' do
|
||||
lambda {
|
||||
lambda {
|
||||
@topic.reload
|
||||
}.should change(post.topic, :bookmark_count).by(-1)
|
||||
end
|
||||
|
@ -118,7 +118,7 @@ describe PostAction do
|
|||
lambda { PostAction.act(u1, post, PostActionType.Types[:off_topic]) }.should raise_error(PostAction::AlreadyFlagged)
|
||||
end
|
||||
|
||||
it 'should update counts when you clear flags' do
|
||||
it 'should update counts when you clear flags' do
|
||||
post = Fabricate(:post)
|
||||
u1 = Fabricate(:evil_trout)
|
||||
PostAction.act(u1, post, PostActionType.Types[:spam])
|
||||
|
@ -132,7 +132,7 @@ describe PostAction do
|
|||
post.spam_count.should == 0
|
||||
end
|
||||
|
||||
it 'should follow the rules for automatic hiding workflow' do
|
||||
it 'should follow the rules for automatic hiding workflow' do
|
||||
|
||||
post = Fabricate(:post)
|
||||
u1 = Fabricate(:evil_trout)
|
||||
|
@ -141,7 +141,7 @@ describe PostAction do
|
|||
# we need an admin for the messages
|
||||
admin = Fabricate(:admin)
|
||||
|
||||
SiteSetting.flags_required_to_hide_post = 2
|
||||
SiteSetting.flags_required_to_hide_post = 2
|
||||
|
||||
PostAction.act(u1, post, PostActionType.Types[:spam])
|
||||
PostAction.act(u2, post, PostActionType.Types[:spam])
|
||||
|
@ -149,7 +149,7 @@ describe PostAction do
|
|||
post.reload
|
||||
|
||||
post.hidden.should.should be_true
|
||||
post.hidden_reason_id.should == Post::HiddenReason::FLAG_THRESHOLD_REACHED
|
||||
post.hidden_reason_id.should == Post::HiddenReason::FLAG_THRESHOLD_REACHED
|
||||
post.topic.visible.should be_false
|
||||
|
||||
post.revise(post.user, post.raw + " ha I edited it ")
|
||||
|
@ -165,14 +165,14 @@ describe PostAction do
|
|||
post.reload
|
||||
|
||||
post.hidden.should be_true
|
||||
post.hidden_reason_id.should == Post::HiddenReason::FLAG_THRESHOLD_REACHED_AGAIN
|
||||
post.hidden_reason_id.should == Post::HiddenReason::FLAG_THRESHOLD_REACHED_AGAIN
|
||||
|
||||
post.revise(post.user, post.raw + " ha I edited it again ")
|
||||
|
||||
|
||||
post.reload
|
||||
|
||||
post.hidden.should be_true
|
||||
post.hidden_reason_id.should == Post::HiddenReason::FLAG_THRESHOLD_REACHED_AGAIN
|
||||
post.hidden_reason_id.should == Post::HiddenReason::FLAG_THRESHOLD_REACHED_AGAIN
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,15 +19,15 @@ describe PostAlertObserver do
|
|||
PostAction.act(evil_trout, post, PostActionType.Types[:like])
|
||||
end
|
||||
|
||||
it 'removes a notification' do
|
||||
it 'removes a notification' do
|
||||
lambda {
|
||||
PostAction.remove_act(evil_trout, post, PostActionType.Types[:like])
|
||||
}.should change(Notification, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when editing a post' do
|
||||
context 'when editing a post' do
|
||||
it 'notifies a user of the revision' do
|
||||
lambda {
|
||||
post.revise(evil_trout, "world is the new body of the message")
|
||||
|
@ -41,21 +41,21 @@ describe PostAlertObserver do
|
|||
lambda {
|
||||
Fabricate(:post, raw: '[quote="EvilTrout, post:1"]whatup[/quote]')
|
||||
}.should change(evil_trout.notifications, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
it "won't notify the user a second time on revision" do
|
||||
p1 = Fabricate(:post, raw: '[quote="Evil Trout, post:1"]whatup[/quote]')
|
||||
lambda {
|
||||
lambda {
|
||||
p1.revise(p1.user, '[quote="Evil Trout, post:1"]whatup now?[/quote]')
|
||||
}.should_not change(evil_trout.notifications, :count)
|
||||
end
|
||||
end
|
||||
|
||||
it "doesn't notify the poster" do
|
||||
topic = post.topic
|
||||
lambda {
|
||||
new_post = Fabricate(:post, topic: topic, user: topic.user, raw: '[quote="Bruce Wayne, post:1"]whatup[/quote]')
|
||||
}.should_not change(topic.user.notifications, :count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context '@mentions' do
|
||||
|
@ -72,7 +72,7 @@ describe PostAlertObserver do
|
|||
|
||||
it "won't notify the user a second time on revision" do
|
||||
mention_post
|
||||
lambda {
|
||||
lambda {
|
||||
mention_post.revise(mention_post.user, "New raw content that still mentions @eviltrout")
|
||||
}.should_not change(evil_trout.notifications, :count)
|
||||
end
|
||||
|
@ -82,14 +82,14 @@ describe PostAlertObserver do
|
|||
it "doesn't notify the user who created the topic in regular mode" do
|
||||
topic.notify_regular!(user)
|
||||
mention_post
|
||||
lambda {
|
||||
lambda {
|
||||
Fabricate(:post, user: user, raw: 'second post', topic: topic)
|
||||
}.should_not change(user.notifications, :count).by(1)
|
||||
end
|
||||
|
||||
it 'removes notifications' do
|
||||
post = mention_post
|
||||
lambda {
|
||||
lambda {
|
||||
post.destroy
|
||||
}.should change(evil_trout.notifications, :count).by(-1)
|
||||
end
|
||||
|
@ -99,8 +99,8 @@ describe PostAlertObserver do
|
|||
context 'private message' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:mention_post) { Fabricate(:post, user: user, raw: 'Hello @eviltrout')}
|
||||
let(:topic) { mention_post.topic }
|
||||
let(:post)
|
||||
let(:topic) { mention_post.topic }
|
||||
let(:post)
|
||||
|
||||
it "won't notify someone who can't see the post" do
|
||||
lambda {
|
||||
|
|
|
@ -18,7 +18,7 @@ describe Post do
|
|||
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:post_args) do
|
||||
{user: topic.user, topic: topic}
|
||||
{user: topic.user, topic: topic}
|
||||
end
|
||||
|
||||
it_behaves_like "a versioned model"
|
||||
|
@ -59,17 +59,17 @@ describe Post do
|
|||
|
||||
end
|
||||
|
||||
describe 'flagging helpers' do
|
||||
it 'isFlagged is accurate' do
|
||||
describe 'flagging helpers' do
|
||||
it 'isFlagged is accurate' do
|
||||
post = Fabricate(:post)
|
||||
user = Fabricate(:coding_horror)
|
||||
PostAction.act(user, post, PostActionType.Types[:off_topic])
|
||||
|
||||
post.reload
|
||||
post.reload
|
||||
post.is_flagged?.should == true
|
||||
|
||||
|
||||
PostAction.remove_act(user, post, PostActionType.Types[:off_topic])
|
||||
post.reload
|
||||
post.reload
|
||||
post.is_flagged?.should == false
|
||||
end
|
||||
end
|
||||
|
@ -106,7 +106,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "doesn't count whitelisted images" do
|
||||
Post.stubs(:white_listed_image_classes).returns(["classy"])
|
||||
Post.stubs(:white_listed_image_classes).returns(["classy"])
|
||||
post_with_two_classy_images.image_count.should == 0
|
||||
end
|
||||
|
||||
|
@ -209,12 +209,12 @@ describe Post do
|
|||
it "ignores code" do
|
||||
post = Fabricate.build(:post, post_args.merge(raw: "@Jake <code>@Finn</code>"))
|
||||
post.raw_mentions.should == ['jake']
|
||||
end
|
||||
end
|
||||
|
||||
it "ignores quotes" do
|
||||
post = Fabricate.build(:post, post_args.merge(raw: "[quote=\"Evil Trout\"]@Jake[/quote] @Finn"))
|
||||
post.raw_mentions.should == ['finn']
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -238,7 +238,7 @@ describe Post do
|
|||
|
||||
let(:raw) { "this is our test post body"}
|
||||
let(:post) { Fabricate.build(:post, raw: raw) }
|
||||
|
||||
|
||||
it "returns a value" do
|
||||
post.raw_hash.should be_present
|
||||
end
|
||||
|
@ -340,11 +340,11 @@ describe Post do
|
|||
end
|
||||
|
||||
it "doesn't create a new version if you do another" do
|
||||
post.cached_version.should == 2
|
||||
post.cached_version.should == 2
|
||||
end
|
||||
|
||||
it "doesn't change last_version_at" do
|
||||
post.last_version_at.to_i.should == revised_at.to_i
|
||||
post.last_version_at.to_i.should == revised_at.to_i
|
||||
end
|
||||
|
||||
context "after second window" do
|
||||
|
@ -357,7 +357,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "does create a new version after the edit window" do
|
||||
post.cached_version.should == 3
|
||||
post.cached_version.should == 3
|
||||
end
|
||||
|
||||
it "does create a new version after the edit window" do
|
||||
|
@ -373,7 +373,7 @@ describe Post do
|
|||
|
||||
describe 'rate limiter' do
|
||||
let(:changed_by) { Fabricate(:coding_horror) }
|
||||
|
||||
|
||||
it "triggers a rate limiter" do
|
||||
EditRateLimiter.any_instance.expects(:performed!)
|
||||
post.revise(changed_by, 'updated body')
|
||||
|
@ -425,7 +425,7 @@ describe Post do
|
|||
|
||||
it 'is a ninja edit, because the second poster posted again quickly' do
|
||||
post.all_versions.size.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -446,7 +446,7 @@ describe Post do
|
|||
|
||||
it 'passes the invalidate_oneboxes along to the job if present' do
|
||||
Jobs.stubs(:enqueue).with(:feature_topic_users, has_key(:topic_id))
|
||||
Jobs.expects(:enqueue).with(:process_post, has_key(:invalidate_oneboxes))
|
||||
Jobs.expects(:enqueue).with(:process_post, has_key(:invalidate_oneboxes))
|
||||
post = Fabricate.build(:post, post_args)
|
||||
post.invalidate_oneboxes = true
|
||||
post.save
|
||||
|
@ -454,7 +454,7 @@ describe Post do
|
|||
|
||||
it 'passes the image_sizes along to the job if present' do
|
||||
Jobs.stubs(:enqueue).with(:feature_topic_users, has_key(:topic_id))
|
||||
Jobs.expects(:enqueue).with(:process_post, has_key(:image_sizes))
|
||||
Jobs.expects(:enqueue).with(:process_post, has_key(:image_sizes))
|
||||
post = Fabricate.build(:post, post_args)
|
||||
post.image_sizes = {'http://an.image.host/image.jpg' => {'width' => 17, 'height' => 31}}
|
||||
post.save
|
||||
|
@ -467,7 +467,7 @@ describe Post do
|
|||
describe 'replies' do
|
||||
|
||||
let(:post) { Fabricate(:post, post_args.merge(raw: "Hello @CodingHorror")) }
|
||||
|
||||
|
||||
it 'notifies the poster on reply' do
|
||||
lambda {
|
||||
@reply = Fabricate(:basic_reply, user: coding_horror, topic: post.topic)
|
||||
|
@ -492,7 +492,7 @@ describe Post do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'muting' do
|
||||
describe 'muting' do
|
||||
it "does not notify users of new posts" do
|
||||
post = Fabricate(:post, post_args)
|
||||
user = post_args[:user]
|
||||
|
@ -530,7 +530,7 @@ describe Post do
|
|||
|
||||
it "creates a new version" do
|
||||
post.version.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -538,7 +538,7 @@ describe Post do
|
|||
|
||||
before do
|
||||
post.delete_by(post.user)
|
||||
post.reload
|
||||
post.reload
|
||||
end
|
||||
|
||||
it "deletes the post" do
|
||||
|
@ -578,14 +578,14 @@ describe Post do
|
|||
}.should change(post.post_replies, :count).by(-1)
|
||||
end
|
||||
|
||||
it 'should increase the post_number when there are deletion gaps' do
|
||||
it 'should increase the post_number when there are deletion gaps' do
|
||||
reply.destroy
|
||||
p = Fabricate(:post, user: post.user, topic: post.topic)
|
||||
p.post_number.should == 3
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
@ -612,14 +612,14 @@ describe Post do
|
|||
|
||||
it 'has no versions' do
|
||||
post.versions.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
it 'has cooked content' do
|
||||
post.cooked.should be_present
|
||||
end
|
||||
|
||||
it 'has an external id' do
|
||||
post.external_id.should be_present
|
||||
post.external_id.should be_present
|
||||
end
|
||||
|
||||
it 'has no quotes' do
|
||||
|
|
|
@ -8,25 +8,25 @@ describe PostTiming do
|
|||
it { should validate_presence_of :post_number }
|
||||
it { should validate_presence_of :msecs }
|
||||
|
||||
describe 'process_timings' do
|
||||
|
||||
describe 'process_timings' do
|
||||
|
||||
# integration test
|
||||
|
||||
it 'processes timings correctly' do
|
||||
it 'processes timings correctly' do
|
||||
post = Fabricate(:post)
|
||||
user2 = Fabricate(:coding_horror)
|
||||
|
||||
PostAction.act(user2, post, PostActionType.Types[:like])
|
||||
post.user.unread_notifications.should == 1
|
||||
|
||||
|
||||
post.user.unread_notifications_by_type.should == {Notification.Types[:liked] => 1}
|
||||
|
||||
|
||||
PostTiming.process_timings(post.user, post.topic_id, 1, 100, [[post.post_number, 100]])
|
||||
|
||||
post.user.reload
|
||||
post.user.unread_notifications_by_type.should == {}
|
||||
post.user.unread_notifications.should == 0
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -65,14 +65,14 @@ describe PostTiming do
|
|||
it 'sums the msecs together' do
|
||||
@timing.msecs.should == 2468
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'avg times' do
|
||||
|
||||
describe 'posts' do
|
||||
it 'has no avg_time by default' do
|
||||
@post.avg_time.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
it "doesn't change when we calculate the avg time for the post because there's no timings" do
|
||||
Post.calculate_avg_time
|
||||
|
@ -84,7 +84,7 @@ describe PostTiming do
|
|||
describe 'topics' do
|
||||
it 'has no avg_time by default' do
|
||||
@topic.avg_time.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
it "doesn't change when we calculate the avg time for the post because there's no timings" do
|
||||
Topic.calculate_avg_time
|
||||
|
|
|
@ -6,37 +6,37 @@ describe SiteCustomization do
|
|||
Fabricate(:user)
|
||||
end
|
||||
|
||||
let :customization do
|
||||
let :customization do
|
||||
SiteCustomization.create!(name: 'my name', user_id: user.id, header: "my awesome header", stylesheet: "my awesome css")
|
||||
end
|
||||
|
||||
it 'should set default key when creating a new customization' do
|
||||
it 'should set default key when creating a new customization' do
|
||||
s = SiteCustomization.create!(name: 'my name', user_id: user.id)
|
||||
s.key.should_not == nil
|
||||
end
|
||||
|
||||
context 'caching' do
|
||||
|
||||
context 'enabled style' do
|
||||
|
||||
context 'enabled style' do
|
||||
before do
|
||||
@customization = customization
|
||||
end
|
||||
|
||||
it 'finds no style when none enabled' do
|
||||
it 'finds no style when none enabled' do
|
||||
SiteCustomization.enabled_style_key.should be_nil
|
||||
end
|
||||
|
||||
|
||||
it 'finds the enabled style' do
|
||||
@customization.enabled = true
|
||||
it 'finds the enabled style' do
|
||||
@customization.enabled = true
|
||||
@customization.save
|
||||
SiteCustomization.enabled_style_key.should == @customization.key
|
||||
end
|
||||
|
||||
it 'finds no enabled style on other sites' do
|
||||
@customization.enabled = true
|
||||
it 'finds no enabled style on other sites' do
|
||||
@customization.enabled = true
|
||||
@customization.save
|
||||
|
||||
|
||||
RailsMultisite::ConnectionManagement.expects(:current_db).returns("foo").twice
|
||||
# the mocking is tricky, lets remove the record so we can properly pretend we are on another db
|
||||
# this bypasses the before / after stuff
|
||||
|
@ -46,7 +46,7 @@ describe SiteCustomization do
|
|||
end
|
||||
end
|
||||
|
||||
it 'ensure stylesheet is on disk on first fetch' do
|
||||
it 'ensure stylesheet is on disk on first fetch' do
|
||||
c = customization
|
||||
c.remove_from_cache!
|
||||
File.delete(c.stylesheet_fullpath)
|
||||
|
@ -57,14 +57,14 @@ describe SiteCustomization do
|
|||
end
|
||||
|
||||
it 'should allow me to lookup a filename containing my preview stylesheet' do
|
||||
SiteCustomization.custom_stylesheet(customization.key).should ==
|
||||
"<link class=\"custom-css\" rel=\"stylesheet\" href=\"/uploads/stylesheet-cache/#{customization.key}.css?#{customization.stylesheet_hash}\" type=\"text/css\" media=\"screen\">"
|
||||
SiteCustomization.custom_stylesheet(customization.key).should ==
|
||||
"<link class=\"custom-css\" rel=\"stylesheet\" href=\"/uploads/stylesheet-cache/#{customization.key}.css?#{customization.stylesheet_hash}\" type=\"text/css\" media=\"screen\">"
|
||||
end
|
||||
|
||||
it 'should fix stylesheet files after changing the stylesheet' do
|
||||
old_file = customization.stylesheet_fullpath
|
||||
it 'should fix stylesheet files after changing the stylesheet' do
|
||||
old_file = customization.stylesheet_fullpath
|
||||
original = SiteCustomization.custom_stylesheet(customization.key)
|
||||
|
||||
|
||||
File.exists?(old_file).should == true
|
||||
customization.stylesheet = "div { clear:both; }"
|
||||
customization.save
|
||||
|
@ -73,27 +73,27 @@ describe SiteCustomization do
|
|||
end
|
||||
|
||||
it 'should delete old stylesheet files after deleting' do
|
||||
old_file = customization.stylesheet_fullpath
|
||||
old_file = customization.stylesheet_fullpath
|
||||
customization.ensure_stylesheet_on_disk!
|
||||
customization.destroy
|
||||
File.exists?(old_file).should == false
|
||||
end
|
||||
|
||||
it 'should nuke old revs out of the cache' do
|
||||
it 'should nuke old revs out of the cache' do
|
||||
old_style = SiteCustomization.custom_stylesheet(customization.key)
|
||||
|
||||
|
||||
customization.stylesheet = "hello worldz"
|
||||
customization.save
|
||||
SiteCustomization.custom_stylesheet(customization.key).should_not == old_style
|
||||
end
|
||||
|
||||
|
||||
it 'should compile scss' do
|
||||
it 'should compile scss' do
|
||||
c = SiteCustomization.create!(user_id: user.id, name: "test", stylesheet: '$black: #000; #a { color: $black; }', header: '')
|
||||
c.stylesheet_baked.should == "#a {\n color: black; }\n"
|
||||
end
|
||||
|
||||
it 'should provide an awesome error on failure' do
|
||||
it 'should provide an awesome error on failure' do
|
||||
c = SiteCustomization.create!(user_id: user.id, name: "test", stylesheet: "$black: #000; #a { color: $black; }\n\n\nboom", header: '')
|
||||
|
||||
c.stylesheet_baked.should =~ /Syntax error/
|
||||
|
|
|
@ -2,8 +2,8 @@ require 'spec_helper'
|
|||
|
||||
describe SiteSetting do
|
||||
|
||||
describe "int setting" do
|
||||
before :all do
|
||||
describe "int setting" do
|
||||
before :all do
|
||||
SiteSetting.setting(:test_setting, 77)
|
||||
SiteSetting.refresh!
|
||||
end
|
||||
|
@ -12,65 +12,65 @@ describe SiteSetting do
|
|||
SiteSetting.all_settings.detect {|s| s[:setting] == :test_setting }.should be_present
|
||||
end
|
||||
|
||||
it "should have the correct desc" do
|
||||
it "should have the correct desc" do
|
||||
I18n.expects(:t).with("site_settings.test_setting").returns("test description")
|
||||
SiteSetting.description(:test_setting).should == "test description"
|
||||
end
|
||||
|
||||
it "should have the correct default" do
|
||||
|
||||
it "should have the correct default" do
|
||||
SiteSetting.test_setting.should == 77
|
||||
end
|
||||
|
||||
describe "when overidden" do
|
||||
before :all do
|
||||
describe "when overidden" do
|
||||
before :all do
|
||||
SiteSetting.test_setting = 100
|
||||
end
|
||||
|
||||
after :all do
|
||||
after :all do
|
||||
SiteSetting.remove_override!(:test_setting)
|
||||
end
|
||||
|
||||
it "should have the correct override" do
|
||||
|
||||
it "should have the correct override" do
|
||||
SiteSetting.test_setting.should == 100
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe "string setting" do
|
||||
before :all do
|
||||
describe "string setting" do
|
||||
before :all do
|
||||
SiteSetting.setting(:test_str, "str")
|
||||
SiteSetting.refresh!
|
||||
end
|
||||
|
||||
it "should have the correct default" do
|
||||
it "should have the correct default" do
|
||||
SiteSetting.test_str.should == "str"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "bool setting" do
|
||||
before :all do
|
||||
SiteSetting.setting(:test_hello?, false)
|
||||
describe "bool setting" do
|
||||
before :all do
|
||||
SiteSetting.setting(:test_hello?, false)
|
||||
SiteSetting.refresh!
|
||||
end
|
||||
|
||||
it "should have the correct default" do
|
||||
it "should have the correct default" do
|
||||
SiteSetting.test_hello?.should == false
|
||||
end
|
||||
|
||||
|
||||
it "should be overridable" do
|
||||
SiteSetting.test_hello = true
|
||||
SiteSetting.refresh!
|
||||
SiteSetting.test_hello?.should == true
|
||||
end
|
||||
|
||||
it "should coerce true strings to true" do
|
||||
it "should coerce true strings to true" do
|
||||
SiteSetting.test_hello = "true"
|
||||
SiteSetting.refresh!
|
||||
SiteSetting.test_hello?.should == true
|
||||
end
|
||||
|
||||
it "should coerce all other strings to false" do
|
||||
it "should coerce all other strings to false" do
|
||||
SiteSetting.test_hello = "f"
|
||||
SiteSetting.refresh!
|
||||
SiteSetting.test_hello?.should == false
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe TopicInvite do
|
||||
|
||||
|
||||
it { should belong_to :topic }
|
||||
it { should belong_to :invite }
|
||||
it { should validate_presence_of :topic_id }
|
||||
it { should validate_presence_of :invite_id }
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'discourse'
|
|||
require 'spec_helper'
|
||||
|
||||
describe TopicLinkClick do
|
||||
|
||||
|
||||
it { should belong_to :topic_link }
|
||||
it { should belong_to :user }
|
||||
|
||||
|
@ -18,11 +18,11 @@ describe TopicLinkClick do
|
|||
|
||||
context 'topic_links' do
|
||||
before do
|
||||
@topic = Fabricate(:topic)
|
||||
@topic = Fabricate(:topic)
|
||||
@post = Fabricate(:post_with_external_links, user: @topic.user, topic: @topic)
|
||||
TopicLink.extract_from(@post)
|
||||
TopicLink.extract_from(@post)
|
||||
@topic_link = @topic.topic_links.first
|
||||
end
|
||||
end
|
||||
|
||||
it 'has 0 clicks at first' do
|
||||
@topic_link.clicks.should == 0
|
||||
|
@ -49,7 +49,7 @@ describe TopicLinkClick do
|
|||
context 'counts for' do
|
||||
|
||||
before do
|
||||
@counts_for = TopicLinkClick.counts_for(@topic, [@post])
|
||||
@counts_for = TopicLinkClick.counts_for(@topic, [@post])
|
||||
end
|
||||
|
||||
it 'has a counts_for result' do
|
||||
|
|
|
@ -13,13 +13,13 @@ describe TopicLink do
|
|||
end
|
||||
|
||||
before do
|
||||
@topic = Fabricate(:topic, title: 'unique topic name')
|
||||
@topic = Fabricate(:topic, title: 'unique topic name')
|
||||
@user = @topic.user
|
||||
end
|
||||
|
||||
it "can't link to the same topic" do
|
||||
ftl = TopicLink.new(url: "/t/#{@topic.id}",
|
||||
topic_id: @topic.id,
|
||||
ftl = TopicLink.new(url: "/t/#{@topic.id}",
|
||||
topic_id: @topic.id,
|
||||
link_topic_id: @topic.id)
|
||||
ftl.valid?.should be_false
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ describe TopicLink do
|
|||
describe 'external links' do
|
||||
before do
|
||||
@post = Fabricate(:post_with_external_links, user: @user, topic: @topic)
|
||||
TopicLink.extract_from(@post)
|
||||
TopicLink.extract_from(@post)
|
||||
end
|
||||
|
||||
it 'has the forum topic links' do
|
||||
|
@ -69,7 +69,7 @@ describe TopicLink do
|
|||
|
||||
it "should be the canonical URL" do
|
||||
@link.url.should == @url
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -167,7 +167,7 @@ describe TopicLink do
|
|||
@reflection = @other_topic.topic_links.should be_blank
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -177,7 +177,7 @@ describe TopicLink do
|
|||
TopicLink.extract_from(post)
|
||||
end
|
||||
|
||||
it 'does not extract a link' do
|
||||
it 'does not extract a link' do
|
||||
@topic.topic_links.should be_blank
|
||||
end
|
||||
end
|
||||
|
@ -188,7 +188,7 @@ describe TopicLink do
|
|||
TopicLink.extract_from(post)
|
||||
end
|
||||
|
||||
it 'does not extract a link' do
|
||||
it 'does not extract a link' do
|
||||
@topic.topic_links.should be_present
|
||||
end
|
||||
end
|
||||
|
@ -200,20 +200,20 @@ describe TopicLink do
|
|||
TopicLink.extract_from(post)
|
||||
end
|
||||
|
||||
it 'does not extract a link' do
|
||||
it 'does not extract a link' do
|
||||
@topic.topic_links.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'internal link from pm' do
|
||||
before do
|
||||
describe 'internal link from pm' do
|
||||
before do
|
||||
@pm = Fabricate(:topic, user: @user, archetype: 'private_message')
|
||||
@other_post = @pm.posts.create(user: @user, raw: "some content")
|
||||
|
||||
|
||||
@url = "http://#{test_uri.host}/t/topic-slug/#{@topic.id}"
|
||||
|
||||
|
||||
@pm.posts.create(user: @user, raw: 'initial post')
|
||||
@linked_post = @pm.posts.create(user: @user, raw: "Link to another topic: #{@url}")
|
||||
|
||||
|
@ -225,7 +225,7 @@ describe TopicLink do
|
|||
it 'should not create a reflection' do
|
||||
@topic.topic_links.first.should be_nil
|
||||
end
|
||||
|
||||
|
||||
it 'should not create a normal link' do
|
||||
@pm.topic_links.first.should_not be_nil
|
||||
end
|
||||
|
|
|
@ -7,8 +7,8 @@ describe Topic do
|
|||
it { should validate_presence_of :title }
|
||||
|
||||
it { should belong_to :category }
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :last_poster }
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :last_poster }
|
||||
it { should belong_to :featured_user1 }
|
||||
it { should belong_to :featured_user2 }
|
||||
it { should belong_to :featured_user3 }
|
||||
|
@ -16,7 +16,7 @@ describe Topic do
|
|||
|
||||
it { should have_many :posts }
|
||||
it { should have_many :topic_users }
|
||||
it { should have_many :topic_links }
|
||||
it { should have_many :topic_links }
|
||||
it { should have_many :topic_allowed_users }
|
||||
it { should have_many :allowed_users }
|
||||
it { should have_many :invites }
|
||||
|
@ -105,12 +105,12 @@ describe Topic do
|
|||
it "won't allow another topic to be created with the same name" do
|
||||
new_topic.should be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'html in title' do
|
||||
let(:topic) { Fabricate(:topic, title: "<script>alert('title')</script> is my topic title" ) }
|
||||
let(:topic) { Fabricate(:topic, title: "<script>alert('title')</script> is my topic title" ) }
|
||||
|
||||
it "should escape the HTML" do
|
||||
topic.title.should == "is my topic title"
|
||||
|
@ -119,7 +119,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
context 'fancy title' do
|
||||
let(:topic) { Fabricate(:topic, title: "\"this topic\" -- has ``fancy stuff''" ) }
|
||||
let(:topic) { Fabricate(:topic, title: "\"this topic\" -- has ``fancy stuff''" ) }
|
||||
|
||||
context 'title_fancy_entities disabled' do
|
||||
before do
|
||||
|
@ -172,7 +172,7 @@ describe Topic do
|
|||
context 'move_posts' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:category) { Fabricate(:category, user: user) }
|
||||
let!(:topic) { Fabricate(:topic, user: user, category: category) }
|
||||
let!(:topic) { Fabricate(:topic, user: user, category: category) }
|
||||
let!(:p1) { Fabricate(:post, topic: topic, user: user) }
|
||||
let!(:p2) { Fabricate(:post, topic: topic, user: user)}
|
||||
let!(:p3) { Fabricate(:post, topic: topic, user: user)}
|
||||
|
@ -210,7 +210,7 @@ describe Topic do
|
|||
topic.expects(:add_moderator_post)
|
||||
TopicUser.update_last_read(user, topic.id, p4.post_number, 0)
|
||||
end
|
||||
|
||||
|
||||
let!(:new_topic) { topic.move_posts(user, "new topic name", [p2.id, p4.id]) }
|
||||
|
||||
|
||||
|
@ -238,7 +238,7 @@ describe Topic do
|
|||
|
||||
it "has renumbered the first post" do
|
||||
p2.reload
|
||||
p2.post_number.should == 1
|
||||
p2.post_number.should == 1
|
||||
end
|
||||
|
||||
it "has changed the first post's sort order" do
|
||||
|
@ -254,7 +254,7 @@ describe Topic do
|
|||
it "has changed the fourth post's sort order" do
|
||||
p4.reload
|
||||
p4.sort_order.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
it "has the correct highest_post_number" do
|
||||
new_topic.reload
|
||||
|
@ -288,28 +288,28 @@ describe Topic do
|
|||
|
||||
end
|
||||
|
||||
context 'private message' do
|
||||
let(:coding_horror) { User.where(username: 'CodingHorror').first }
|
||||
context 'private message' do
|
||||
let(:coding_horror) { User.where(username: 'CodingHorror').first }
|
||||
let(:evil_trout) { Fabricate(:evil_trout) }
|
||||
let!(:topic) { Fabricate(:private_message_topic) }
|
||||
let!(:topic) { Fabricate(:private_message_topic) }
|
||||
|
||||
it "should allow the allowed users to see the topic" do
|
||||
Guardian.new(topic.user).can_see?(topic).should be_true
|
||||
end
|
||||
|
||||
it "should disallow anon to see the topic" do
|
||||
it "should disallow anon to see the topic" do
|
||||
Guardian.new.can_see?(topic).should be_false
|
||||
end
|
||||
|
||||
it "should disallow a different user to see the topic" do
|
||||
it "should disallow a different user to see the topic" do
|
||||
Guardian.new(evil_trout).can_see?(topic).should be_false
|
||||
end
|
||||
|
||||
it "should allow the recipient user to see the topic" do
|
||||
it "should allow the recipient user to see the topic" do
|
||||
Guardian.new(coding_horror).can_see?(topic).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "should be excluded from the list view" do
|
||||
it "should be excluded from the list view" do
|
||||
TopicQuery.new(evil_trout).list_popular.topics.should_not include(topic)
|
||||
end
|
||||
|
||||
|
@ -355,23 +355,23 @@ describe Topic do
|
|||
lambda { topic.invite(topic.user, walter.email) }.should change(Notification, :count)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "user actions" do
|
||||
context "user actions" do
|
||||
let(:actions) { topic.user.user_actions }
|
||||
|
||||
it "should not log a user action for the creation of the topic" do
|
||||
it "should not log a user action for the creation of the topic" do
|
||||
actions.map{|a| a.action_type}.should_not include(UserAction::NEW_TOPIC)
|
||||
end
|
||||
|
||||
it "should log a user action for the creation of a private message" do
|
||||
|
||||
it "should log a user action for the creation of a private message" do
|
||||
actions.map{|a| a.action_type}.should include(UserAction::NEW_PRIVATE_MESSAGE)
|
||||
end
|
||||
|
||||
it "should log a user action for the recepient of the private message" do
|
||||
it "should log a user action for the recepient of the private message" do
|
||||
coding_horror.user_actions.map{|a| a.action_type}.should include(UserAction::GOT_PRIVATE_MESSAGE)
|
||||
end
|
||||
end
|
||||
|
@ -432,14 +432,14 @@ describe Topic do
|
|||
@last_post.revise(Fabricate(:moderator), 'updated contents')
|
||||
@topic.reload
|
||||
}.should change(@topic, :bumped_at)
|
||||
end
|
||||
end
|
||||
|
||||
it "doesn't bump the topic when a post that isn't the last post receives a new version" do
|
||||
lambda {
|
||||
@earlier_post.revise(Fabricate(:moderator), 'updated contents')
|
||||
@topic.reload
|
||||
}.should_not change(@topic, :bumped_at)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
@ -454,7 +454,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'creates a moderator post' do
|
||||
@mod_post.should be_present
|
||||
@mod_post.should be_present
|
||||
end
|
||||
|
||||
it 'has the moderator action type' do
|
||||
|
@ -472,7 +472,7 @@ describe Topic do
|
|||
|
||||
it "has the custom sort order we specified" do
|
||||
@mod_post.sort_order.should == 999
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates a topic link' do
|
||||
@topic.topic_links.count.should == 1
|
||||
|
@ -490,13 +490,13 @@ describe Topic do
|
|||
|
||||
context 'visibility' do
|
||||
context 'disable' do
|
||||
before do
|
||||
before do
|
||||
@topic.update_status('visible', false, @user)
|
||||
@topic.reload
|
||||
end
|
||||
|
||||
it 'should not be visible' do
|
||||
@topic.should_not be_visible
|
||||
@topic.should_not be_visible
|
||||
end
|
||||
|
||||
it 'adds a moderator post' do
|
||||
|
@ -517,7 +517,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should be visible' do
|
||||
@topic.should be_visible
|
||||
@topic.should be_visible
|
||||
end
|
||||
|
||||
it 'adds a moderator post' do
|
||||
|
@ -526,8 +526,8 @@ describe Topic do
|
|||
|
||||
it "doesn't bump the topic" do
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'pinned' do
|
||||
|
@ -538,7 +538,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should not be pinned' do
|
||||
@topic.should_not be_pinned
|
||||
@topic.should_not be_pinned
|
||||
end
|
||||
|
||||
it 'adds a moderator post' do
|
||||
|
@ -547,7 +547,7 @@ describe Topic do
|
|||
|
||||
it "doesn't bump the topic" do
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'enable' do
|
||||
|
@ -558,7 +558,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should be pinned' do
|
||||
@topic.should be_pinned
|
||||
@topic.should be_pinned
|
||||
end
|
||||
|
||||
it 'adds a moderator post' do
|
||||
|
@ -568,7 +568,7 @@ describe Topic do
|
|||
it "doesn't bump the topic" do
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'archived' do
|
||||
|
@ -579,7 +579,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should not be pinned' do
|
||||
@topic.should_not be_archived
|
||||
@topic.should_not be_archived
|
||||
end
|
||||
|
||||
it 'adds a moderator post' do
|
||||
|
@ -588,7 +588,7 @@ describe Topic do
|
|||
|
||||
it "doesn't bump the topic" do
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'enable' do
|
||||
|
@ -599,7 +599,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should be archived' do
|
||||
@topic.should be_archived
|
||||
@topic.should be_archived
|
||||
end
|
||||
|
||||
it 'adds a moderator post' do
|
||||
|
@ -608,8 +608,8 @@ describe Topic do
|
|||
|
||||
it "doesn't bump the topic" do
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'closed' do
|
||||
|
@ -630,7 +630,7 @@ describe Topic do
|
|||
# We bump the topic when a topic is re-opened
|
||||
it "bumps the topic" do
|
||||
@topic.bumped_at.to_f.should_not == @original_bumped_at
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
@ -642,7 +642,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should be closed' do
|
||||
@topic.should be_closed
|
||||
@topic.should be_closed
|
||||
end
|
||||
|
||||
it 'adds a moderator post' do
|
||||
|
@ -651,9 +651,9 @@ describe Topic do
|
|||
|
||||
it "doesn't bump the topic" do
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -668,15 +668,15 @@ describe Topic do
|
|||
|
||||
it 'triggers a forum topic user change with true' do
|
||||
# otherwise no chance the mock will work
|
||||
freeze_time do
|
||||
freeze_time do
|
||||
TopicUser.expects(:change).with(@user, @topic.id, starred: true, starred_at: DateTime.now)
|
||||
@topic.toggle_star(@user, true)
|
||||
end
|
||||
end
|
||||
|
||||
it 'increases the star_count of the forum topic' do
|
||||
lambda {
|
||||
@topic.toggle_star(@user, true)
|
||||
lambda {
|
||||
@topic.toggle_star(@user, true)
|
||||
@topic.reload
|
||||
}.should change(@topic, :star_count).by(1)
|
||||
end
|
||||
|
@ -688,8 +688,8 @@ describe Topic do
|
|||
|
||||
describe 'removing a star' do
|
||||
before do
|
||||
@topic.toggle_star(@user, true)
|
||||
@topic.reload
|
||||
@topic.toggle_star(@user, true)
|
||||
@topic.reload
|
||||
end
|
||||
|
||||
it 'rolls back the rate limiter' do
|
||||
|
@ -703,10 +703,10 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'reduces the star_count' do
|
||||
lambda {
|
||||
@topic.toggle_star(@user, false)
|
||||
lambda {
|
||||
@topic.toggle_star(@user, false)
|
||||
@topic.reload
|
||||
}.should change(@topic, :star_count).by(-1)
|
||||
}.should change(@topic, :star_count).by(-1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -766,18 +766,18 @@ describe Topic do
|
|||
@topic_user = @second_user.topic_users.where(topic_id: @topic.id).first
|
||||
end
|
||||
|
||||
it 'clears the posted flag for the second user' do
|
||||
it 'clears the posted flag for the second user' do
|
||||
@topic_user.posted?.should be_false
|
||||
end
|
||||
|
||||
it "sets the second user's last_read_post_number back to 1" do
|
||||
it "sets the second user's last_read_post_number back to 1" do
|
||||
@topic_user.last_read_post_number.should == 1
|
||||
end
|
||||
|
||||
it "sets the second user's last_read_post_number back to 1" do
|
||||
it "sets the second user's last_read_post_number back to 1" do
|
||||
@topic_user.seen_post_count.should == 1
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
@ -849,7 +849,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'is not a best_of' do
|
||||
topic.has_best_of.should be_false
|
||||
topic.has_best_of.should be_false
|
||||
end
|
||||
|
||||
it 'is not invisible' do
|
||||
|
@ -882,7 +882,7 @@ describe Topic do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe 'versions' do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
|
||||
|
@ -941,8 +941,8 @@ describe Topic do
|
|||
|
||||
before do
|
||||
@topic = Fabricate(:topic)
|
||||
@category = Fabricate(:category, user: @topic.user)
|
||||
@user = @topic.user
|
||||
@category = Fabricate(:category, user: @topic.user)
|
||||
@user = @topic.user
|
||||
end
|
||||
|
||||
describe 'without a previous category' do
|
||||
|
@ -957,7 +957,7 @@ describe Topic do
|
|||
@category.reload
|
||||
end
|
||||
|
||||
it 'changes the category' do
|
||||
it 'changes the category' do
|
||||
@topic.category.should == @category
|
||||
end
|
||||
|
||||
|
@ -1010,20 +1010,20 @@ describe Topic do
|
|||
it "should lower the original category's topic count" do
|
||||
@category.topic_count.should == 0
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe 'when the category exists' do
|
||||
before do
|
||||
@topic.change_category(nil)
|
||||
@category.reload
|
||||
@category.reload
|
||||
end
|
||||
|
||||
it "resets the category" do
|
||||
it "resets the category" do
|
||||
@topic.category_id.should be_blank
|
||||
end
|
||||
|
||||
it "lowers the forum topic count" do
|
||||
it "lowers the forum topic count" do
|
||||
@category.topic_count.should == 0
|
||||
end
|
||||
|
||||
|
|
|
@ -13,49 +13,49 @@ describe TopicUser do
|
|||
@user = Fabricate(:coding_horror)
|
||||
end
|
||||
|
||||
describe 'notifications' do
|
||||
describe 'notifications' do
|
||||
|
||||
it 'should be set to tracking if auto_track_topics is enabled' do
|
||||
it 'should be set to tracking if auto_track_topics is enabled' do
|
||||
@user.auto_track_topics_after_msecs = 0
|
||||
@user.save
|
||||
TopicUser.change(@user, @topic, {:starred_at => DateTime.now})
|
||||
TopicUser.get(@topic,@user).notification_level.should == TopicUser::NotificationLevel::TRACKING
|
||||
end
|
||||
|
||||
it 'should reset regular topics to tracking topics if auto track is changed' do
|
||||
it 'should reset regular topics to tracking topics if auto track is changed' do
|
||||
TopicUser.change(@user, @topic, {:starred_at => DateTime.now})
|
||||
@user.auto_track_topics_after_msecs = 0
|
||||
@user.save
|
||||
TopicUser.get(@topic,@user).notification_level.should == TopicUser::NotificationLevel::TRACKING
|
||||
end
|
||||
|
||||
it 'should be set to "regular" notifications, by default on non creators' do
|
||||
it 'should be set to "regular" notifications, by default on non creators' do
|
||||
TopicUser.change(@user, @topic, {:starred_at => DateTime.now})
|
||||
TopicUser.get(@topic,@user).notification_level.should == TopicUser::NotificationLevel::REGULAR
|
||||
end
|
||||
|
||||
it 'reason should reset when changed' do
|
||||
it 'reason should reset when changed' do
|
||||
@topic.notify_muted!(@topic.user)
|
||||
TopicUser.get(@topic,@topic.user).notifications_reason_id.should == TopicUser::NotificationReasons::USER_CHANGED
|
||||
end
|
||||
|
||||
it 'should have the correct reason for a user change when watched' do
|
||||
|
||||
it 'should have the correct reason for a user change when watched' do
|
||||
@topic.notify_watch!(@user)
|
||||
tu = TopicUser.get(@topic,@user)
|
||||
tu.notification_level.should == TopicUser::NotificationLevel::WATCHING
|
||||
tu.notifications_reason_id.should == TopicUser::NotificationReasons::USER_CHANGED
|
||||
tu.notifications_changed_at.should_not be_nil
|
||||
end
|
||||
|
||||
it 'should have the correct reason for a user change when set to regular' do
|
||||
|
||||
it 'should have the correct reason for a user change when set to regular' do
|
||||
@topic.notify_regular!(@user)
|
||||
tu = TopicUser.get(@topic,@user)
|
||||
tu.notification_level.should == TopicUser::NotificationLevel::REGULAR
|
||||
tu.notifications_reason_id.should == TopicUser::NotificationReasons::USER_CHANGED
|
||||
tu.notifications_changed_at.should_not be_nil
|
||||
end
|
||||
|
||||
it 'should have the correct reason for a user change when set to regular' do
|
||||
|
||||
it 'should have the correct reason for a user change when set to regular' do
|
||||
@topic.notify_muted!(@user)
|
||||
tu = TopicUser.get(@topic,@user)
|
||||
tu.notification_level.should == TopicUser::NotificationLevel::MUTED
|
||||
|
@ -75,17 +75,17 @@ describe TopicUser do
|
|||
TopicUser.track_visit!(@topic, @user)
|
||||
@topic_user = TopicUser.get(@topic,@user)
|
||||
|
||||
end
|
||||
|
||||
it 'set upon initial visit' do
|
||||
end
|
||||
|
||||
it 'set upon initial visit' do
|
||||
@topic_user.first_visited_at.to_i.should == @now.to_i
|
||||
@topic_user.last_visited_at.to_i.should == @now.to_i
|
||||
end
|
||||
|
||||
it 'updates upon repeat visit' do
|
||||
it 'updates upon repeat visit' do
|
||||
tomorrow = @now.tomorrow
|
||||
DateTime.expects(:now).returns(tomorrow)
|
||||
|
||||
|
||||
TopicUser.track_visit!(@topic,@user)
|
||||
# reload is a no go
|
||||
@topic_user = TopicUser.get(@topic,@user)
|
||||
|
@ -95,21 +95,21 @@ describe TopicUser do
|
|||
|
||||
end
|
||||
|
||||
describe 'read tracking' do
|
||||
before do
|
||||
@post = Fabricate(:post, topic: @topic, user: @topic.user)
|
||||
describe 'read tracking' do
|
||||
before do
|
||||
@post = Fabricate(:post, topic: @topic, user: @topic.user)
|
||||
TopicUser.update_last_read(@user, @topic.id, 1, 0)
|
||||
@topic_user = TopicUser.get(@topic,@user)
|
||||
end
|
||||
|
||||
it 'should create a new record for a visit' do
|
||||
it 'should create a new record for a visit' do
|
||||
@topic_user.last_read_post_number.should == 1
|
||||
@topic_user.last_visited_at.to_i.should == @now.to_i
|
||||
@topic_user.first_visited_at.to_i.should == @now.to_i
|
||||
end
|
||||
|
||||
it 'should update the record for repeat visit' do
|
||||
Fabricate(:post, topic: @topic, user: @user)
|
||||
|
||||
it 'should update the record for repeat visit' do
|
||||
Fabricate(:post, topic: @topic, user: @user)
|
||||
TopicUser.update_last_read(@user, @topic.id, 2, 0)
|
||||
@topic_user = TopicUser.get(@topic,@user)
|
||||
@topic_user.last_read_post_number.should == 2
|
||||
|
@ -117,21 +117,21 @@ describe TopicUser do
|
|||
@topic_user.first_visited_at.to_i.should == @now.to_i
|
||||
end
|
||||
|
||||
context 'auto tracking' do
|
||||
context 'auto tracking' do
|
||||
before do
|
||||
Fabricate(:post, topic: @topic, user: @user)
|
||||
Fabricate(:post, topic: @topic, user: @user)
|
||||
@new_user = Fabricate(:user, auto_track_topics_after_msecs: 1000)
|
||||
TopicUser.update_last_read(@new_user, @topic.id, 2, 0)
|
||||
@topic_user = TopicUser.get(@topic,@new_user)
|
||||
end
|
||||
|
||||
|
||||
it 'should automatically track topics you reply to' do
|
||||
post = Fabricate(:post, topic: @topic, user: @new_user)
|
||||
@topic_user = TopicUser.get(@topic,@new_user)
|
||||
@topic_user.notification_level.should == TopicUser::NotificationLevel::TRACKING
|
||||
@topic_user.notifications_reason_id.should == TopicUser::NotificationReasons::CREATED_POST
|
||||
end
|
||||
|
||||
|
||||
it 'should not automatically track topics you reply to and have set state manually' do
|
||||
Fabricate(:post, topic: @topic, user: @new_user)
|
||||
TopicUser.change(@new_user, @topic, notification_level: TopicUser::NotificationLevel::REGULAR)
|
||||
|
@ -140,14 +140,14 @@ describe TopicUser do
|
|||
@topic_user.notifications_reason_id.should == TopicUser::NotificationReasons::USER_CHANGED
|
||||
end
|
||||
|
||||
it 'should automatically track topics after they are read for long enough' do
|
||||
it 'should automatically track topics after they are read for long enough' do
|
||||
@topic_user.notification_level.should == TopicUser::NotificationLevel::REGULAR
|
||||
TopicUser.update_last_read(@new_user, @topic.id, 2, 1001)
|
||||
@topic_user = TopicUser.get(@topic,@new_user)
|
||||
@topic_user.notification_level.should == TopicUser::NotificationLevel::TRACKING
|
||||
end
|
||||
|
||||
it 'should not automatically track topics after they are read for long enough if changed manually' do
|
||||
|
||||
it 'should not automatically track topics after they are read for long enough if changed manually' do
|
||||
TopicUser.change(@new_user, @topic, notification_level: TopicUser::NotificationLevel::REGULAR)
|
||||
@topic_user = TopicUser.get(@topic,@new_user)
|
||||
|
||||
|
@ -173,7 +173,7 @@ describe TopicUser do
|
|||
TopicUser.change(@user, @topic.id, starred: true)
|
||||
}.should change(TopicUser, :count).by(1)
|
||||
end
|
||||
|
||||
|
||||
describe 'after creating a row' do
|
||||
before do
|
||||
TopicUser.change(@user, @topic.id, starred: true)
|
||||
|
@ -196,4 +196,4 @@ describe TopicUser do
|
|||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,70 +6,70 @@ describe UserAction do
|
|||
it { should validate_presence_of :user_id }
|
||||
|
||||
|
||||
describe 'lists' do
|
||||
describe 'lists' do
|
||||
|
||||
let(:public_post) { Fabricate(:post) }
|
||||
let(:public_topic) { public_post.topic }
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
let(:private_post) { Fabricate(:post) }
|
||||
let(:private_topic) do
|
||||
let(:private_topic) do
|
||||
topic = private_post.topic
|
||||
topic.update_column(:archetype, Archetype::private_message)
|
||||
topic.update_column(:archetype, Archetype::private_message)
|
||||
topic
|
||||
end
|
||||
|
||||
def log_test_action(opts={})
|
||||
UserAction.log_action!({
|
||||
action_type: UserAction::NEW_PRIVATE_MESSAGE,
|
||||
user_id: user.id,
|
||||
acting_user_id: user.id,
|
||||
user_id: user.id,
|
||||
acting_user_id: user.id,
|
||||
target_topic_id: private_topic.id,
|
||||
target_post_id: private_post.id,
|
||||
target_post_id: private_post.id,
|
||||
}.merge(opts))
|
||||
end
|
||||
|
||||
before do
|
||||
before do
|
||||
# Create some test data using a helper
|
||||
log_test_action
|
||||
log_test_action(action_type: UserAction::GOT_PRIVATE_MESSAGE)
|
||||
log_test_action(action_type: UserAction::NEW_TOPIC, target_topic_id: public_topic.id, target_post_id: public_post.id)
|
||||
log_test_action(action_type: UserAction::BOOKMARK)
|
||||
log_test_action(action_type: UserAction::BOOKMARK)
|
||||
end
|
||||
|
||||
describe 'stats' do
|
||||
|
||||
let :mystats do
|
||||
let :mystats do
|
||||
UserAction.stats(user.id, Guardian.new(user))
|
||||
end
|
||||
|
||||
it 'should include non private message events' do
|
||||
it 'should include non private message events' do
|
||||
mystats.map{|r| r["action_type"].to_i}.should include(UserAction::NEW_TOPIC)
|
||||
end
|
||||
|
||||
it 'should exclude private messages for non owners' do
|
||||
it 'should exclude private messages for non owners' do
|
||||
UserAction.stats(user.id,Guardian.new).map{|r| r["action_type"].to_i}.should_not include(UserAction::NEW_PRIVATE_MESSAGE)
|
||||
end
|
||||
|
||||
it 'should not include got private messages for owners' do
|
||||
it 'should not include got private messages for owners' do
|
||||
UserAction.stats(user.id,Guardian.new).map{|r| r["action_type"].to_i}.should_not include(UserAction::GOT_PRIVATE_MESSAGE)
|
||||
end
|
||||
|
||||
it 'should include private messages for owners' do
|
||||
|
||||
it 'should include private messages for owners' do
|
||||
mystats.map{|r| r["action_type"].to_i}.should include(UserAction::NEW_PRIVATE_MESSAGE)
|
||||
end
|
||||
|
||||
it 'should include got private messages for owners' do
|
||||
it 'should include got private messages for owners' do
|
||||
mystats.map{|r| r["action_type"].to_i}.should include(UserAction::GOT_PRIVATE_MESSAGE)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'stream' do
|
||||
describe 'stream' do
|
||||
|
||||
it 'should have 1 item for non owners' do
|
||||
UserAction.stream(user_id: user.id, guardian: Guardian.new).count.should == 1
|
||||
end
|
||||
|
||||
|
||||
it 'should have bookmarks and pms for owners' do
|
||||
UserAction.stream(user_id: user.id, guardian: user.guardian).count.should == 4
|
||||
end
|
||||
|
@ -82,7 +82,7 @@ describe UserAction do
|
|||
Fabricate(:user_action)
|
||||
end
|
||||
|
||||
describe 'when user likes' do
|
||||
describe 'when user likes' do
|
||||
|
||||
let!(:post) { Fabricate(:post) }
|
||||
let(:likee) { post.user }
|
||||
|
@ -96,24 +96,24 @@ describe UserAction do
|
|||
@old_count = likee_stream.count
|
||||
end
|
||||
|
||||
it "creates a new stream entry" do
|
||||
PostAction.act(liker, post, PostActionType.Types[:like])
|
||||
it "creates a new stream entry" do
|
||||
PostAction.act(liker, post, PostActionType.Types[:like])
|
||||
likee_stream.count.should == @old_count + 1
|
||||
end
|
||||
|
||||
context "successful like" do
|
||||
before do
|
||||
before do
|
||||
PostAction.act(liker, post, PostActionType.Types[:like])
|
||||
@liker_action = liker.user_actions.where(action_type: UserAction::LIKE).first
|
||||
@likee_action = likee.user_actions.where(action_type: UserAction::WAS_LIKED).first
|
||||
end
|
||||
|
||||
it 'should create a like action on the liker' do
|
||||
@liker_action.should_not be_nil
|
||||
it 'should create a like action on the liker' do
|
||||
@liker_action.should_not be_nil
|
||||
end
|
||||
|
||||
it 'should create a like action on the likee' do
|
||||
@likee_action.should_not be_nil
|
||||
@likee_action.should_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -124,8 +124,8 @@ describe UserAction do
|
|||
end
|
||||
|
||||
it "doesn't add the entry to the stream" do
|
||||
PostAction.act(liker, post, PostActionType.Types[:like])
|
||||
likee_stream.count.should_not == @old_count + 1
|
||||
PostAction.act(liker, post, PostActionType.Types[:like])
|
||||
likee_stream.count.should_not == @old_count + 1
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -133,53 +133,53 @@ describe UserAction do
|
|||
end
|
||||
|
||||
describe 'when a user posts a new topic' do
|
||||
before do
|
||||
before do
|
||||
@post = Fabricate(:old_post)
|
||||
end
|
||||
|
||||
describe 'topic action' do
|
||||
before do
|
||||
describe 'topic action' do
|
||||
before do
|
||||
@action = @post.user.user_actions.where(action_type: UserAction::NEW_TOPIC).first
|
||||
end
|
||||
it 'should exist' do
|
||||
it 'should exist' do
|
||||
@action.should_not be_nil
|
||||
end
|
||||
it 'shoule have the correct date' do
|
||||
it 'shoule have the correct date' do
|
||||
@action.created_at.should be_within(1).of(@post.topic.created_at)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not log a post user action' do
|
||||
it 'should not log a post user action' do
|
||||
@post.user.user_actions.where(action_type: UserAction::POST).first.should be_nil
|
||||
end
|
||||
|
||||
|
||||
describe 'when another user posts on the topic' do
|
||||
before do
|
||||
describe 'when another user posts on the topic' do
|
||||
before do
|
||||
@other_user = Fabricate(:coding_horror)
|
||||
@mentioned = Fabricate(:admin)
|
||||
@response = Fabricate(:post, reply_to_post_number: 1, topic: @post.topic, user: @other_user, raw: "perhaps @#{@mentioned.username} knows how this works?")
|
||||
end
|
||||
|
||||
it 'should log a post action for the poster' do
|
||||
|
||||
it 'should log a post action for the poster' do
|
||||
@response.user.user_actions.where(action_type: UserAction::POST).first.should_not be_nil
|
||||
end
|
||||
|
||||
it 'should log a post action for the original poster' do
|
||||
it 'should log a post action for the original poster' do
|
||||
@post.user.user_actions.where(action_type: UserAction::RESPONSE).first.should_not be_nil
|
||||
end
|
||||
|
||||
it 'should log a mention for the mentioned' do
|
||||
it 'should log a mention for the mentioned' do
|
||||
@mentioned.user_actions.where(action_type: UserAction::MENTION).first.should_not be_nil
|
||||
end
|
||||
|
||||
it 'should not log a double notification for a post edit' do
|
||||
@response.raw = "here it goes again"
|
||||
@response.save!
|
||||
@response.save!
|
||||
@response.user.user_actions.where(action_type: UserAction::POST).count.should == 1
|
||||
end
|
||||
|
||||
it 'should not log topic reply and reply for a single post' do
|
||||
it 'should not log topic reply and reply for a single post' do
|
||||
@post.user.user_actions.joins(:target_post).where('posts.post_number = 2').count.should == 1
|
||||
end
|
||||
|
||||
|
@ -188,26 +188,26 @@ describe UserAction do
|
|||
end
|
||||
|
||||
describe 'when user bookmarks' do
|
||||
before do
|
||||
before do
|
||||
@post = Fabricate(:post)
|
||||
@user = @post.user
|
||||
PostAction.act(@user, @post, PostActionType.Types[:bookmark])
|
||||
@action = @user.user_actions.where(action_type: UserAction::BOOKMARK).first
|
||||
end
|
||||
|
||||
it 'should create a bookmark action' do
|
||||
it 'should create a bookmark action' do
|
||||
@action.action_type.should == UserAction::BOOKMARK
|
||||
end
|
||||
it 'should point to the correct post' do
|
||||
@action.target_post_id.should == @post.id
|
||||
end
|
||||
it 'should have the right acting_user' do
|
||||
@action.acting_user_id.should == @user.id
|
||||
@action.acting_user_id.should == @user.id
|
||||
end
|
||||
it 'should target the correct user' do
|
||||
it 'should target the correct user' do
|
||||
@action.user_id.should == @user.id
|
||||
end
|
||||
it 'should nuke the action when unbookmarked' do
|
||||
it 'should nuke the action when unbookmarked' do
|
||||
PostAction.remove_act(@user, @post, PostActionType.Types[:bookmark])
|
||||
@user.user_actions.where(action_type: UserAction::BOOKMARK).first.should be_nil
|
||||
end
|
||||
|
|
|
@ -170,8 +170,8 @@ describe User do
|
|||
|
||||
end
|
||||
|
||||
describe 'delete posts' do
|
||||
before do
|
||||
describe 'delete posts' do
|
||||
before do
|
||||
@post1 = Fabricate(:post)
|
||||
@user = @post1.user
|
||||
@post2 = Fabricate(:post, topic: @post1.topic, user: @user)
|
||||
|
@ -180,7 +180,7 @@ describe User do
|
|||
@guardian = Guardian.new(Fabricate(:admin))
|
||||
end
|
||||
|
||||
it 'allows moderator to delete all posts' do
|
||||
it 'allows moderator to delete all posts' do
|
||||
@user.delete_all_posts!(@guardian)
|
||||
@posts.each do |p|
|
||||
p.reload
|
||||
|
@ -689,24 +689,24 @@ describe User do
|
|||
end
|
||||
|
||||
|
||||
describe 'update_time_read!' do
|
||||
describe 'update_time_read!' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it 'makes no changes if nothing is cached' do
|
||||
it 'makes no changes if nothing is cached' do
|
||||
$redis.expects(:get).with("user-last-seen:#{user.id}").returns(nil)
|
||||
user.update_time_read!
|
||||
user.reload
|
||||
user.time_read.should == 0
|
||||
end
|
||||
|
||||
it 'makes a change if time read is below threshold' do
|
||||
it 'makes a change if time read is below threshold' do
|
||||
$redis.expects(:get).with("user-last-seen:#{user.id}").returns(Time.now - 10.0)
|
||||
user.update_time_read!
|
||||
user.reload
|
||||
user.time_read.should == 10
|
||||
end
|
||||
|
||||
it 'makes no change if time read is above threshold' do
|
||||
it 'makes no change if time read is above threshold' do
|
||||
t = Time.now - 1 - User::MAX_TIME_READ_DIFF
|
||||
$redis.expects(:get).with("user-last-seen:#{user.id}").returns(t)
|
||||
user.update_time_read!
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe "Stores incoming links" do
|
||||
before do
|
||||
before do
|
||||
TopicUser.stubs(:track_visit!)
|
||||
end
|
||||
|
||||
let :topic do
|
||||
let :topic do
|
||||
Fabricate(:post).topic
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module Helpers
|
|||
def log_in_user(user)
|
||||
session[:current_user_id] = user.id
|
||||
end
|
||||
|
||||
|
||||
def fixture_file(filename)
|
||||
return '' if filename == ''
|
||||
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
||||
|
@ -60,7 +60,7 @@ Spork.prefork do
|
|||
config.infer_base_class_for_anonymous_controllers = true
|
||||
|
||||
config.before(:suite) do
|
||||
SeedFu.seed
|
||||
SeedFu.seed
|
||||
end
|
||||
|
||||
config.before(:all) do
|
||||
|
@ -71,7 +71,7 @@ Spork.prefork do
|
|||
|
||||
class DateTime
|
||||
class << self
|
||||
alias_method :old_now, :now
|
||||
alias_method :old_now, :now
|
||||
def now
|
||||
@now || old_now
|
||||
end
|
||||
|
@ -95,7 +95,7 @@ end
|
|||
|
||||
Spork.each_run do
|
||||
# This code will be run each time you run your specs.
|
||||
$redis.client.reconnect
|
||||
$redis.client.reconnect
|
||||
MessageBus.reliable_pub_sub.pub_redis.client.reconnect
|
||||
Rails.cache.reconnect
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ describe "users/omniauth_callbacks/complete.html.erb" do
|
|||
rendered_data["auth_provider"].should eq("OpenId")
|
||||
rendered_data["awaiting_activation"].should eq(true)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue