models with rspec3 syntax
This commit is contained in:
parent
07540bcb49
commit
b52f12948a
|
@ -8,7 +8,7 @@ describe ApiKey do
|
|||
|
||||
it { is_expected.to validate_presence_of :key }
|
||||
|
||||
pending 'validates uniqueness of user_id' do
|
||||
skip 'validates uniqueness of user_id' do
|
||||
Fabricate(:api_key)
|
||||
is_expected.to validate_uniqueness_of(:user_id)
|
||||
end
|
||||
|
|
|
@ -5,11 +5,11 @@ describe Notification do
|
|||
ActiveRecord::Base.observers.enable :all
|
||||
end
|
||||
|
||||
it { should validate_presence_of :notification_type }
|
||||
it { should validate_presence_of :data }
|
||||
it { is_expected.to validate_presence_of :notification_type }
|
||||
it { is_expected.to validate_presence_of :data }
|
||||
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :topic }
|
||||
it { is_expected.to belong_to :user }
|
||||
it { is_expected.to belong_to :topic }
|
||||
|
||||
describe 'post' do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
|
@ -30,17 +30,17 @@ describe Notification do
|
|||
|
||||
|
||||
it 'notifies the poster on reply' do
|
||||
lambda {
|
||||
expect {
|
||||
reply = Fabricate(:basic_reply, user: coding_horror, topic: post.topic)
|
||||
process_alerts(reply)
|
||||
}.should change(post.user.notifications, :count).by(1)
|
||||
}.to change(post.user.notifications, :count).by(1)
|
||||
end
|
||||
|
||||
it "doesn't notify the poster when they reply to their own post" do
|
||||
lambda {
|
||||
expect {
|
||||
reply = Fabricate(:basic_reply, user: post.user, topic: post.topic)
|
||||
process_alerts(reply)
|
||||
}.should_not change(post.user.notifications, :count)
|
||||
}.not_to change(post.user.notifications, :count)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,9 +49,9 @@ describe Notification do
|
|||
post = PostAlerter.post_created(Fabricate(:post, post_args))
|
||||
user2 = Fabricate(:coding_horror)
|
||||
post_args[:topic].notify_watch!(user2)
|
||||
lambda {
|
||||
expect {
|
||||
PostAlerter.post_created(Fabricate(:post, user: post.user, topic: post.topic))
|
||||
}.should change(user2.notifications, :count).by(1)
|
||||
}.to change(user2.notifications, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -62,9 +62,9 @@ describe Notification do
|
|||
user2 = Fabricate(:coding_horror)
|
||||
|
||||
post_args[:topic].notify_muted!(user)
|
||||
lambda {
|
||||
expect {
|
||||
Fabricate(:post, user: user2, topic: post.topic, raw: 'hello @' + user.username)
|
||||
}.should change(user.notifications, :count).by(0)
|
||||
}.to change(user.notifications, :count).by(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -75,29 +75,29 @@ describe Notification do
|
|||
|
||||
context 'a regular notification' do
|
||||
it 'increases unread_notifications' do
|
||||
lambda { Fabricate(:notification, user: user); user.reload }.should change(user, :unread_notifications)
|
||||
expect { Fabricate(:notification, user: user); user.reload }.to change(user, :unread_notifications)
|
||||
end
|
||||
|
||||
it 'increases total_unread_notifications' do
|
||||
lambda { Fabricate(:notification, user: user); user.reload }.should change(user, :total_unread_notifications)
|
||||
expect { Fabricate(:notification, user: user); user.reload }.to change(user, :total_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)
|
||||
expect { Fabricate(:notification, user: user); user.reload }.not_to change(user, :unread_private_messages)
|
||||
end
|
||||
end
|
||||
|
||||
context 'a private message' do
|
||||
it "doesn't increase unread_notifications" do
|
||||
lambda { Fabricate(:private_message_notification, user: user); user.reload }.should_not change(user, :unread_notifications)
|
||||
expect { Fabricate(:private_message_notification, user: user); user.reload }.not_to change(user, :unread_notifications)
|
||||
end
|
||||
|
||||
it 'increases total_unread_notifications' do
|
||||
lambda { Fabricate(:notification, user: user); user.reload }.should change(user, :total_unread_notifications)
|
||||
expect { Fabricate(:notification, user: user); user.reload }.to change(user, :total_unread_notifications)
|
||||
end
|
||||
|
||||
it "increases unread_private_messages" do
|
||||
lambda { Fabricate(:private_message_notification, user: user); user.reload }.should change(user, :unread_private_messages)
|
||||
expect { Fabricate(:private_message_notification, user: user); user.reload }.to change(user, :unread_private_messages)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -147,14 +147,14 @@ describe Notification do
|
|||
end
|
||||
|
||||
it 'should create and rollup private message notifications' do
|
||||
@target.notifications.first.notification_type.should == Notification.types[:private_message]
|
||||
@post.user.unread_notifications.should == 0
|
||||
@post.user.total_unread_notifications.should == 0
|
||||
@target.unread_private_messages.should == 1
|
||||
expect(@target.notifications.first.notification_type).to eq(Notification.types[:private_message])
|
||||
expect(@post.user.unread_notifications).to eq(0)
|
||||
expect(@post.user.total_unread_notifications).to eq(0)
|
||||
expect(@target.unread_private_messages).to eq(1)
|
||||
|
||||
Fabricate(:post, topic: @topic, user: @topic.user)
|
||||
@target.reload
|
||||
@target.unread_private_messages.should == 1
|
||||
expect(@target.unread_private_messages).to eq(1)
|
||||
|
||||
end
|
||||
|
||||
|
@ -166,7 +166,7 @@ describe Notification do
|
|||
let!(:notification) { Fabricate(:notification, user: post.user, topic: post.topic, post_number: post.post_number) }
|
||||
|
||||
it 'returns the post' do
|
||||
notification.post.should == post
|
||||
expect(notification.post).to eq(post)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -175,11 +175,11 @@ describe Notification do
|
|||
let(:notification) { Fabricate.build(:notification) }
|
||||
|
||||
it 'should have a data hash' do
|
||||
notification.data_hash.should be_present
|
||||
expect(notification.data_hash).to be_present
|
||||
end
|
||||
|
||||
it 'should have the data within the json' do
|
||||
notification.data_hash[:poison].should == 'ivy'
|
||||
expect(notification.data_hash[:poison]).to eq('ivy')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -205,9 +205,9 @@ describe Notification do
|
|||
user.saw_notification_id(other.id)
|
||||
user.reload
|
||||
|
||||
user.unread_notifications.should == 0
|
||||
user.total_unread_notifications.should == 2
|
||||
user.unread_private_messages.should == 1
|
||||
expect(user.unread_notifications).to eq(0)
|
||||
expect(user.total_unread_notifications).to eq(2)
|
||||
expect(user.unread_private_messages).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -220,7 +220,7 @@ describe Notification do
|
|||
end
|
||||
Notification.create!(read: true, user_id: user.id, topic_id: 2, post_number: 4, data: '{}', notification_type: 1)
|
||||
|
||||
Notification.mark_posts_read(user,2,[1,2,3,4]).should == 3
|
||||
expect(Notification.mark_posts_read(user,2,[1,2,3,4])).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -244,7 +244,7 @@ describe Notification do
|
|||
# we may want to make notification "trashable" but for now we nuke pm notifications from deleted topics/posts
|
||||
Notification.ensure_consistency!
|
||||
|
||||
Notification.count.should == 2
|
||||
expect(Notification.count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -284,7 +284,7 @@ describe Notification do
|
|||
# bumps unread pms to front of list
|
||||
|
||||
notifications = Notification.recent_report(user, 3)
|
||||
notifications.map{|n| n.id}.should == [a.id, d.id, c.id]
|
||||
expect(notifications.map{|n| n.id}).to eq([a.id, d.id, c.id])
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ describe OptimizedImage do
|
|||
|
||||
it "returns nil" do
|
||||
OptimizedImage.expects(:resize).returns(false)
|
||||
OptimizedImage.create_for(upload, 100, 200).should == nil
|
||||
expect(OptimizedImage.create_for(upload, 100, 200)).to eq(nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -39,11 +39,11 @@ describe OptimizedImage do
|
|||
|
||||
it "works" do
|
||||
oi = OptimizedImage.create_for(upload, 100, 200)
|
||||
oi.sha1.should == "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||
oi.extension.should == ".png"
|
||||
oi.width.should == 100
|
||||
oi.height.should == 200
|
||||
oi.url.should == "/internally/stored/optimized/image.png"
|
||||
expect(oi.sha1).to eq("da39a3ee5e6b4b0d3255bfef95601890afd80709")
|
||||
expect(oi.extension).to eq(".png")
|
||||
expect(oi.width).to eq(100)
|
||||
expect(oi.height).to eq(200)
|
||||
expect(oi.url).to eq("/internally/stored/optimized/image.png")
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -59,7 +59,7 @@ describe OptimizedImage do
|
|||
|
||||
it "returns nil" do
|
||||
OptimizedImage.expects(:resize).returns(false)
|
||||
OptimizedImage.create_for(upload, 100, 200).should == nil
|
||||
expect(OptimizedImage.create_for(upload, 100, 200)).to eq(nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -78,11 +78,11 @@ describe OptimizedImage do
|
|||
|
||||
it "works" do
|
||||
oi = OptimizedImage.create_for(upload, 100, 200)
|
||||
oi.sha1.should == "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||
oi.extension.should == ".png"
|
||||
oi.width.should == 100
|
||||
oi.height.should == 200
|
||||
oi.url.should == "/externally/stored/optimized/image.png"
|
||||
expect(oi.sha1).to eq("da39a3ee5e6b4b0d3255bfef95601890afd80709")
|
||||
expect(oi.extension).to eq(".png")
|
||||
expect(oi.width).to eq(100)
|
||||
expect(oi.height).to eq(200)
|
||||
expect(oi.url).to eq("/externally/stored/optimized/image.png")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,14 +11,14 @@ describe Post do
|
|||
Fabricate.build(:post, args)
|
||||
end
|
||||
|
||||
it { should validate_presence_of :raw }
|
||||
it { is_expected.to validate_presence_of :raw }
|
||||
|
||||
# Min/max body lengths, respecting padding
|
||||
it { should_not allow_value("x").for(:raw) }
|
||||
it { should_not allow_value("x" * (SiteSetting.max_post_length + 1)).for(:raw) }
|
||||
it { should_not allow_value((" " * SiteSetting.min_post_length) + "x").for(:raw) }
|
||||
it { is_expected.not_to allow_value("x").for(:raw) }
|
||||
it { is_expected.not_to allow_value("x" * (SiteSetting.max_post_length + 1)).for(:raw) }
|
||||
it { is_expected.not_to allow_value((" " * SiteSetting.min_post_length) + "x").for(:raw) }
|
||||
|
||||
it { should rate_limit }
|
||||
it { is_expected.to rate_limit }
|
||||
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:post_args) do
|
||||
|
@ -32,14 +32,14 @@ describe Post do
|
|||
2.times do |t|
|
||||
Fabricate(:post, created_at: t.seconds.from_now)
|
||||
end
|
||||
Post.by_newest.first.created_at.should > Post.by_newest.last.created_at
|
||||
expect(Post.by_newest.first.created_at).to be > Post.by_newest.last.created_at
|
||||
end
|
||||
end
|
||||
|
||||
describe '#with_user' do
|
||||
it 'gives you a user' do
|
||||
Fabricate(:post, user: Fabricate.build(:user))
|
||||
Post.with_user.first.user.should be_a User
|
||||
expect(Post.with_user.first.user).to be_a User
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -56,7 +56,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "doesn't create a new revision when deleted" do
|
||||
post.revisions.count.should == 0
|
||||
expect(post.revisions.count).to eq(0)
|
||||
end
|
||||
|
||||
describe "recovery" do
|
||||
|
@ -66,7 +66,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "doesn't create a new revision when recovered" do
|
||||
post.revisions.count.should == 0
|
||||
expect(post.revisions.count).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -95,11 +95,11 @@ describe Post do
|
|||
PostAction.act(user, post, PostActionType.types[:off_topic])
|
||||
|
||||
post.reload
|
||||
post.is_flagged?.should == true
|
||||
expect(post.is_flagged?).to eq(true)
|
||||
|
||||
PostAction.remove_act(user, post, PostActionType.types[:off_topic])
|
||||
post.reload
|
||||
post.is_flagged?.should == false
|
||||
expect(post.is_flagged?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -114,32 +114,32 @@ describe Post do
|
|||
let(:post_with_two_classy_images) { post_with_body("<img src='http://discourse.org/logo.png' class='classy'> <img src='http://bbc.co.uk/sherlock.jpg' class='classy'>", newuser) }
|
||||
|
||||
it "returns 0 images for an empty post" do
|
||||
Fabricate.build(:post).image_count.should == 0
|
||||
expect(Fabricate.build(:post).image_count).to eq(0)
|
||||
end
|
||||
|
||||
it "finds images from markdown" do
|
||||
post_one_image.image_count.should == 1
|
||||
expect(post_one_image.image_count).to eq(1)
|
||||
end
|
||||
|
||||
it "finds images from HTML" do
|
||||
post_two_images.image_count.should == 2
|
||||
expect(post_two_images.image_count).to eq(2)
|
||||
end
|
||||
|
||||
it "doesn't count avatars as images" do
|
||||
post_with_avatars.image_count.should == 0
|
||||
expect(post_with_avatars.image_count).to eq(0)
|
||||
end
|
||||
|
||||
it "doesn't count favicons as images" do
|
||||
post_with_favicon.image_count.should == 0
|
||||
expect(post_with_favicon.image_count).to eq(0)
|
||||
end
|
||||
|
||||
it "doesn't count thumbnails as images" do
|
||||
post_with_thumbnail.image_count.should == 0
|
||||
expect(post_with_thumbnail.image_count).to eq(0)
|
||||
end
|
||||
|
||||
it "doesn't count whitelisted images" do
|
||||
Post.stubs(:white_listed_image_classes).returns(["classy"])
|
||||
post_with_two_classy_images.image_count.should == 0
|
||||
expect(post_with_two_classy_images.image_count).to eq(0)
|
||||
end
|
||||
|
||||
context "validation" do
|
||||
|
@ -150,26 +150,26 @@ describe Post do
|
|||
|
||||
context 'newuser' do
|
||||
it "allows a new user to post below the limit" do
|
||||
post_one_image.should be_valid
|
||||
expect(post_one_image).to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow more than the maximum" do
|
||||
post_two_images.should_not be_valid
|
||||
expect(post_two_images).not_to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a new user to edit their post to insert an image" do
|
||||
post_no_images.user.trust_level = TrustLevel[0]
|
||||
post_no_images.save
|
||||
-> {
|
||||
expect {
|
||||
post_no_images.revise(post_no_images.user, { raw: post_two_images.raw })
|
||||
post_no_images.reload
|
||||
}.should_not change(post_no_images, :raw)
|
||||
}.not_to change(post_no_images, :raw)
|
||||
end
|
||||
end
|
||||
|
||||
it "allows more images from a not-new account" do
|
||||
post_two_images.user.trust_level = TrustLevel[1]
|
||||
post_two_images.should be_valid
|
||||
expect(post_two_images).to be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -183,11 +183,11 @@ describe Post do
|
|||
let(:post_two_attachments) { post_with_body('<a class="attachment" href="/uploads/default/2/20947092.log">errors.log</a> <a class="attachment" href="/uploads/default/3/283572385.3ds">model.3ds</a>', newuser) }
|
||||
|
||||
it "returns 0 attachments for an empty post" do
|
||||
Fabricate.build(:post).attachment_count.should == 0
|
||||
expect(Fabricate.build(:post).attachment_count).to eq(0)
|
||||
end
|
||||
|
||||
it "finds attachments from HTML" do
|
||||
post_two_attachments.attachment_count.should == 2
|
||||
expect(post_two_attachments.attachment_count).to eq(2)
|
||||
end
|
||||
|
||||
context "validation" do
|
||||
|
@ -198,26 +198,26 @@ describe Post do
|
|||
|
||||
context 'newuser' do
|
||||
it "allows a new user to post below the limit" do
|
||||
post_one_attachment.should be_valid
|
||||
expect(post_one_attachment).to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow more than the maximum" do
|
||||
post_two_attachments.should_not be_valid
|
||||
expect(post_two_attachments).not_to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a new user to edit their post to insert an attachment" do
|
||||
post_no_attachments.user.trust_level = TrustLevel[0]
|
||||
post_no_attachments.save
|
||||
-> {
|
||||
expect {
|
||||
post_no_attachments.revise(post_no_attachments.user, { raw: post_two_attachments.raw })
|
||||
post_no_attachments.reload
|
||||
}.should_not change(post_no_attachments, :raw)
|
||||
}.not_to change(post_no_attachments, :raw)
|
||||
end
|
||||
end
|
||||
|
||||
it "allows more attachments from a not-new account" do
|
||||
post_two_attachments.user.trust_level = TrustLevel[1]
|
||||
post_two_attachments.should be_valid
|
||||
expect(post_two_attachments).to be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -233,40 +233,40 @@ describe Post do
|
|||
|
||||
describe "raw_links" do
|
||||
it "returns a blank collection for a post with no links" do
|
||||
no_links.raw_links.should be_blank
|
||||
expect(no_links.raw_links).to be_blank
|
||||
end
|
||||
|
||||
it "finds a link within markdown" do
|
||||
one_link.raw_links.should == ["http://www.imdb.com/name/nm2225369"]
|
||||
expect(one_link.raw_links).to eq(["http://www.imdb.com/name/nm2225369"])
|
||||
end
|
||||
|
||||
it "can find two links from html" do
|
||||
two_links.raw_links.should == ["http://disneyland.disney.go.com/", "http://reddit.com"]
|
||||
expect(two_links.raw_links).to eq(["http://disneyland.disney.go.com/", "http://reddit.com"])
|
||||
end
|
||||
|
||||
it "can find three links without markup" do
|
||||
three_links.raw_links.should == ["http://discourse.org", "http://discourse.org/another_url", "http://www.imdb.com/name/nm2225369"]
|
||||
expect(three_links.raw_links).to eq(["http://discourse.org", "http://discourse.org/another_url", "http://www.imdb.com/name/nm2225369"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "linked_hosts" do
|
||||
it "returns blank with no links" do
|
||||
no_links.linked_hosts.should be_blank
|
||||
expect(no_links.linked_hosts).to be_blank
|
||||
end
|
||||
|
||||
it "returns the host and a count for links" do
|
||||
two_links.linked_hosts.should == {"disneyland.disney.go.com" => 1, "reddit.com" => 1}
|
||||
expect(two_links.linked_hosts).to eq({"disneyland.disney.go.com" => 1, "reddit.com" => 1})
|
||||
end
|
||||
|
||||
it "it counts properly with more than one link on the same host" do
|
||||
three_links.linked_hosts.should == {"discourse.org" => 1, "www.imdb.com" => 1}
|
||||
expect(three_links.linked_hosts).to eq({"discourse.org" => 1, "www.imdb.com" => 1})
|
||||
end
|
||||
end
|
||||
|
||||
describe "total host usage" do
|
||||
|
||||
it "has none for a regular post" do
|
||||
no_links.total_hosts_usage.should be_blank
|
||||
expect(no_links.total_hosts_usage).to be_blank
|
||||
end
|
||||
|
||||
context "with a previous host" do
|
||||
|
@ -280,7 +280,7 @@ describe Post do
|
|||
end
|
||||
|
||||
it "contains the new post's links, PLUS the previous one" do
|
||||
two_links.total_hosts_usage.should == {'disneyland.disney.go.com' => 2, 'reddit.com' => 1}
|
||||
expect(two_links.total_hosts_usage).to eq({'disneyland.disney.go.com' => 2, 'reddit.com' => 1})
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -298,19 +298,19 @@ describe Post do
|
|||
let(:post_with_mentions) { post_with_body("hello @#{newuser.username} how are you doing?", newuser) }
|
||||
|
||||
it "returns 0 links for an empty post" do
|
||||
Fabricate.build(:post).link_count.should == 0
|
||||
expect(Fabricate.build(:post).link_count).to eq(0)
|
||||
end
|
||||
|
||||
it "returns 0 links for a post with mentions" do
|
||||
post_with_mentions.link_count.should == 0
|
||||
expect(post_with_mentions.link_count).to eq(0)
|
||||
end
|
||||
|
||||
it "finds links from markdown" do
|
||||
post_one_link.link_count.should == 1
|
||||
expect(post_one_link.link_count).to eq(1)
|
||||
end
|
||||
|
||||
it "finds links from HTML" do
|
||||
post_two_links.link_count.should == 2
|
||||
expect(post_two_links.link_count).to eq(2)
|
||||
end
|
||||
|
||||
context "validation" do
|
||||
|
@ -321,17 +321,17 @@ describe Post do
|
|||
|
||||
context 'newuser' do
|
||||
it "returns true when within the amount of links allowed" do
|
||||
post_one_link.should be_valid
|
||||
expect(post_one_link).to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow more links than allowed" do
|
||||
post_two_links.should_not be_valid
|
||||
expect(post_two_links).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "allows multiple images for basic accounts" do
|
||||
post_two_links.user.trust_level = TrustLevel[1]
|
||||
post_two_links.should be_valid
|
||||
expect(post_two_links).to be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -345,37 +345,37 @@ describe Post do
|
|||
|
||||
it "returns an empty array with no matches" do
|
||||
post = Fabricate.build(:post, post_args.merge(raw: "Hello Jake and Finn!"))
|
||||
post.raw_mentions.should == []
|
||||
expect(post.raw_mentions).to eq([])
|
||||
end
|
||||
|
||||
it "returns lowercase unique versions of the mentions" do
|
||||
post = Fabricate.build(:post, post_args.merge(raw: "@Jake @Finn @Jake"))
|
||||
post.raw_mentions.should == ['jake', 'finn']
|
||||
expect(post.raw_mentions).to eq(['jake', 'finn'])
|
||||
end
|
||||
|
||||
it "ignores pre" do
|
||||
post = Fabricate.build(:post, post_args.merge(raw: "<pre>@Jake</pre> @Finn"))
|
||||
post.raw_mentions.should == ['finn']
|
||||
expect(post.raw_mentions).to eq(['finn'])
|
||||
end
|
||||
|
||||
it "catches content between pre tags" do
|
||||
post = Fabricate.build(:post, post_args.merge(raw: "<pre>hello</pre> @Finn <pre></pre>"))
|
||||
post.raw_mentions.should == ['finn']
|
||||
expect(post.raw_mentions).to eq(['finn'])
|
||||
end
|
||||
|
||||
it "ignores code" do
|
||||
post = Fabricate.build(:post, post_args.merge(raw: "@Jake `@Finn`"))
|
||||
post.raw_mentions.should == ['jake']
|
||||
expect(post.raw_mentions).to eq(['jake'])
|
||||
end
|
||||
|
||||
it "ignores quotes" do
|
||||
post = Fabricate.build(:post, post_args.merge(raw: "[quote=\"Evil Trout\"]@Jake[/quote] @Finn"))
|
||||
post.raw_mentions.should == ['finn']
|
||||
expect(post.raw_mentions).to eq(['finn'])
|
||||
end
|
||||
|
||||
it "handles underscore in username" do
|
||||
post = Fabricate.build(:post, post_args.merge(raw: "@Jake @Finn @Jake_Old"))
|
||||
post.raw_mentions.should == ['jake', 'finn', 'jake_old']
|
||||
expect(post.raw_mentions).to eq(['jake', 'finn', 'jake_old'])
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -393,11 +393,11 @@ describe Post do
|
|||
end
|
||||
|
||||
it "allows a new user to have newuser_max_mentions_per_post mentions" do
|
||||
post_with_one_mention.should be_valid
|
||||
expect(post_with_one_mention).to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a new user to have more than newuser_max_mentions_per_post mentions" do
|
||||
post_with_two_mentions.should_not be_valid
|
||||
expect(post_with_two_mentions).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -409,12 +409,12 @@ describe Post do
|
|||
|
||||
it "allows vmax_mentions_per_post mentions" do
|
||||
post_with_one_mention.user.trust_level = TrustLevel[1]
|
||||
post_with_one_mention.should be_valid
|
||||
expect(post_with_one_mention).to be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow to have more than max_mentions_per_post mentions" do
|
||||
post_with_two_mentions.user.trust_level = TrustLevel[1]
|
||||
post_with_two_mentions.should_not be_valid
|
||||
expect(post_with_two_mentions).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -425,11 +425,11 @@ describe Post do
|
|||
|
||||
context 'validation' do
|
||||
it 'validates our default post' do
|
||||
Fabricate.build(:post, post_args).should be_valid
|
||||
expect(Fabricate.build(:post, post_args)).to be_valid
|
||||
end
|
||||
|
||||
it 'treate blank posts as invalid' do
|
||||
Fabricate.build(:post, raw: "").should_not be_valid
|
||||
expect(Fabricate.build(:post, raw: "")).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -439,24 +439,24 @@ describe Post do
|
|||
let(:post) { post_with_body(raw) }
|
||||
|
||||
it "returns a value" do
|
||||
post.raw_hash.should be_present
|
||||
expect(post.raw_hash).to be_present
|
||||
end
|
||||
|
||||
it "returns blank for a nil body" do
|
||||
post.raw = nil
|
||||
post.raw_hash.should be_blank
|
||||
expect(post.raw_hash).to be_blank
|
||||
end
|
||||
|
||||
it "returns the same value for the same raw" do
|
||||
post.raw_hash.should == post_with_body(raw).raw_hash
|
||||
expect(post.raw_hash).to eq(post_with_body(raw).raw_hash)
|
||||
end
|
||||
|
||||
it "returns a different value for a different raw" do
|
||||
post.raw_hash.should_not == post_with_body("something else").raw_hash
|
||||
expect(post.raw_hash).not_to eq(post_with_body("something else").raw_hash)
|
||||
end
|
||||
|
||||
it "returns a different value with different text case" do
|
||||
post.raw_hash.should_not == post_with_body("THIS is OUR TEST post BODy").raw_hash
|
||||
expect(post.raw_hash).not_to eq(post_with_body("THIS is OUR TEST post BODy").raw_hash)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -466,15 +466,15 @@ describe Post do
|
|||
let(:first_version_at) { post.last_version_at }
|
||||
|
||||
it 'has no revision' do
|
||||
post.revisions.size.should == 0
|
||||
first_version_at.should be_present
|
||||
post.revise(post.user, { raw: post.raw }).should == false
|
||||
expect(post.revisions.size).to eq(0)
|
||||
expect(first_version_at).to be_present
|
||||
expect(post.revise(post.user, { raw: post.raw })).to eq(false)
|
||||
end
|
||||
|
||||
describe 'with the same body' do
|
||||
|
||||
it "doesn't change version" do
|
||||
lambda { post.revise(post.user, { raw: post.raw }); post.reload }.should_not change(post, :version)
|
||||
expect { post.revise(post.user, { raw: post.raw }); post.reload }.not_to change(post, :version)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -490,34 +490,34 @@ describe Post do
|
|||
# ninja edit
|
||||
post.revise(post.user, { raw: 'updated body' }, revised_at: post.updated_at + 10.seconds)
|
||||
post.reload
|
||||
post.version.should == 1
|
||||
post.public_version.should == 1
|
||||
post.revisions.size.should == 0
|
||||
post.last_version_at.to_i.should == first_version_at.to_i
|
||||
expect(post.version).to eq(1)
|
||||
expect(post.public_version).to eq(1)
|
||||
expect(post.revisions.size).to eq(0)
|
||||
expect(post.last_version_at.to_i).to eq(first_version_at.to_i)
|
||||
|
||||
# revision much later
|
||||
post.revise(post.user, { raw: 'another updated body' }, revised_at: revised_at)
|
||||
post.reload
|
||||
post.version.should == 2
|
||||
post.public_version.should == 2
|
||||
post.revisions.size.should == 1
|
||||
post.last_version_at.to_i.should == revised_at.to_i
|
||||
expect(post.version).to eq(2)
|
||||
expect(post.public_version).to eq(2)
|
||||
expect(post.revisions.size).to eq(1)
|
||||
expect(post.last_version_at.to_i).to eq(revised_at.to_i)
|
||||
|
||||
# new edit window
|
||||
post.revise(post.user, { raw: 'yet another updated body' }, revised_at: revised_at + 10.seconds)
|
||||
post.reload
|
||||
post.version.should == 2
|
||||
post.public_version.should == 2
|
||||
post.revisions.size.should == 1
|
||||
post.last_version_at.to_i.should == revised_at.to_i
|
||||
expect(post.version).to eq(2)
|
||||
expect(post.public_version).to eq(2)
|
||||
expect(post.revisions.size).to eq(1)
|
||||
expect(post.last_version_at.to_i).to eq(revised_at.to_i)
|
||||
|
||||
# after second window
|
||||
post.revise(post.user, { raw: 'yet another, another updated body' }, revised_at: new_revised_at)
|
||||
post.reload
|
||||
post.version.should == 3
|
||||
post.public_version.should == 3
|
||||
post.revisions.size.should == 2
|
||||
post.last_version_at.to_i.should == new_revised_at.to_i
|
||||
expect(post.version).to eq(3)
|
||||
expect(post.public_version).to eq(3)
|
||||
expect(post.revisions.size).to eq(2)
|
||||
expect(post.last_version_at.to_i).to eq(new_revised_at.to_i)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -536,13 +536,13 @@ describe Post do
|
|||
let!(:result) { post.revise(changed_by, { raw: 'updated body' }) }
|
||||
|
||||
it 'acts correctly' do
|
||||
result.should == true
|
||||
post.raw.should == 'updated body'
|
||||
post.invalidate_oneboxes.should == true
|
||||
post.version.should == 2
|
||||
post.public_version.should == 2
|
||||
post.revisions.size.should == 1
|
||||
post.revisions.first.user.should be_present
|
||||
expect(result).to eq(true)
|
||||
expect(post.raw).to eq('updated body')
|
||||
expect(post.invalidate_oneboxes).to eq(true)
|
||||
expect(post.version).to eq(2)
|
||||
expect(post.public_version).to eq(2)
|
||||
expect(post.revisions.size).to eq(1)
|
||||
expect(post.revisions.first.user).to be_present
|
||||
end
|
||||
|
||||
context 'second poster posts again quickly' do
|
||||
|
@ -552,9 +552,9 @@ describe Post do
|
|||
post.revise(changed_by, { raw: 'yet another updated body' }, revised_at: post.updated_at + 10.seconds)
|
||||
post.reload
|
||||
|
||||
post.version.should == 2
|
||||
post.public_version.should == 2
|
||||
post.revisions.size.should == 1
|
||||
expect(post.version).to eq(2)
|
||||
expect(post.public_version).to eq(2)
|
||||
expect(post.revisions.size).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -569,15 +569,15 @@ describe Post do
|
|||
let(:post) { Fabricate(:post, post_args) }
|
||||
|
||||
it "has correct info set" do
|
||||
post.user_deleted?.should == false
|
||||
post.post_number.should be_present
|
||||
post.excerpt.should be_present
|
||||
post.post_type.should == Post.types[:regular]
|
||||
post.revisions.should be_blank
|
||||
post.cooked.should be_present
|
||||
post.external_id.should be_present
|
||||
post.quote_count.should == 0
|
||||
post.replies.should be_blank
|
||||
expect(post.user_deleted?).to eq(false)
|
||||
expect(post.post_number).to be_present
|
||||
expect(post.excerpt).to be_present
|
||||
expect(post.post_type).to eq(Post.types[:regular])
|
||||
expect(post.revisions).to be_blank
|
||||
expect(post.cooked).to be_present
|
||||
expect(post.external_id).to be_present
|
||||
expect(post.quote_count).to eq(0)
|
||||
expect(post.replies).to be_blank
|
||||
end
|
||||
|
||||
describe 'extract_quoted_post_numbers' do
|
||||
|
@ -588,13 +588,13 @@ describe Post do
|
|||
it "finds the quote when in the same topic" do
|
||||
reply.raw = "[quote=\"EvilTrout, post:#{post.post_number}, topic:#{post.topic_id}\"]hello[/quote]"
|
||||
reply.extract_quoted_post_numbers
|
||||
reply.quoted_post_numbers.should == [post.post_number]
|
||||
expect(reply.quoted_post_numbers).to eq([post.post_number])
|
||||
end
|
||||
|
||||
it "doesn't find the quote in a different topic" do
|
||||
reply.raw = "[quote=\"EvilTrout, post:#{post.post_number}, topic:#{post.topic_id+1}\"]hello[/quote]"
|
||||
reply.extract_quoted_post_numbers
|
||||
reply.quoted_post_numbers.should be_blank
|
||||
expect(reply.quoted_post_numbers).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -608,25 +608,25 @@ describe Post do
|
|||
let!(:reply) { PostCreator.new(other_user, raw: reply_text, topic_id: topic.id, reply_to_post_number: post.post_number ).create }
|
||||
|
||||
it 'has a quote' do
|
||||
reply.quote_count.should == 1
|
||||
expect(reply.quote_count).to eq(1)
|
||||
end
|
||||
|
||||
it 'has a reply to the user of the original user' do
|
||||
reply.reply_to_user.should == post.user
|
||||
expect(reply.reply_to_user).to eq(post.user)
|
||||
end
|
||||
|
||||
it 'increases the reply count of the parent' do
|
||||
post.reload
|
||||
post.reply_count.should == 1
|
||||
expect(post.reply_count).to eq(1)
|
||||
end
|
||||
|
||||
it 'increases the reply count of the topic' do
|
||||
topic.reload
|
||||
topic.reply_count.should == 1
|
||||
expect(topic.reply_count).to eq(1)
|
||||
end
|
||||
|
||||
it 'is the child of the parent post' do
|
||||
post.replies.should == [reply]
|
||||
expect(post.replies).to eq([reply])
|
||||
end
|
||||
|
||||
|
||||
|
@ -634,7 +634,7 @@ describe Post do
|
|||
reply.raw = 'updated raw'
|
||||
reply.save
|
||||
post.reload
|
||||
post.reply_count.should == 1
|
||||
expect(post.reply_count).to eq(1)
|
||||
end
|
||||
|
||||
context 'a multi-quote reply' do
|
||||
|
@ -645,9 +645,9 @@ describe Post do
|
|||
end
|
||||
|
||||
it 'has the correct info set' do
|
||||
multi_reply.quote_count.should == 2
|
||||
post.replies.include?(multi_reply).should == true
|
||||
reply.replies.include?(multi_reply).should == true
|
||||
expect(multi_reply.quote_count).to eq(2)
|
||||
expect(post.replies.include?(multi_reply)).to eq(true)
|
||||
expect(reply.replies.include?(multi_reply)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -662,7 +662,7 @@ describe Post do
|
|||
|
||||
it "returns the OP and posts above the threshold in summary mode" do
|
||||
SiteSetting.stubs(:summary_percent_filter).returns(66)
|
||||
Post.summary.order(:post_number).should == [p1, p2]
|
||||
expect(Post.summary.order(:post_number)).to eq([p1, p2])
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -676,7 +676,7 @@ describe Post do
|
|||
let!(:p3) { Fabricate(:post, post_args) }
|
||||
|
||||
it 'defaults to created order' do
|
||||
Post.regular_order.should == [p1, p2, p3]
|
||||
expect(Post.regular_order).to eq([p1, p2, p3])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -689,24 +689,24 @@ describe Post do
|
|||
let!(:p4) { Fabricate(:post, post_args.merge(reply_to_post_number: p2.post_number)) }
|
||||
|
||||
it "returns the posts in reply to this post" do
|
||||
p4.reply_history.should == [p1, p2]
|
||||
p4.reply_history(1).should == [p2]
|
||||
p3.reply_history.should be_blank
|
||||
p2.reply_history.should == [p1]
|
||||
expect(p4.reply_history).to eq([p1, p2])
|
||||
expect(p4.reply_history(1)).to eq([p2])
|
||||
expect(p3.reply_history).to be_blank
|
||||
expect(p2.reply_history).to eq([p1])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'urls' do
|
||||
it 'no-ops for empty list' do
|
||||
Post.urls([]).should == {}
|
||||
expect(Post.urls([])).to eq({})
|
||||
end
|
||||
|
||||
# integration test -> should move to centralized integration test
|
||||
it 'finds urls for posts presented' do
|
||||
p1 = Fabricate(:post)
|
||||
p2 = Fabricate(:post)
|
||||
Post.urls([p1.id, p2.id]).should == {p1.id => p1.url, p2.id => p2.url}
|
||||
expect(Post.urls([p1.id, p2.id])).to eq({p1.id => p1.url, p2.id => p2.url})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -714,15 +714,15 @@ describe Post do
|
|||
it "adds details" do
|
||||
post = Fabricate.build(:post)
|
||||
post.add_detail("key", "value")
|
||||
post.post_details.size.should == 1
|
||||
post.post_details.first.key.should == "key"
|
||||
post.post_details.first.value.should == "value"
|
||||
expect(post.post_details.size).to eq(1)
|
||||
expect(post.post_details.first.key).to eq("key")
|
||||
expect(post.post_details.first.value).to eq("value")
|
||||
end
|
||||
|
||||
it "can find a post by a detail" do
|
||||
detail = Fabricate(:post_detail)
|
||||
post = detail.post
|
||||
Post.find_by_detail(detail.key, detail.value).id.should == post.id
|
||||
expect(Post.find_by_detail(detail.key, detail.value).id).to eq(post.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -732,21 +732,21 @@ describe Post do
|
|||
it "should add nofollow to links in the post for trust levels below 3" do
|
||||
post.user.trust_level = 2
|
||||
post.save
|
||||
post.cooked.should =~ /nofollow/
|
||||
expect(post.cooked).to match(/nofollow/)
|
||||
end
|
||||
|
||||
it "when tl3_links_no_follow is false, should not add nofollow for trust level 3 and higher" do
|
||||
SiteSetting.stubs(:tl3_links_no_follow).returns(false)
|
||||
post.user.trust_level = 3
|
||||
post.save
|
||||
post.cooked.should_not =~ /nofollow/
|
||||
expect(post.cooked).not_to match(/nofollow/)
|
||||
end
|
||||
|
||||
it "when tl3_links_no_follow is true, should add nofollow for trust level 3 and higher" do
|
||||
SiteSetting.stubs(:tl3_links_no_follow).returns(true)
|
||||
post.user.trust_level = 3
|
||||
post.save
|
||||
post.cooked.should =~ /nofollow/
|
||||
expect(post.cooked).to match(/nofollow/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -763,36 +763,36 @@ describe Post do
|
|||
it "correctly detects host spam" do
|
||||
post = Fabricate(:post, raw: "hello from my site http://www.somesite.com http://#{GlobalSetting.hostname} http://#{RailsMultisite::ConnectionManagement.current_hostname}")
|
||||
|
||||
post.total_hosts_usage.should == {"www.somesite.com" => 1}
|
||||
expect(post.total_hosts_usage).to eq({"www.somesite.com" => 1})
|
||||
post.acting_user.trust_level = 0
|
||||
|
||||
post.has_host_spam?.should == false
|
||||
expect(post.has_host_spam?).to eq(false)
|
||||
|
||||
SiteSetting.newuser_spam_host_threshold = 1
|
||||
|
||||
post.has_host_spam?.should == true
|
||||
expect(post.has_host_spam?).to eq(true)
|
||||
|
||||
SiteSetting.white_listed_spam_host_domains = "bla.com|boo.com | somesite.com "
|
||||
post.has_host_spam?.should == false
|
||||
expect(post.has_host_spam?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
it "has custom fields" do
|
||||
post = Fabricate(:post)
|
||||
post.custom_fields["a"].should == nil
|
||||
expect(post.custom_fields["a"]).to eq(nil)
|
||||
|
||||
post.custom_fields["Tommy"] = "Hanks"
|
||||
post.custom_fields["Vincent"] = "Vega"
|
||||
post.save
|
||||
|
||||
post = Post.find(post.id)
|
||||
post.custom_fields.should == {"Tommy" => "Hanks", "Vincent" => "Vega"}
|
||||
expect(post.custom_fields).to eq({"Tommy" => "Hanks", "Vincent" => "Vega"})
|
||||
end
|
||||
|
||||
describe "#rebake!" do
|
||||
it "will rebake a post correctly" do
|
||||
post = create_post
|
||||
post.baked_at.should_not == nil
|
||||
expect(post.baked_at).not_to eq(nil)
|
||||
first_baked = post.baked_at
|
||||
first_cooked = post.cooked
|
||||
|
||||
|
@ -803,9 +803,9 @@ describe Post do
|
|||
|
||||
result = post.rebake!
|
||||
|
||||
post.baked_at.should_not == first_baked
|
||||
post.cooked.should == first_cooked
|
||||
result.should == true
|
||||
expect(post.baked_at).not_to eq(first_baked)
|
||||
expect(post.cooked).to eq(first_cooked)
|
||||
expect(result).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -816,12 +816,12 @@ describe Post do
|
|||
Post.rebake_old(100)
|
||||
|
||||
post.reload
|
||||
post.baked_at.should be > 1.day.ago
|
||||
expect(post.baked_at).to be > 1.day.ago
|
||||
|
||||
baked = post.baked_at
|
||||
Post.rebake_old(100)
|
||||
post.reload
|
||||
post.baked_at.should == baked
|
||||
expect(post.baked_at).to eq(baked)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -835,7 +835,7 @@ describe Post do
|
|||
post.update_columns(hidden: true, hidden_at: Time.now, hidden_reason_id: 1)
|
||||
post.reload
|
||||
|
||||
post.hidden.should == true
|
||||
expect(post.hidden).to eq(true)
|
||||
|
||||
post.expects(:publish_change_to_clients!).with(:acted)
|
||||
|
||||
|
@ -844,8 +844,8 @@ describe Post do
|
|||
post.reload
|
||||
hidden_topic.reload
|
||||
|
||||
post.hidden.should == false
|
||||
hidden_topic.visible.should == true
|
||||
expect(post.hidden).to eq(false)
|
||||
expect(hidden_topic.visible).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -862,8 +862,8 @@ describe Post do
|
|||
second_post.reload
|
||||
hidden_topic.reload
|
||||
|
||||
second_post.hidden.should == false
|
||||
hidden_topic.visible.should == false
|
||||
expect(second_post.hidden).to eq(false)
|
||||
expect(hidden_topic.visible).to eq(false)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,8 +7,8 @@ describe QuotedPost do
|
|||
raw: "[quote=\"#{post1.user.username}, post: 1, topic:#{post1.topic_id}\"]\ntest\n[/quote]\nthis is a test post",
|
||||
reply_to_post_number: 1)
|
||||
|
||||
QuotedPost.find_by(post_id: post2.id, quoted_post_id: post1.id).should_not == nil
|
||||
post2.reply_quoted.should == true
|
||||
expect(QuotedPost.find_by(post_id: post2.id, quoted_post_id: post1.id)).not_to eq(nil)
|
||||
expect(post2.reply_quoted).to eq(true)
|
||||
end
|
||||
|
||||
it 'correctly handles deltas' do
|
||||
|
@ -22,9 +22,9 @@ HTML
|
|||
QuotedPost.create!(post_id: post2.id, quoted_post_id: 999)
|
||||
|
||||
QuotedPost.extract_from(post2)
|
||||
QuotedPost.where(post_id: post2.id).count.should == 1
|
||||
QuotedPost.find_by(post_id: post2.id, quoted_post_id: post1.id).should_not == nil
|
||||
expect(QuotedPost.where(post_id: post2.id).count).to eq(1)
|
||||
expect(QuotedPost.find_by(post_id: post2.id, quoted_post_id: post1.id)).not_to eq(nil)
|
||||
|
||||
post2.reply_quoted.should == false
|
||||
expect(post2.reply_quoted).to eq(false)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,11 +21,11 @@ describe Report do
|
|||
end
|
||||
|
||||
it "returns a report with data" do
|
||||
report.data.should be_present
|
||||
expect(report.data).to be_present
|
||||
end
|
||||
|
||||
it "returns today's visit" do
|
||||
report.data.select { |v| v[:x].today? }.should be_present
|
||||
expect(report.data.select { |v| v[:x].today? }).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -76,15 +76,15 @@ describe Report do
|
|||
end
|
||||
|
||||
it "returns today's data" do
|
||||
report.data.select { |v| v[:x].today? }.should be_present
|
||||
expect(report.data.select { |v| v[:x].today? }).to be_present
|
||||
end
|
||||
|
||||
it 'returns total data' do
|
||||
report.total.should == 7
|
||||
expect(report.total).to eq 7
|
||||
end
|
||||
|
||||
it "returns previous 30 day's data" do
|
||||
report.prev30Days.should == 1
|
||||
expect(report.prev30Days).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -93,7 +93,7 @@ describe Report do
|
|||
describe 'private messages' do
|
||||
let(:report) { Report.find('user_to_user_private_messages') }
|
||||
|
||||
it 'topic report should not include private messages' do
|
||||
it 'topic report).to not include private messages' do
|
||||
Fabricate(:private_message_topic, created_at: 1.hour.ago)
|
||||
Fabricate(:topic, created_at: 1.hour.ago)
|
||||
report = Report.find('topics')
|
||||
|
@ -101,24 +101,24 @@ describe Report do
|
|||
expect(report.total).to eq(1)
|
||||
end
|
||||
|
||||
it 'post report should not include private messages' do
|
||||
it 'post report).to not include private messages' do
|
||||
Fabricate(:private_message_post, created_at: 1.hour.ago)
|
||||
Fabricate(:post)
|
||||
report = Report.find('posts')
|
||||
report.data[0][:y].should == 1
|
||||
report.total.should == 1
|
||||
expect(report.data[0][:y]).to eq 1
|
||||
expect(report.total).to eq 1
|
||||
end
|
||||
|
||||
context 'no private messages' do
|
||||
it 'returns an empty report' do
|
||||
report.data.should be_blank
|
||||
expect(report.data).to be_blank
|
||||
end
|
||||
|
||||
context 'some public posts' do
|
||||
it 'returns an empty report' do
|
||||
Fabricate(:post); Fabricate(:post)
|
||||
report.data.should be_blank
|
||||
report.total.should == 0
|
||||
expect(report.data).to be_blank
|
||||
expect(report.total).to eq 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -131,9 +131,9 @@ describe Report do
|
|||
end
|
||||
|
||||
it 'returns correct data' do
|
||||
report.data[0][:y].should == 1
|
||||
report.data[1][:y].should == 2
|
||||
report.total.should == 3
|
||||
expect(report.data[0][:y]).to eq 1
|
||||
expect(report.data[1][:y]).to eq 2
|
||||
expect(report.total).to eq 3
|
||||
end
|
||||
|
||||
context 'and some public posts' do
|
||||
|
@ -142,9 +142,9 @@ describe Report do
|
|||
end
|
||||
|
||||
it 'returns correct data' do
|
||||
report.data[0][:y].should == 1
|
||||
report.data[1][:y].should == 2
|
||||
report.total.should == 3
|
||||
expect(report.data[0][:y]).to eq 1
|
||||
expect(report.data[1][:y]).to eq 2
|
||||
expect(report.total).to eq 3
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -155,7 +155,7 @@ describe Report do
|
|||
|
||||
context "no users" do
|
||||
it "returns an empty report" do
|
||||
report.data.should be_blank
|
||||
expect(report.data).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -167,11 +167,12 @@ describe Report do
|
|||
end
|
||||
|
||||
it "returns a report with data" do
|
||||
report.data.should be_present
|
||||
report.data.find {|d| d[:x] == TrustLevel[0]}[:y].should == 3
|
||||
report.data.find {|d| d[:x] == TrustLevel[2]}[:y].should == 2
|
||||
report.data.find {|d| d[:x] == TrustLevel[4]}[:y].should == 1
|
||||
expect(report.data).to be_present
|
||||
expect(report.data.find {|d| d[:x] == TrustLevel[0]}[:y]).to eq 3
|
||||
expect(report.data.find {|d| d[:x] == TrustLevel[2]}[:y]).to eq 2
|
||||
expect(report.data.find {|d| d[:x] == TrustLevel[4]}[:y]).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,13 +13,13 @@ describe RTL do
|
|||
before { user.stubs(:locale).returns('he') }
|
||||
|
||||
it 'returns rtl class' do
|
||||
RTL.new(user).css_class.should == 'rtl'
|
||||
expect(RTL.new(user).css_class).to eq('rtl')
|
||||
end
|
||||
end
|
||||
|
||||
context 'user locale is not RTL' do
|
||||
it 'returns empty class' do
|
||||
RTL.new(user).css_class.should == ''
|
||||
expect(RTL.new(user).css_class).to eq('')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -32,7 +32,7 @@ describe RTL do
|
|||
before { SiteSetting.stubs(:default_locale).returns('he') }
|
||||
|
||||
it 'returns rtl class' do
|
||||
RTL.new(user).css_class.should == 'rtl'
|
||||
expect(RTL.new(user).css_class).to eq('rtl')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,7 +43,7 @@ describe RTL do
|
|||
before { user.stubs(:locale).returns('he') }
|
||||
|
||||
it 'returns empty class' do
|
||||
RTL.new(user).css_class.should == ''
|
||||
expect(RTL.new(user).css_class).to eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,18 +7,18 @@ describe ScreenedEmail do
|
|||
|
||||
describe "new record" do
|
||||
it "sets a default action_type" do
|
||||
ScreenedEmail.create(email: email).action_type.should == ScreenedEmail.actions[:block]
|
||||
expect(ScreenedEmail.create(email: email).action_type).to eq(ScreenedEmail.actions[:block])
|
||||
end
|
||||
|
||||
it "last_match_at is null" do
|
||||
# If we manually load the table with some emails, we can see whether those emails
|
||||
# have ever been blocked by looking at last_match_at.
|
||||
ScreenedEmail.create(email: email).last_match_at.should == nil
|
||||
expect(ScreenedEmail.create(email: email).last_match_at).to eq(nil)
|
||||
end
|
||||
|
||||
it "downcases the email" do
|
||||
s = ScreenedEmail.create(email: 'SPAMZ@EXAMPLE.COM')
|
||||
s.email.should == 'spamz@example.com'
|
||||
expect(s.email).to eq('spamz@example.com')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -26,16 +26,16 @@ describe ScreenedEmail do
|
|||
context 'email is not being blocked' do
|
||||
it 'creates a new record with default action of :block' do
|
||||
record = ScreenedEmail.block(email)
|
||||
record.should_not be_new_record
|
||||
record.email.should == email
|
||||
record.action_type.should == ScreenedEmail.actions[:block]
|
||||
expect(record).not_to be_new_record
|
||||
expect(record.email).to eq(email)
|
||||
expect(record.action_type).to eq(ScreenedEmail.actions[:block])
|
||||
end
|
||||
|
||||
it 'lets action_type be overriden' do
|
||||
record = ScreenedEmail.block(email, action_type: ScreenedEmail.actions[:do_nothing])
|
||||
record.should_not be_new_record
|
||||
record.email.should == email
|
||||
record.action_type.should == ScreenedEmail.actions[:do_nothing]
|
||||
expect(record).not_to be_new_record
|
||||
expect(record.email).to eq(email)
|
||||
expect(record.action_type).to eq(ScreenedEmail.actions[:do_nothing])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -47,7 +47,7 @@ describe ScreenedEmail do
|
|||
end
|
||||
|
||||
it "returns the existing record" do
|
||||
ScreenedEmail.block(email).should == existing
|
||||
expect(ScreenedEmail.block(email)).to eq(existing)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -56,44 +56,44 @@ describe ScreenedEmail do
|
|||
subject { ScreenedEmail.should_block?(email) }
|
||||
|
||||
it "returns false if a record with the email doesn't exist" do
|
||||
subject.should == false
|
||||
expect(subject).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true when there is a record with the email" do
|
||||
ScreenedEmail.should_block?(email).should == false
|
||||
expect(ScreenedEmail.should_block?(email)).to eq(false)
|
||||
ScreenedEmail.create(email: email).save
|
||||
ScreenedEmail.should_block?(email).should == true
|
||||
expect(ScreenedEmail.should_block?(email)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when there is a record with a similar email" do
|
||||
ScreenedEmail.should_block?(email).should == false
|
||||
expect(ScreenedEmail.should_block?(email)).to eq(false)
|
||||
ScreenedEmail.create(email: similar_email).save
|
||||
ScreenedEmail.should_block?(email).should == true
|
||||
expect(ScreenedEmail.should_block?(email)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when it's same email, but all caps" do
|
||||
ScreenedEmail.create(email: email).save
|
||||
ScreenedEmail.should_block?(email.upcase).should == true
|
||||
expect(ScreenedEmail.should_block?(email.upcase)).to eq(true)
|
||||
end
|
||||
|
||||
shared_examples "when a ScreenedEmail record matches" do
|
||||
it "updates statistics" do
|
||||
Timecop.freeze(Time.zone.now) do
|
||||
expect { subject }.to change { screened_email.reload.match_count }.by(1)
|
||||
screened_email.last_match_at.should be_within_one_second_of(Time.zone.now)
|
||||
expect(screened_email.last_match_at).to be_within_one_second_of(Time.zone.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "action_type is :block" do
|
||||
let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: ScreenedEmail.actions[:block]) }
|
||||
it { should == true }
|
||||
it { is_expected.to eq(true) }
|
||||
include_examples "when a ScreenedEmail record matches"
|
||||
end
|
||||
|
||||
context "action_type is :do_nothing" do
|
||||
let!(:screened_email) { Fabricate(:screened_email, email: email, action_type: ScreenedEmail.actions[:do_nothing]) }
|
||||
it { should == false }
|
||||
it { is_expected.to eq(false) }
|
||||
include_examples "when a ScreenedEmail record matches"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,18 +6,18 @@ describe ScreenedIpAddress do
|
|||
|
||||
describe 'new record' do
|
||||
it 'sets a default action_type' do
|
||||
described_class.create(valid_params).action_type.should == described_class.actions[:block]
|
||||
expect(described_class.create(valid_params).action_type).to eq(described_class.actions[:block])
|
||||
end
|
||||
|
||||
it 'sets an error when ip_address is invalid' do
|
||||
described_class.create(valid_params.merge(ip_address: '99.99.99')).errors[:ip_address].should be_present
|
||||
expect(described_class.create(valid_params.merge(ip_address: '99.99.99')).errors[:ip_address]).to be_present
|
||||
end
|
||||
|
||||
it 'can set action_type using the action_name virtual attribute' do
|
||||
described_class.new(valid_params.merge(action_name: :do_nothing)).action_type.should == described_class.actions[:do_nothing]
|
||||
described_class.new(valid_params.merge(action_name: :block)).action_type.should == described_class.actions[:block]
|
||||
described_class.new(valid_params.merge(action_name: 'do_nothing')).action_type.should == described_class.actions[:do_nothing]
|
||||
described_class.new(valid_params.merge(action_name: 'block')).action_type.should == described_class.actions[:block]
|
||||
expect(described_class.new(valid_params.merge(action_name: :do_nothing)).action_type).to eq(described_class.actions[:do_nothing])
|
||||
expect(described_class.new(valid_params.merge(action_name: :block)).action_type).to eq(described_class.actions[:block])
|
||||
expect(described_class.new(valid_params.merge(action_name: 'do_nothing')).action_type).to eq(described_class.actions[:do_nothing])
|
||||
expect(described_class.new(valid_params.merge(action_name: 'block')).action_type).to eq(described_class.actions[:block])
|
||||
end
|
||||
|
||||
it 'raises a useful exception when action is invalid' do
|
||||
|
@ -35,15 +35,15 @@ describe ScreenedIpAddress do
|
|||
|
||||
describe "ip_address_with_mask" do
|
||||
it "returns nil when ip_address is nil" do
|
||||
described_class.new.ip_address_with_mask.should == nil
|
||||
expect(described_class.new.ip_address_with_mask).to eq(nil)
|
||||
end
|
||||
|
||||
it "returns ip_address without mask if there is no mask" do
|
||||
described_class.new(ip_address: "123.123.23.22").ip_address_with_mask.should == "123.123.23.22"
|
||||
expect(described_class.new(ip_address: "123.123.23.22").ip_address_with_mask).to eq("123.123.23.22")
|
||||
end
|
||||
|
||||
it "returns ip_address with mask" do
|
||||
described_class.new(ip_address: "123.12.0.0/16").ip_address_with_mask.should == "123.12.0.0/16"
|
||||
expect(described_class.new(ip_address: "123.12.0.0/16").ip_address_with_mask).to eq("123.12.0.0/16")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -52,14 +52,14 @@ describe ScreenedIpAddress do
|
|||
|
||||
def test_good_value(arg, expected)
|
||||
record.ip_address = arg
|
||||
record.ip_address_with_mask.should == expected
|
||||
expect(record.ip_address_with_mask).to eq(expected)
|
||||
end
|
||||
|
||||
def test_bad_value(arg)
|
||||
r = described_class.new
|
||||
r.ip_address = arg
|
||||
r.should_not be_valid
|
||||
r.errors[:ip_address].should be_present
|
||||
expect(r).not_to be_valid
|
||||
expect(r.errors[:ip_address]).to be_present
|
||||
end
|
||||
|
||||
it "handles valid ip addresses" do
|
||||
|
@ -95,14 +95,14 @@ describe ScreenedIpAddress do
|
|||
context 'ip_address is not being watched' do
|
||||
it 'should create a new record' do
|
||||
record = described_class.watch(ip_address)
|
||||
record.should_not be_new_record
|
||||
record.action_type.should == described_class.actions[:block]
|
||||
expect(record).not_to be_new_record
|
||||
expect(record.action_type).to eq(described_class.actions[:block])
|
||||
end
|
||||
|
||||
it 'lets action_type be overridden' do
|
||||
record = described_class.watch(ip_address, action_type: described_class.actions[:do_nothing])
|
||||
record.should_not be_new_record
|
||||
record.action_type.should == described_class.actions[:do_nothing]
|
||||
expect(record).not_to be_new_record
|
||||
expect(record.action_type).to eq(described_class.actions[:do_nothing])
|
||||
end
|
||||
|
||||
it "a record with subnet mask exists, but doesn't match" do
|
||||
|
@ -123,7 +123,7 @@ describe ScreenedIpAddress do
|
|||
end
|
||||
|
||||
it 'returns the existing record' do
|
||||
described_class.watch(ip_address_arg).should == existing
|
||||
expect(described_class.watch(ip_address_arg)).to eq(existing)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -149,91 +149,91 @@ describe ScreenedIpAddress do
|
|||
end
|
||||
|
||||
it "doesn't block 10.0.0.0/8" do
|
||||
described_class.watch('10.0.0.0').action_type.should == described_class.actions[:do_nothing]
|
||||
described_class.watch('10.0.0.1').action_type.should == described_class.actions[:do_nothing]
|
||||
described_class.watch('10.10.125.111').action_type.should == described_class.actions[:do_nothing]
|
||||
expect(described_class.watch('10.0.0.0').action_type).to eq(described_class.actions[:do_nothing])
|
||||
expect(described_class.watch('10.0.0.1').action_type).to eq(described_class.actions[:do_nothing])
|
||||
expect(described_class.watch('10.10.125.111').action_type).to eq(described_class.actions[:do_nothing])
|
||||
end
|
||||
|
||||
it "doesn't block 192.168.0.0/16" do
|
||||
described_class.watch('192.168.0.5').action_type.should == described_class.actions[:do_nothing]
|
||||
described_class.watch('192.168.10.1').action_type.should == described_class.actions[:do_nothing]
|
||||
expect(described_class.watch('192.168.0.5').action_type).to eq(described_class.actions[:do_nothing])
|
||||
expect(described_class.watch('192.168.10.1').action_type).to eq(described_class.actions[:do_nothing])
|
||||
end
|
||||
|
||||
it "doesn't block 127.0.0.0/8" do
|
||||
described_class.watch('127.0.0.1').action_type.should == described_class.actions[:do_nothing]
|
||||
expect(described_class.watch('127.0.0.1').action_type).to eq(described_class.actions[:do_nothing])
|
||||
end
|
||||
|
||||
it "doesn't block fc00::/7 addresses (IPv6)" do
|
||||
described_class.watch('fd12:db8::ff00:42:8329').action_type.should == described_class.actions[:do_nothing]
|
||||
expect(described_class.watch('fd12:db8::ff00:42:8329').action_type).to eq(described_class.actions[:do_nothing])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#should_block?' do
|
||||
it 'returns false when record does not exist' do
|
||||
described_class.should_block?(ip_address).should eq(false)
|
||||
expect(described_class.should_block?(ip_address)).to eq(false)
|
||||
end
|
||||
|
||||
it 'returns false when no record matches' do
|
||||
Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:block])
|
||||
described_class.should_block?('222.12.12.12').should eq(false)
|
||||
expect(described_class.should_block?('222.12.12.12')).to eq(false)
|
||||
end
|
||||
|
||||
context 'IPv4' do
|
||||
it 'returns false when when record matches and action is :do_nothing' do
|
||||
Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:do_nothing])
|
||||
described_class.should_block?('111.234.23.11').should eq(false)
|
||||
expect(described_class.should_block?('111.234.23.11')).to eq(false)
|
||||
end
|
||||
|
||||
it 'returns true when when record matches and action is :block' do
|
||||
Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:block])
|
||||
described_class.should_block?('111.234.23.11').should eq(true)
|
||||
expect(described_class.should_block?('111.234.23.11')).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'IPv6' do
|
||||
it 'returns false when when record matches and action is :do_nothing' do
|
||||
Fabricate(:screened_ip_address, ip_address: '2001:db8::ff00:42:8329', action_type: described_class.actions[:do_nothing])
|
||||
described_class.should_block?('2001:db8::ff00:42:8329').should eq(false)
|
||||
expect(described_class.should_block?('2001:db8::ff00:42:8329')).to eq(false)
|
||||
end
|
||||
|
||||
it 'returns true when when record matches and action is :block' do
|
||||
Fabricate(:screened_ip_address, ip_address: '2001:db8::ff00:42:8329', action_type: described_class.actions[:block])
|
||||
described_class.should_block?('2001:db8::ff00:42:8329').should eq(true)
|
||||
expect(described_class.should_block?('2001:db8::ff00:42:8329')).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#is_whitelisted?' do
|
||||
it 'returns false when record does not exist' do
|
||||
described_class.is_whitelisted?(ip_address).should eq(false)
|
||||
expect(described_class.is_whitelisted?(ip_address)).to eq(false)
|
||||
end
|
||||
|
||||
it 'returns false when no record matches' do
|
||||
Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:do_nothing])
|
||||
described_class.is_whitelisted?('222.12.12.12').should eq(false)
|
||||
expect(described_class.is_whitelisted?('222.12.12.12')).to eq(false)
|
||||
end
|
||||
|
||||
context 'IPv4' do
|
||||
it 'returns true when when record matches and action is :do_nothing' do
|
||||
Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:do_nothing])
|
||||
described_class.is_whitelisted?('111.234.23.11').should eq(true)
|
||||
expect(described_class.is_whitelisted?('111.234.23.11')).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns false when when record matches and action is :block' do
|
||||
Fabricate(:screened_ip_address, ip_address: '111.234.23.11', action_type: described_class.actions[:block])
|
||||
described_class.is_whitelisted?('111.234.23.11').should eq(false)
|
||||
expect(described_class.is_whitelisted?('111.234.23.11')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'IPv6' do
|
||||
it 'returns true when when record matches and action is :do_nothing' do
|
||||
Fabricate(:screened_ip_address, ip_address: '2001:db8::ff00:42:8329', action_type: described_class.actions[:do_nothing])
|
||||
described_class.is_whitelisted?('2001:db8::ff00:42:8329').should eq(true)
|
||||
expect(described_class.is_whitelisted?('2001:db8::ff00:42:8329')).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns false when when record matches and action is :block' do
|
||||
Fabricate(:screened_ip_address, ip_address: '2001:db8::ff00:42:8329', action_type: described_class.actions[:block])
|
||||
described_class.is_whitelisted?('2001:db8::ff00:42:8329').should eq(false)
|
||||
expect(described_class.is_whitelisted?('2001:db8::ff00:42:8329')).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -241,19 +241,19 @@ describe ScreenedIpAddress do
|
|||
describe '#block_login?' do
|
||||
context 'no allow_admin records exist' do
|
||||
it "returns false when user is nil" do
|
||||
described_class.block_login?(nil, '123.12.12.12').should == false
|
||||
expect(described_class.block_login?(nil, '123.12.12.12')).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false for non-admin user" do
|
||||
described_class.block_login?(Fabricate.build(:user), '123.12.12.12').should == false
|
||||
expect(described_class.block_login?(Fabricate.build(:user), '123.12.12.12')).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false for admin user" do
|
||||
described_class.block_login?(Fabricate.build(:admin), '123.12.12.12').should == false
|
||||
expect(described_class.block_login?(Fabricate.build(:admin), '123.12.12.12')).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false for admin user and ip_address arg is nil" do
|
||||
described_class.block_login?(Fabricate.build(:admin), nil).should == false
|
||||
expect(described_class.block_login?(Fabricate.build(:admin), nil)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -264,23 +264,23 @@ describe ScreenedIpAddress do
|
|||
end
|
||||
|
||||
it "returns false when user is nil" do
|
||||
described_class.block_login?(nil, @permitted_ip_address).should == false
|
||||
expect(described_class.block_login?(nil, @permitted_ip_address)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false for an admin user at the allowed ip address" do
|
||||
described_class.block_login?(Fabricate.build(:admin), @permitted_ip_address).should == false
|
||||
expect(described_class.block_login?(Fabricate.build(:admin), @permitted_ip_address)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true for an admin user at another ip address" do
|
||||
described_class.block_login?(Fabricate.build(:admin), '123.12.12.12').should == true
|
||||
expect(described_class.block_login?(Fabricate.build(:admin), '123.12.12.12')).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false for regular user at allowed ip address" do
|
||||
described_class.block_login?(Fabricate.build(:user), @permitted_ip_address).should == false
|
||||
expect(described_class.block_login?(Fabricate.build(:user), @permitted_ip_address)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns false for regular user at another ip address" do
|
||||
described_class.block_login?(Fabricate.build(:user), '123.12.12.12').should == false
|
||||
expect(described_class.block_login?(Fabricate.build(:user), '123.12.12.12')).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,11 +9,11 @@ describe ScreenedUrl do
|
|||
|
||||
describe "new record" do
|
||||
it "sets a default action_type" do
|
||||
described_class.create(valid_params).action_type.should == described_class.actions[:do_nothing]
|
||||
expect(described_class.create(valid_params).action_type).to eq(described_class.actions[:do_nothing])
|
||||
end
|
||||
|
||||
it "last_match_at is null" do
|
||||
described_class.create(valid_params).last_match_at.should == nil
|
||||
expect(described_class.create(valid_params).last_match_at).to eq(nil)
|
||||
end
|
||||
|
||||
it "normalizes the url and domain" do
|
||||
|
@ -30,46 +30,46 @@ describe ScreenedUrl do
|
|||
['http://', 'HTTP://', 'https://', 'HTTPS://'].each do |prefix|
|
||||
it "strips #{prefix}" do
|
||||
@params = valid_params.merge(url: url.gsub('http://', prefix))
|
||||
subject.url.should == url.gsub('http://', '')
|
||||
expect(subject.url).to eq(url.gsub('http://', ''))
|
||||
end
|
||||
end
|
||||
|
||||
it "strips trailing slash" do
|
||||
@params = valid_params.merge(url: 'silverbullet.in/')
|
||||
subject.url.should == 'silverbullet.in'
|
||||
expect(subject.url).to eq('silverbullet.in')
|
||||
end
|
||||
|
||||
it "strips trailing slashes" do
|
||||
@params = valid_params.merge(url: 'silverbullet.in/buy///')
|
||||
subject.url.should == 'silverbullet.in/buy'
|
||||
expect(subject.url).to eq('silverbullet.in/buy')
|
||||
end
|
||||
|
||||
it "downcases domains" do
|
||||
record1 = described_class.new(valid_params.merge(domain: 'DuB30.com', url: 'DuB30.com/Gems/Gems-of-Power'))
|
||||
record1.normalize
|
||||
record1.domain.should == 'dub30.com'
|
||||
record1.url.should == 'dub30.com/Gems/Gems-of-Power'
|
||||
record1.should be_valid
|
||||
expect(record1.domain).to eq('dub30.com')
|
||||
expect(record1.url).to eq('dub30.com/Gems/Gems-of-Power')
|
||||
expect(record1).to be_valid
|
||||
|
||||
record2 = described_class.new(valid_params.merge(domain: 'DuB30.com', url: 'DuB30.com'))
|
||||
record2.normalize
|
||||
record2.domain.should == 'dub30.com'
|
||||
record2.url.should == 'dub30.com'
|
||||
record2.should be_valid
|
||||
expect(record2.domain).to eq('dub30.com')
|
||||
expect(record2.url).to eq('dub30.com')
|
||||
expect(record2).to be_valid
|
||||
end
|
||||
|
||||
it "strips www. from domains" do
|
||||
record1 = described_class.new(valid_params.merge(domain: 'www.DuB30.com', url: 'www.DuB30.com/Gems/Gems-of-Power'))
|
||||
record1.normalize
|
||||
record1.domain.should == 'dub30.com'
|
||||
expect(record1.domain).to eq('dub30.com')
|
||||
|
||||
record2 = described_class.new(valid_params.merge(domain: 'WWW.DuB30.cOM', url: 'WWW.DuB30.com/Gems/Gems-of-Power'))
|
||||
record2.normalize
|
||||
record2.domain.should == 'dub30.com'
|
||||
expect(record2.domain).to eq('dub30.com')
|
||||
|
||||
record3 = described_class.new(valid_params.merge(domain: 'www.trolls.spammers.com', url: 'WWW.DuB30.com/Gems/Gems-of-Power'))
|
||||
record3.normalize
|
||||
record3.domain.should == 'trolls.spammers.com'
|
||||
expect(record3.domain).to eq('trolls.spammers.com')
|
||||
end
|
||||
|
||||
it "doesn't modify the url argument" do
|
||||
|
@ -88,17 +88,17 @@ describe ScreenedUrl do
|
|||
|
||||
describe 'find_match' do
|
||||
it 'returns nil when there is no match' do
|
||||
described_class.find_match('http://spamspot.com/buy/it').should == nil
|
||||
expect(described_class.find_match('http://spamspot.com/buy/it')).to eq(nil)
|
||||
end
|
||||
|
||||
it 'returns the record when there is an exact match' do
|
||||
match = described_class.create(valid_params)
|
||||
described_class.find_match(valid_params[:url]).should == match
|
||||
expect(described_class.find_match(valid_params[:url])).to eq(match)
|
||||
end
|
||||
|
||||
it 'ignores case of the domain' do
|
||||
match = described_class.create(valid_params.merge(url: 'spamexchange.com/Good/Things'))
|
||||
described_class.find_match("http://SPAMExchange.com/Good/Things").should == match
|
||||
expect(described_class.find_match("http://SPAMExchange.com/Good/Things")).to eq(match)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -106,14 +106,14 @@ describe ScreenedUrl do
|
|||
context 'url is not being blocked' do
|
||||
it 'creates a new record with default action of :do_nothing' do
|
||||
record = described_class.watch(url, domain)
|
||||
record.should_not be_new_record
|
||||
record.action_type.should == described_class.actions[:do_nothing]
|
||||
expect(record).not_to be_new_record
|
||||
expect(record.action_type).to eq(described_class.actions[:do_nothing])
|
||||
end
|
||||
|
||||
it 'lets action_type be overriden' do
|
||||
record = described_class.watch(url, domain, action_type: described_class.actions[:block])
|
||||
record.should_not be_new_record
|
||||
record.action_type.should == described_class.actions[:block]
|
||||
expect(record).not_to be_new_record
|
||||
expect(record.action_type).to eq(described_class.actions[:block])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -125,7 +125,7 @@ describe ScreenedUrl do
|
|||
end
|
||||
|
||||
it "returns the existing record" do
|
||||
described_class.watch(url, domain).should == existing
|
||||
expect(described_class.watch(url, domain)).to eq(existing)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,12 +13,12 @@ describe SearchObserver do
|
|||
it 'correctly indexes chinese' do
|
||||
SiteSetting.default_locale = 'zh_CN'
|
||||
data = "你好世界"
|
||||
data.split(" ").length.should == 1
|
||||
expect(data.split(" ").length).to eq(1)
|
||||
|
||||
SearchObserver.update_posts_index(99, "你好世界", "", nil)
|
||||
|
||||
row = get_row(99)
|
||||
row.raw_data.split(' ').length.should == 2
|
||||
expect(row.raw_data.split(' ').length).to eq(2)
|
||||
end
|
||||
|
||||
it 'correctly indexes a post' do
|
||||
|
@ -28,13 +28,13 @@ describe SearchObserver do
|
|||
|
||||
row = get_row(99)
|
||||
|
||||
row.raw_data.should == "This is a test"
|
||||
row.locale.should == "en"
|
||||
expect(row.raw_data).to eq("This is a test")
|
||||
expect(row.locale).to eq("en")
|
||||
|
||||
SearchObserver.update_posts_index(99, "tester", "", nil)
|
||||
|
||||
row = get_row(99)
|
||||
|
||||
row.raw_data.should == "tester"
|
||||
expect(row.raw_data).to eq("tester")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ describe SiteCustomization 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
|
||||
expect(s.key).not_to eq(nil)
|
||||
end
|
||||
|
||||
it 'can enable more than one style at once' do
|
||||
|
@ -38,25 +38,25 @@ describe SiteCustomization do
|
|||
stylesheet: 'p{width: 1px;}'
|
||||
)
|
||||
|
||||
SiteCustomization.custom_header.should == "Hello\nWorld"
|
||||
SiteCustomization.custom_header(nil, :mobile).should == "hi"
|
||||
SiteCustomization.custom_footer(nil, :mobile).should == "mfooter"
|
||||
SiteCustomization.custom_footer.should == "footer"
|
||||
expect(SiteCustomization.custom_header).to eq("Hello\nWorld")
|
||||
expect(SiteCustomization.custom_header(nil, :mobile)).to eq("hi")
|
||||
expect(SiteCustomization.custom_footer(nil, :mobile)).to eq("mfooter")
|
||||
expect(SiteCustomization.custom_footer).to eq("footer")
|
||||
|
||||
desktop_css = SiteCustomization.custom_stylesheet
|
||||
desktop_css.should =~ Regexp.new("#{SiteCustomization::ENABLED_KEY}.css\\?target=desktop")
|
||||
expect(desktop_css).to match(Regexp.new("#{SiteCustomization::ENABLED_KEY}.css\\?target=desktop"))
|
||||
|
||||
mobile_css = SiteCustomization.custom_stylesheet(nil, :mobile)
|
||||
mobile_css.should =~ Regexp.new("#{SiteCustomization::ENABLED_KEY}.css\\?target=mobile")
|
||||
expect(mobile_css).to match(Regexp.new("#{SiteCustomization::ENABLED_KEY}.css\\?target=mobile"))
|
||||
|
||||
SiteCustomization.enabled_stylesheet_contents.should =~ /\.hello \.world/
|
||||
expect(SiteCustomization.enabled_stylesheet_contents).to match(/\.hello \.world/)
|
||||
|
||||
# cache expiry
|
||||
c1.enabled = false
|
||||
c1.save
|
||||
|
||||
SiteCustomization.custom_stylesheet.should_not == desktop_css
|
||||
SiteCustomization.enabled_stylesheet_contents.should_not =~ /\.hello \.world/
|
||||
expect(SiteCustomization.custom_stylesheet).not_to eq(desktop_css)
|
||||
expect(SiteCustomization.enabled_stylesheet_contents).not_to match(/\.hello \.world/)
|
||||
end
|
||||
|
||||
it 'should be able to look up stylesheets by key' do
|
||||
|
@ -65,30 +65,30 @@ describe SiteCustomization do
|
|||
stylesheet: '.hello{.world {color: blue;}}',
|
||||
mobile_stylesheet: '.world{.hello{color: black;}}')
|
||||
|
||||
SiteCustomization.custom_stylesheet(c.key, :mobile).should =~ Regexp.new("#{c.key}.css\\?target=mobile")
|
||||
SiteCustomization.custom_stylesheet(c.key).should =~ Regexp.new("#{c.key}.css\\?target=desktop")
|
||||
expect(SiteCustomization.custom_stylesheet(c.key, :mobile)).to match(Regexp.new("#{c.key}.css\\?target=mobile"))
|
||||
expect(SiteCustomization.custom_stylesheet(c.key)).to match(Regexp.new("#{c.key}.css\\?target=desktop"))
|
||||
|
||||
end
|
||||
|
||||
|
||||
it 'should allow including discourse styles' do
|
||||
c = SiteCustomization.create!(user_id: user.id, name: "test", stylesheet: '@import "desktop";', mobile_stylesheet: '@import "mobile";')
|
||||
c.stylesheet_baked.should_not =~ /Syntax error/
|
||||
c.stylesheet_baked.length.should be > 1000
|
||||
c.mobile_stylesheet_baked.should_not =~ /Syntax error/
|
||||
c.mobile_stylesheet_baked.length.should be > 1000
|
||||
expect(c.stylesheet_baked).not_to match(/Syntax error/)
|
||||
expect(c.stylesheet_baked.length).to be > 1000
|
||||
expect(c.mobile_stylesheet_baked).not_to match(/Syntax error/)
|
||||
expect(c.mobile_stylesheet_baked.length).to be > 1000
|
||||
end
|
||||
|
||||
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/
|
||||
c.mobile_stylesheet_baked.should_not be_present
|
||||
expect(c.stylesheet_baked).to match(/Syntax error/)
|
||||
expect(c.mobile_stylesheet_baked).not_to be_present
|
||||
end
|
||||
|
||||
it 'should provide an awesome error on failure for mobile too' do
|
||||
c = SiteCustomization.create!(user_id: user.id, name: "test", stylesheet: '', header: '', mobile_stylesheet: "$black: #000; #a { color: $black; }\n\n\nboom", mobile_header: '')
|
||||
c.mobile_stylesheet_baked.should =~ /Syntax error/
|
||||
c.stylesheet_baked.should_not be_present
|
||||
expect(c.mobile_stylesheet_baked).to match(/Syntax error/)
|
||||
expect(c.stylesheet_baked).not_to be_present
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -7,30 +7,31 @@ describe SiteSetting do
|
|||
describe "normalized_embeddable_host" do
|
||||
it 'returns the `embeddable_host` value' do
|
||||
SiteSetting.stubs(:embeddable_host).returns("eviltrout.com")
|
||||
SiteSetting.normalized_embeddable_host.should == "eviltrout.com"
|
||||
expect(SiteSetting.normalized_embeddable_host).to eq("eviltrout.com")
|
||||
end
|
||||
|
||||
it 'strip http from `embeddable_host` value' do
|
||||
SiteSetting.stubs(:embeddable_host).returns("http://eviltrout.com")
|
||||
SiteSetting.normalized_embeddable_host.should == "eviltrout.com"
|
||||
expect(SiteSetting.normalized_embeddable_host).to eq("eviltrout.com")
|
||||
end
|
||||
|
||||
it 'strip https from `embeddable_host` value' do
|
||||
SiteSetting.stubs(:embeddable_host).returns("https://eviltrout.com")
|
||||
SiteSetting.normalized_embeddable_host.should == "eviltrout.com"
|
||||
expect(SiteSetting.normalized_embeddable_host).to eq("eviltrout.com")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'topic_title_length' do
|
||||
it 'returns a range of min/max topic title length' do
|
||||
SiteSetting.topic_title_length.should ==
|
||||
expect(SiteSetting.topic_title_length).to eq(
|
||||
(SiteSetting.defaults[:min_topic_title_length]..SiteSetting.defaults[:max_topic_title_length])
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'post_length' do
|
||||
it 'returns a range of min/max post length' do
|
||||
SiteSetting.post_length.should == (SiteSetting.defaults[:min_post_length]..SiteSetting.defaults[:max_post_length])
|
||||
expect(SiteSetting.post_length).to eq(SiteSetting.defaults[:min_post_length]..SiteSetting.defaults[:max_post_length])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -83,12 +84,12 @@ describe SiteSetting do
|
|||
|
||||
it "returns http when ssl is disabled" do
|
||||
SiteSetting.expects(:use_https).returns(false)
|
||||
SiteSetting.scheme.should == "http"
|
||||
expect(SiteSetting.scheme).to eq("http")
|
||||
end
|
||||
|
||||
it "returns https when using ssl" do
|
||||
SiteSetting.expects(:use_https).returns(true)
|
||||
SiteSetting.scheme.should == "https"
|
||||
expect(SiteSetting.scheme).to eq("https")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,26 +6,26 @@ describe Site do
|
|||
category = Fabricate(:category)
|
||||
user = Fabricate(:user)
|
||||
|
||||
Site.new(Guardian.new(user)).categories.count.should == 2
|
||||
expect(Site.new(Guardian.new(user)).categories.count).to eq(2)
|
||||
|
||||
category.set_permissions(:everyone => :create_post)
|
||||
category.save
|
||||
|
||||
guardian = Guardian.new(user)
|
||||
|
||||
Site.new(guardian)
|
||||
expect(Site.new(guardian)
|
||||
.categories
|
||||
.keep_if{|c| c.name == category.name}
|
||||
.first
|
||||
.permission
|
||||
.should_not == CategoryGroup.permission_types[:full]
|
||||
.permission)
|
||||
.not_to eq(CategoryGroup.permission_types[:full])
|
||||
|
||||
# If a parent category is not visible, the child categories should not be returned
|
||||
category.set_permissions(:staff => :full)
|
||||
category.save
|
||||
|
||||
sub_category = Fabricate(:category, parent_category_id: category.id)
|
||||
Site.new(guardian).categories.should_not include(sub_category)
|
||||
expect(Site.new(guardian).categories).not_to include(sub_category)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,23 +2,23 @@ require 'spec_helper'
|
|||
|
||||
describe SiteText do
|
||||
|
||||
it { should validate_presence_of :value }
|
||||
it { is_expected.to validate_presence_of :value }
|
||||
|
||||
|
||||
describe "#text_for" do
|
||||
|
||||
it "returns an empty string for a missing text_type" do
|
||||
SiteText.text_for('something_random').should == ""
|
||||
expect(SiteText.text_for('something_random')).to eq("")
|
||||
end
|
||||
|
||||
it "returns the default value for a text` type with a default" do
|
||||
SiteText.text_for("usage_tips").should be_present
|
||||
expect(SiteText.text_for("usage_tips")).to be_present
|
||||
end
|
||||
|
||||
it "correctly expires and bypasses cache" do
|
||||
SiteSetting.enable_sso = false
|
||||
text = SiteText.create!(text_type: "got.sso", value: "got sso: %{enable_sso}")
|
||||
SiteText.text_for("got.sso").should == "got sso: false"
|
||||
expect(SiteText.text_for("got.sso")).to eq("got sso: false")
|
||||
SiteText.text_for("got.sso").frozen? == true
|
||||
|
||||
SiteSetting.enable_sso = true
|
||||
|
@ -33,14 +33,14 @@ describe SiteText do
|
|||
SiteText.text_for("got.sso") == "I gots sso: true"
|
||||
end
|
||||
|
||||
SiteText.text_for("got.sso", enable_sso: "frog").should == "I gots sso: frog"
|
||||
expect(SiteText.text_for("got.sso", enable_sso: "frog")).to eq("I gots sso: frog")
|
||||
end
|
||||
|
||||
context "without replacements" do
|
||||
let!(:site_text) { Fabricate(:site_text_basic) }
|
||||
|
||||
it "returns the simple string" do
|
||||
SiteText.text_for('breaking.bad').should == "best show ever"
|
||||
expect(SiteText.text_for('breaking.bad')).to eq("best show ever")
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -50,15 +50,15 @@ describe SiteText do
|
|||
let(:replacements) { {flower: 'roses', food: 'grapes'} }
|
||||
|
||||
it "returns the correct string with replacements" do
|
||||
SiteText.text_for('great.poem', replacements).should == "roses are red. grapes are blue."
|
||||
expect(SiteText.text_for('great.poem', replacements)).to eq("roses are red. grapes are blue.")
|
||||
end
|
||||
|
||||
it "doesn't mind extra keys in the replacements" do
|
||||
SiteText.text_for('great.poem', replacements.merge(extra: 'key')).should == "roses are red. grapes are blue."
|
||||
expect(SiteText.text_for('great.poem', replacements.merge(extra: 'key'))).to eq("roses are red. grapes are blue.")
|
||||
end
|
||||
|
||||
it "ignores missing keys" do
|
||||
SiteText.text_for('great.poem', flower: 'roses').should == "roses are red. %{food} are blue."
|
||||
expect(SiteText.text_for('great.poem', flower: 'roses')).to eq("roses are red. %{food} are blue.")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,12 +68,12 @@ describe SiteText do
|
|||
|
||||
it "replaces site_settings by default" do
|
||||
SiteSetting.title = "Evil Trout"
|
||||
SiteText.text_for('site.replacement').should == "Evil Trout is evil."
|
||||
expect(SiteText.text_for('site.replacement')).to eq("Evil Trout is evil.")
|
||||
end
|
||||
|
||||
it "allows us to override the default site settings" do
|
||||
SiteSetting.title = "Evil Trout"
|
||||
SiteText.text_for('site.replacement', title: 'Good Tuna').should == "Good Tuna is evil."
|
||||
expect(SiteText.text_for('site.replacement', title: 'Good Tuna')).to eq("Good Tuna is evil.")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,9 +7,9 @@ describe Topic do
|
|||
|
||||
let(:now) { Time.zone.local(2013,11,20,8,0) }
|
||||
|
||||
it { should validate_presence_of :title }
|
||||
it { is_expected.to validate_presence_of :title }
|
||||
|
||||
it { should rate_limit }
|
||||
it { is_expected.to rate_limit }
|
||||
|
||||
context 'slug' do
|
||||
|
||||
|
@ -18,7 +18,7 @@ describe Topic do
|
|||
|
||||
it "returns a Slug for a title" do
|
||||
Slug.expects(:for).with(title).returns(slug)
|
||||
Fabricate.build(:topic, title: title).slug.should == slug
|
||||
expect(Fabricate.build(:topic, title: title).slug).to eq(slug)
|
||||
end
|
||||
|
||||
let(:chinese_title) { "习近平:中企承建港口电站等助斯里兰卡发展" }
|
||||
|
@ -26,12 +26,12 @@ describe Topic do
|
|||
|
||||
it "returns a symbolized slug for a chinese title" do
|
||||
SiteSetting.default_locale = 'zh_CN'
|
||||
Fabricate.build(:topic, title: chinese_title).slug.should == chinese_slug
|
||||
expect(Fabricate.build(:topic, title: chinese_title).slug).to eq(chinese_slug)
|
||||
end
|
||||
|
||||
it "returns 'topic' when the slug is empty (say, non-english chars)" do
|
||||
Slug.expects(:for).with(title).returns("")
|
||||
Fabricate.build(:topic, title: title).slug.should == "topic"
|
||||
expect(Fabricate.build(:topic, title: title).slug).to eq("topic")
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -41,7 +41,7 @@ describe Topic do
|
|||
|
||||
it "doesn't update it to be shorter due to cleaning using TextCleaner" do
|
||||
topic.title = 'unread glitch'
|
||||
topic.save.should == false
|
||||
expect(topic.save).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -87,22 +87,22 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "won't allow another topic to be created with the same name" do
|
||||
new_topic.should_not be_valid
|
||||
expect(new_topic).not_to be_valid
|
||||
end
|
||||
|
||||
it "won't allow another topic with an upper case title to be created" do
|
||||
new_topic.title = new_topic.title.upcase
|
||||
new_topic.should_not be_valid
|
||||
expect(new_topic).not_to be_valid
|
||||
end
|
||||
|
||||
it "allows it when the topic is deleted" do
|
||||
topic.destroy
|
||||
new_topic.should be_valid
|
||||
expect(new_topic).to be_valid
|
||||
end
|
||||
|
||||
it "allows a private message to be created with the same topic" do
|
||||
new_topic.archetype = Archetype.private_message
|
||||
new_topic.should be_valid
|
||||
expect(new_topic).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -112,7 +112,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "will allow another topic to be created with the same name" do
|
||||
new_topic.should be_valid
|
||||
expect(new_topic).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -129,15 +129,15 @@ describe Topic do
|
|||
let(:topic_script) { build_topic_with_title("Topic with <script>alert('title')</script> script in its title" ) }
|
||||
|
||||
it "escapes script contents" do
|
||||
topic_script.fancy_title.should == "Topic with <script>alert(‘title’)</script> script in its title"
|
||||
expect(topic_script.fancy_title).to eq("Topic with <script>alert(‘title’)</script> script in its title")
|
||||
end
|
||||
|
||||
it "escapes bold contents" do
|
||||
topic_bold.fancy_title.should == "Topic with <b>bold</b> text in its title"
|
||||
expect(topic_bold.fancy_title).to eq("Topic with <b>bold</b> text in its title")
|
||||
end
|
||||
|
||||
it "escapes image contents" do
|
||||
topic_image.fancy_title.should == "Topic with <img src=‘something’> image in its title"
|
||||
expect(topic_image.fancy_title).to eq("Topic with <img src=‘something’> image in its title")
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -151,7 +151,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "doesn't add entities to the title" do
|
||||
topic.fancy_title.should == ""this topic" -- has ``fancy stuff''"
|
||||
expect(topic.fancy_title).to eq(""this topic" -- has ``fancy stuff''")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -161,7 +161,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "converts the title to have fancy entities" do
|
||||
topic.fancy_title.should == "“this topic” – has “fancy stuff”"
|
||||
expect(topic.fancy_title).to eq("“this topic” – has “fancy stuff”")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -174,17 +174,17 @@ describe Topic do
|
|||
|
||||
it "does not allow nil category" do
|
||||
topic = Fabricate.build(:topic, category: nil)
|
||||
topic.should_not be_valid
|
||||
topic.errors[:category_id].should be_present
|
||||
expect(topic).not_to be_valid
|
||||
expect(topic.errors[:category_id]).to be_present
|
||||
end
|
||||
|
||||
it "allows PMs" do
|
||||
topic = Fabricate.build(:topic, category: nil, archetype: Archetype.private_message)
|
||||
topic.should be_valid
|
||||
expect(topic).to be_valid
|
||||
end
|
||||
|
||||
it 'passes for topics with a category' do
|
||||
Fabricate.build(:topic, category: Fabricate(:category)).should be_valid
|
||||
expect(Fabricate.build(:topic, category: Fabricate(:category))).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -194,11 +194,11 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "passes for topics with nil category" do
|
||||
Fabricate.build(:topic, category: nil).should be_valid
|
||||
expect(Fabricate.build(:topic, category: nil)).to be_valid
|
||||
end
|
||||
|
||||
it 'passes for topics with a category' do
|
||||
Fabricate.build(:topic, category: Fabricate(:category)).should be_valid
|
||||
expect(Fabricate.build(:topic, category: Fabricate(:category))).to be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -207,14 +207,14 @@ describe Topic do
|
|||
context 'similar_to' do
|
||||
|
||||
it 'returns blank with nil params' do
|
||||
Topic.similar_to(nil, nil).should be_blank
|
||||
expect(Topic.similar_to(nil, nil)).to be_blank
|
||||
end
|
||||
|
||||
context "with a category definition" do
|
||||
let!(:category) { Fabricate(:category) }
|
||||
|
||||
it "excludes the category definition topic from similar_to" do
|
||||
Topic.similar_to('category definition for', "no body").should be_blank
|
||||
expect(Topic.similar_to('category definition for', "no body")).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -226,7 +226,7 @@ describe Topic do
|
|||
}
|
||||
|
||||
it 'returns the similar topic if the title is similar' do
|
||||
Topic.similar_to("has evil trout made any topics?", "i am wondering has evil trout made any topics?").should == [topic]
|
||||
expect(Topic.similar_to("has evil trout made any topics?", "i am wondering has evil trout made any topics?")).to eq([topic])
|
||||
end
|
||||
|
||||
context "secure categories" do
|
||||
|
@ -260,10 +260,10 @@ describe Topic do
|
|||
let!(:p3) { Fabricate(:post, topic: topic, user: topic.user) }
|
||||
|
||||
it "returns the post numbers of the topic" do
|
||||
topic.post_numbers.should == [1, 2, 3]
|
||||
expect(topic.post_numbers).to eq([1, 2, 3])
|
||||
p2.destroy
|
||||
topic.reload
|
||||
topic.post_numbers.should == [1, 3]
|
||||
expect(topic.post_numbers).to eq([1, 3])
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -275,14 +275,14 @@ describe Topic do
|
|||
let(:topic) { Fabricate(:private_message_topic) }
|
||||
|
||||
it "should integrate correctly" do
|
||||
Guardian.new(topic.user).can_see?(topic).should == true
|
||||
Guardian.new.can_see?(topic).should == false
|
||||
Guardian.new(evil_trout).can_see?(topic).should == false
|
||||
Guardian.new(coding_horror).can_see?(topic).should == true
|
||||
TopicQuery.new(evil_trout).list_latest.topics.should_not include(topic)
|
||||
expect(Guardian.new(topic.user).can_see?(topic)).to eq(true)
|
||||
expect(Guardian.new.can_see?(topic)).to eq(false)
|
||||
expect(Guardian.new(evil_trout).can_see?(topic)).to eq(false)
|
||||
expect(Guardian.new(coding_horror).can_see?(topic)).to eq(true)
|
||||
expect(TopicQuery.new(evil_trout).list_latest.topics).not_to include(topic)
|
||||
|
||||
# invites
|
||||
topic.invite(topic.user, 'duhhhhh').should == false
|
||||
expect(topic.invite(topic.user, 'duhhhhh')).to eq(false)
|
||||
end
|
||||
|
||||
context 'invite' do
|
||||
|
@ -293,26 +293,26 @@ describe Topic do
|
|||
context 'by username' do
|
||||
|
||||
it 'adds and removes walter to the allowed users' do
|
||||
topic.invite(topic.user, walter.username).should == true
|
||||
topic.allowed_users.include?(walter).should == true
|
||||
expect(topic.invite(topic.user, walter.username)).to eq(true)
|
||||
expect(topic.allowed_users.include?(walter)).to eq(true)
|
||||
|
||||
topic.remove_allowed_user(walter.username).should == true
|
||||
expect(topic.remove_allowed_user(walter.username)).to eq(true)
|
||||
topic.reload
|
||||
topic.allowed_users.include?(walter).should == false
|
||||
expect(topic.allowed_users.include?(walter)).to eq(false)
|
||||
end
|
||||
|
||||
it 'creates a notification' do
|
||||
lambda { topic.invite(topic.user, walter.username) }.should change(Notification, :count)
|
||||
expect { topic.invite(topic.user, walter.username) }.to change(Notification, :count)
|
||||
end
|
||||
end
|
||||
|
||||
context 'by email' do
|
||||
|
||||
it 'adds user correctly' do
|
||||
lambda {
|
||||
topic.invite(topic.user, walter.email).should == true
|
||||
}.should change(Notification, :count)
|
||||
topic.allowed_users.include?(walter).should == true
|
||||
expect {
|
||||
expect(topic.invite(topic.user, walter.email)).to eq(true)
|
||||
}.to change(Notification, :count)
|
||||
expect(topic.allowed_users.include?(walter)).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -326,9 +326,9 @@ describe Topic do
|
|||
it "should set up actions correctly" do
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
|
||||
actions.map{|a| a.action_type}.should_not include(UserAction::NEW_TOPIC)
|
||||
actions.map{|a| a.action_type}.should include(UserAction::NEW_PRIVATE_MESSAGE)
|
||||
coding_horror.user_actions.map{|a| a.action_type}.should include(UserAction::GOT_PRIVATE_MESSAGE)
|
||||
expect(actions.map{|a| a.action_type}).not_to include(UserAction::NEW_TOPIC)
|
||||
expect(actions.map{|a| a.action_type}).to include(UserAction::NEW_PRIVATE_MESSAGE)
|
||||
expect(coding_horror.user_actions.map{|a| a.action_type}).to include(UserAction::GOT_PRIVATE_MESSAGE)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -343,11 +343,11 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'updates the bumped_at field when a new post is made' do
|
||||
@topic.bumped_at.should be_present
|
||||
lambda {
|
||||
expect(@topic.bumped_at).to be_present
|
||||
expect {
|
||||
create_post(topic: @topic, user: @topic.user)
|
||||
@topic.reload
|
||||
}.should change(@topic, :bumped_at)
|
||||
}.to change(@topic, :bumped_at)
|
||||
end
|
||||
|
||||
context 'editing posts' do
|
||||
|
@ -358,25 +358,25 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "doesn't bump the topic on an edit to the last post that doesn't result in a new version" do
|
||||
lambda {
|
||||
expect {
|
||||
SiteSetting.expects(:ninja_edit_window).returns(5.minutes)
|
||||
@last_post.revise(@last_post.user, { raw: 'updated contents' }, revised_at: @last_post.created_at + 10.seconds)
|
||||
@topic.reload
|
||||
}.should_not change(@topic, :bumped_at)
|
||||
}.not_to change(@topic, :bumped_at)
|
||||
end
|
||||
|
||||
it "bumps the topic when a new version is made of the last post" do
|
||||
lambda {
|
||||
expect {
|
||||
@last_post.revise(Fabricate(:moderator), { raw: 'updated contents' })
|
||||
@topic.reload
|
||||
}.should change(@topic, :bumped_at)
|
||||
}.to change(@topic, :bumped_at)
|
||||
end
|
||||
|
||||
it "doesn't bump the topic when a post that isn't the last post receives a new version" do
|
||||
lambda {
|
||||
expect {
|
||||
@earlier_post.revise(Fabricate(:moderator), { raw: 'updated contents' })
|
||||
@topic.reload
|
||||
}.should_not change(@topic, :bumped_at)
|
||||
}.not_to change(@topic, :bumped_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -389,13 +389,13 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'creates a moderator post' do
|
||||
@mod_post.should be_present
|
||||
@mod_post.post_type.should == Post.types[:moderator_action]
|
||||
@mod_post.post_number.should == 999
|
||||
@mod_post.sort_order.should == 999
|
||||
@topic.topic_links.count.should == 1
|
||||
expect(@mod_post).to be_present
|
||||
expect(@mod_post.post_type).to eq(Post.types[:moderator_action])
|
||||
expect(@mod_post.post_number).to eq(999)
|
||||
expect(@mod_post.sort_order).to eq(999)
|
||||
expect(@topic.topic_links.count).to eq(1)
|
||||
@topic.reload
|
||||
@topic.moderator_posts_count.should == 1
|
||||
expect(@topic.moderator_posts_count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -417,9 +417,9 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should not be visible and have correct counts' do
|
||||
@topic.should_not be_visible
|
||||
@topic.moderator_posts_count.should == 1
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
expect(@topic).not_to be_visible
|
||||
expect(@topic.moderator_posts_count).to eq(1)
|
||||
expect(@topic.bumped_at.to_f).to eq(@original_bumped_at)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -431,9 +431,9 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should be visible with correct counts' do
|
||||
@topic.should be_visible
|
||||
@topic.moderator_posts_count.should == 1
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
expect(@topic).to be_visible
|
||||
expect(@topic.moderator_posts_count).to eq(1)
|
||||
expect(@topic.bumped_at.to_f).to eq(@original_bumped_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -446,9 +446,9 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "doesn't have a pinned_at but has correct dates" do
|
||||
@topic.pinned_at.should be_blank
|
||||
@topic.moderator_posts_count.should == 1
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
expect(@topic.pinned_at).to be_blank
|
||||
expect(@topic.moderator_posts_count).to eq(1)
|
||||
expect(@topic.bumped_at.to_f).to eq(@original_bumped_at)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -460,9 +460,9 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should enable correctly' do
|
||||
@topic.pinned_at.should be_present
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
@topic.moderator_posts_count.should == 1
|
||||
expect(@topic.pinned_at).to be_present
|
||||
expect(@topic.bumped_at.to_f).to eq(@original_bumped_at)
|
||||
expect(@topic.moderator_posts_count).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -476,9 +476,9 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should archive correctly' do
|
||||
@topic.should_not be_archived
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
@topic.moderator_posts_count.should == 1
|
||||
expect(@topic).not_to be_archived
|
||||
expect(@topic.bumped_at.to_f).to eq(@original_bumped_at)
|
||||
expect(@topic.moderator_posts_count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -490,9 +490,9 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should be archived' do
|
||||
@topic.should be_archived
|
||||
@topic.moderator_posts_count.should == 1
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
expect(@topic).to be_archived
|
||||
expect(@topic.moderator_posts_count).to eq(1)
|
||||
expect(@topic.bumped_at.to_f).to eq(@original_bumped_at)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -506,9 +506,9 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should not be pinned' do
|
||||
@topic.should_not be_closed
|
||||
@topic.moderator_posts_count.should == 1
|
||||
@topic.bumped_at.to_f.should_not == @original_bumped_at
|
||||
expect(@topic).not_to be_closed
|
||||
expect(@topic.moderator_posts_count).to eq(1)
|
||||
expect(@topic.bumped_at.to_f).not_to eq(@original_bumped_at)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -521,9 +521,9 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'should be closed' do
|
||||
@topic.should be_closed
|
||||
@topic.bumped_at.to_f.should == @original_bumped_at
|
||||
@topic.moderator_posts_count.should == 1
|
||||
expect(@topic).to be_closed
|
||||
expect(@topic.bumped_at.to_f).to eq(@original_bumped_at)
|
||||
expect(@topic.moderator_posts_count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -573,10 +573,10 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'increases the star_count of the forum topic' do
|
||||
lambda {
|
||||
expect {
|
||||
@topic.toggle_star(@user, true)
|
||||
@topic.reload
|
||||
}.should change(@topic, :star_count).by(1)
|
||||
}.to change(@topic, :star_count).by(1)
|
||||
end
|
||||
|
||||
it 'triggers the rate limiter' do
|
||||
|
@ -610,10 +610,10 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'reduces the star_count' do
|
||||
lambda {
|
||||
expect {
|
||||
@topic.toggle_star(@user, false)
|
||||
@topic.reload
|
||||
}.should change(@topic, :star_count).by(-1)
|
||||
}.to change(@topic, :star_count).by(-1)
|
||||
end
|
||||
|
||||
describe 'and adding a star again' do
|
||||
|
@ -639,20 +639,20 @@ describe Topic do
|
|||
it "changes the topic archetype to 'banner'" do
|
||||
messages = MessageBus.track_publish do
|
||||
topic.make_banner!(user)
|
||||
topic.archetype.should == Archetype.banner
|
||||
expect(topic.archetype).to eq(Archetype.banner)
|
||||
end
|
||||
|
||||
channels = messages.map(&:channel)
|
||||
channels.should include('/site/banner')
|
||||
channels.should include('/distributed_hash')
|
||||
expect(channels).to include('/site/banner')
|
||||
expect(channels).to include('/distributed_hash')
|
||||
end
|
||||
|
||||
it "ensures only one banner topic at all time" do
|
||||
_banner_topic = Fabricate(:banner_topic)
|
||||
Topic.where(archetype: Archetype.banner).count.should == 1
|
||||
expect(Topic.where(archetype: Archetype.banner).count).to eq(1)
|
||||
|
||||
topic.make_banner!(user)
|
||||
Topic.where(archetype: Archetype.banner).count.should == 1
|
||||
expect(Topic.where(archetype: Archetype.banner).count).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -663,7 +663,7 @@ describe Topic do
|
|||
topic.expects(:add_moderator_post)
|
||||
MessageBus.expects(:publish).with("/site/banner", nil)
|
||||
topic.remove_banner!(user)
|
||||
topic.archetype.should == Archetype.default
|
||||
expect(topic.archetype).to eq(Archetype.default)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -680,7 +680,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'initially has the last_post_user_id of the OP' do
|
||||
@topic.last_post_user_id.should == @user.id
|
||||
expect(@topic.last_post_user_id).to eq(@user.id)
|
||||
end
|
||||
|
||||
context 'after a second post' do
|
||||
|
@ -691,10 +691,10 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'updates the last_post_user_id to the second_user' do
|
||||
@topic.last_post_user_id.should == @second_user.id
|
||||
@topic.last_posted_at.to_i.should == @new_post.created_at.to_i
|
||||
expect(@topic.last_post_user_id).to eq(@second_user.id)
|
||||
expect(@topic.last_posted_at.to_i).to eq(@new_post.created_at.to_i)
|
||||
topic_user = @second_user.topic_users.find_by(topic_id: @topic.id)
|
||||
topic_user.posted?.should == true
|
||||
expect(topic_user.posted?).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -707,11 +707,11 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "should not increase the topic_count with no category" do
|
||||
-> { Fabricate(:topic, user: @category.user); @category.reload }.should_not change(@category, :topic_count)
|
||||
expect { Fabricate(:topic, user: @category.user); @category.reload }.not_to change(@category, :topic_count)
|
||||
end
|
||||
|
||||
it "should increase the category's topic_count" do
|
||||
-> { Fabricate(:topic, user: @category.user, category_id: @category.id); @category.reload }.should change(@category, :topic_count).by(1)
|
||||
expect { Fabricate(:topic, user: @category.user, category_id: @category.id); @category.reload }.to change(@category, :topic_count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -719,7 +719,7 @@ describe Topic do
|
|||
let(:topic) { Fabricate(:topic, meta_data: {'hello' => 'world'}) }
|
||||
|
||||
it 'allows us to create a topic with meta data' do
|
||||
topic.meta_data['hello'].should == 'world'
|
||||
expect(topic.meta_data['hello']).to eq('world')
|
||||
end
|
||||
|
||||
context 'updating' do
|
||||
|
@ -730,7 +730,7 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'updates the key' do
|
||||
topic.meta_data['hello'].should == 'bane'
|
||||
expect(topic.meta_data['hello']).to eq('bane')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -740,8 +740,8 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'adds the new key' do
|
||||
topic.meta_data['city'].should == 'gotham'
|
||||
topic.meta_data['hello'].should == 'world'
|
||||
expect(topic.meta_data['city']).to eq('gotham')
|
||||
expect(topic.meta_data['hello']).to eq('world')
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -753,11 +753,11 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "can be loaded" do
|
||||
Topic.find(topic.id).meta_data["other"].should == "key"
|
||||
expect(Topic.find(topic.id).meta_data["other"]).to eq("key")
|
||||
end
|
||||
|
||||
it "is in sync with custom_fields" do
|
||||
Topic.find(topic.id).custom_fields["other"].should == "key"
|
||||
expect(Topic.find(topic.id).custom_fields["other"]).to eq("key")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -771,21 +771,21 @@ describe Topic do
|
|||
let(:topic) { Fabricate(:topic) }
|
||||
|
||||
it 'is a regular topic by default' do
|
||||
topic.archetype.should == Archetype.default
|
||||
topic.has_summary.should == false
|
||||
topic.percent_rank.should == 1.0
|
||||
topic.should be_visible
|
||||
topic.pinned_at.should be_blank
|
||||
topic.should_not be_closed
|
||||
topic.should_not be_archived
|
||||
topic.moderator_posts_count.should == 0
|
||||
expect(topic.archetype).to eq(Archetype.default)
|
||||
expect(topic.has_summary).to eq(false)
|
||||
expect(topic.percent_rank).to eq(1.0)
|
||||
expect(topic).to be_visible
|
||||
expect(topic.pinned_at).to be_blank
|
||||
expect(topic).not_to be_closed
|
||||
expect(topic).not_to be_archived
|
||||
expect(topic.moderator_posts_count).to eq(0)
|
||||
end
|
||||
|
||||
context 'post' do
|
||||
let(:post) { Fabricate(:post, topic: topic, user: topic.user) }
|
||||
|
||||
it 'has the same archetype as the topic' do
|
||||
post.archetype.should == topic.archetype
|
||||
expect(post.archetype).to eq(topic.archetype)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -801,7 +801,7 @@ describe Topic do
|
|||
describe 'without a previous category' do
|
||||
|
||||
it 'should not change the topic_count when not changed' do
|
||||
lambda { @topic.change_category_to_id(@topic.category.id); @category.reload }.should_not change(@category, :topic_count)
|
||||
expect { @topic.change_category_to_id(@topic.category.id); @category.reload }.not_to change(@category, :topic_count)
|
||||
end
|
||||
|
||||
describe 'changed category' do
|
||||
|
@ -811,15 +811,15 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'changes the category' do
|
||||
@topic.category.should == @category
|
||||
@category.topic_count.should == 1
|
||||
expect(@topic.category).to eq(@category)
|
||||
expect(@category.topic_count).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it "doesn't change the category when it can't be found" do
|
||||
@topic.change_category_to_id(12312312)
|
||||
@topic.category_id.should == SiteSetting.uncategorized_category_id
|
||||
expect(@topic.category_id).to eq(SiteSetting.uncategorized_category_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -831,16 +831,16 @@ describe Topic do
|
|||
end
|
||||
|
||||
it 'increases the topic_count' do
|
||||
@category.topic_count.should == 1
|
||||
expect(@category.topic_count).to eq(1)
|
||||
end
|
||||
|
||||
it "doesn't change the topic_count when the value doesn't change" do
|
||||
lambda { @topic.change_category_to_id(@category.id); @category.reload }.should_not change(@category, :topic_count)
|
||||
expect { @topic.change_category_to_id(@category.id); @category.reload }.not_to change(@category, :topic_count)
|
||||
end
|
||||
|
||||
it "doesn't reset the category when given a name that doesn't exist" do
|
||||
@topic.change_category_to_id(55556)
|
||||
@topic.category_id.should be_present
|
||||
expect(@topic.category_id).to be_present
|
||||
end
|
||||
|
||||
describe 'to a different category' do
|
||||
|
@ -853,11 +853,11 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "should increase the new category's topic count" do
|
||||
@new_category.topic_count.should == 1
|
||||
expect(@new_category.topic_count).to eq(1)
|
||||
end
|
||||
|
||||
it "should lower the original category's topic count" do
|
||||
@category.topic_count.should == 0
|
||||
expect(@category.topic_count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -869,7 +869,7 @@ describe Topic do
|
|||
let!(:topic) { Fabricate(:topic, category: Fabricate(:category)) }
|
||||
|
||||
it 'returns false' do
|
||||
topic.change_category_to_id(nil).should eq(false) # don't use "== false" here because it would also match nil
|
||||
expect(topic.change_category_to_id(nil)).to eq(false) # don't use "== false" here because it would also match nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -880,8 +880,8 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "resets the category" do
|
||||
@topic.category_id.should == SiteSetting.uncategorized_category_id
|
||||
@category.topic_count.should == 0
|
||||
expect(@topic.category_id).to eq(SiteSetting.uncategorized_category_id)
|
||||
expect(@category.topic_count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -897,7 +897,7 @@ describe Topic do
|
|||
b = Fabricate(:topic, created_at: now)
|
||||
c = Fabricate(:topic, created_at: now)
|
||||
d = Fabricate(:topic, created_at: now - 2.minutes)
|
||||
Topic.by_newest.should == [c,b,d,a]
|
||||
expect(Topic.by_newest).to eq([c,b,d,a])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -909,11 +909,11 @@ describe Topic do
|
|||
c = Fabricate(:topic, created_at: now)
|
||||
d = Fabricate(:topic, created_at: now + 1.minute)
|
||||
e = Fabricate(:topic, created_at: now + 2.minutes)
|
||||
Topic.created_since(now).should_not include a
|
||||
Topic.created_since(now).should_not include b
|
||||
Topic.created_since(now).should_not include c
|
||||
Topic.created_since(now).should include d
|
||||
Topic.created_since(now).should include e
|
||||
expect(Topic.created_since(now)).not_to include a
|
||||
expect(Topic.created_since(now)).not_to include b
|
||||
expect(Topic.created_since(now)).not_to include c
|
||||
expect(Topic.created_since(now)).to include d
|
||||
expect(Topic.created_since(now)).to include e
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -922,9 +922,9 @@ describe Topic do
|
|||
a = Fabricate(:topic, visible: false)
|
||||
b = Fabricate(:topic, visible: true)
|
||||
c = Fabricate(:topic, visible: true)
|
||||
Topic.visible.should_not include a
|
||||
Topic.visible.should include b
|
||||
Topic.visible.should include c
|
||||
expect(Topic.visible).not_to include a
|
||||
expect(Topic.visible).to include b
|
||||
expect(Topic.visible).to include c
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -983,7 +983,7 @@ describe Topic do
|
|||
topic = Fabricate(:topic)
|
||||
Jobs.expects(:enqueue_at).with(12.hours.from_now, :close_topic, has_entries(topic_id: topic.id, user_id: topic.user_id))
|
||||
topic.auto_close_at = 12.hours.from_now
|
||||
topic.save.should == true
|
||||
expect(topic.save).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -994,7 +994,7 @@ describe Topic do
|
|||
Jobs.expects(:enqueue_at).with(12.hours.from_now, :close_topic, has_entries(topic_id: topic.id, user_id: closer.id))
|
||||
topic.auto_close_at = 12.hours.from_now
|
||||
topic.auto_close_user = closer
|
||||
topic.save.should == true
|
||||
expect(topic.save).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1003,8 +1003,8 @@ describe Topic do
|
|||
topic = Fabricate(:topic, auto_close_at: 1.day.from_now)
|
||||
Jobs.expects(:cancel_scheduled_job).with(:close_topic, {topic_id: topic.id})
|
||||
topic.auto_close_at = nil
|
||||
topic.save.should == true
|
||||
topic.auto_close_user.should == nil
|
||||
expect(topic.save).to eq(true)
|
||||
expect(topic.auto_close_user).to eq(nil)
|
||||
end
|
||||
|
||||
it 'when auto_close_user is removed, it updates the job' do
|
||||
|
@ -1014,7 +1014,7 @@ describe Topic do
|
|||
Jobs.expects(:cancel_scheduled_job).with(:close_topic, {topic_id: topic.id})
|
||||
Jobs.expects(:enqueue_at).with(1.day.from_now, :close_topic, has_entries(topic_id: topic.id, user_id: topic.user_id))
|
||||
topic.auto_close_user = nil
|
||||
topic.save.should == true
|
||||
expect(topic.save).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1025,7 +1025,7 @@ describe Topic do
|
|||
Jobs.expects(:cancel_scheduled_job).with(:close_topic, {topic_id: topic.id})
|
||||
Jobs.expects(:enqueue_at).with(3.days.from_now, :close_topic, has_entry(topic_id: topic.id))
|
||||
topic.auto_close_at = 3.days.from_now
|
||||
topic.save.should == true
|
||||
expect(topic.save).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1037,7 +1037,7 @@ describe Topic do
|
|||
Jobs.expects(:cancel_scheduled_job).with(:close_topic, {topic_id: topic.id})
|
||||
Jobs.expects(:enqueue_at).with(1.day.from_now, :close_topic, has_entries(topic_id: topic.id, user_id: admin.id))
|
||||
topic.auto_close_user = admin
|
||||
topic.save.should == true
|
||||
expect(topic.save).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1047,7 +1047,7 @@ describe Topic do
|
|||
Jobs.expects(:cancel_scheduled_job).never
|
||||
topic = Fabricate(:topic, auto_close_at: 1.day.from_now)
|
||||
topic.title = 'A new title that is long enough'
|
||||
topic.save.should == true
|
||||
expect(topic.save).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1061,12 +1061,12 @@ describe Topic do
|
|||
topic.save
|
||||
|
||||
topic.reload
|
||||
topic.closed.should == false
|
||||
expect(topic.closed).to eq(false)
|
||||
|
||||
Timecop.freeze(24.hours.from_now) do
|
||||
Topic.auto_close
|
||||
topic.reload
|
||||
topic.closed.should == true
|
||||
expect(topic.closed).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1099,36 +1099,36 @@ describe Topic do
|
|||
it "can take a time later in the day" do
|
||||
Timecop.freeze(now) do
|
||||
topic.set_auto_close('13:00', admin)
|
||||
topic.auto_close_at.should == Time.zone.local(2013,11,20,13,0)
|
||||
expect(topic.auto_close_at).to eq(Time.zone.local(2013,11,20,13,0))
|
||||
end
|
||||
end
|
||||
|
||||
it "can take a time for the next day" do
|
||||
Timecop.freeze(now) do
|
||||
topic.set_auto_close('5:00', admin)
|
||||
topic.auto_close_at.should == Time.zone.local(2013,11,21,5,0)
|
||||
expect(topic.auto_close_at).to eq(Time.zone.local(2013,11,21,5,0))
|
||||
end
|
||||
end
|
||||
|
||||
it "can take a timestamp for a future time" do
|
||||
Timecop.freeze(now) do
|
||||
topic.set_auto_close('2013-11-22 5:00', admin)
|
||||
topic.auto_close_at.should == Time.zone.local(2013,11,22,5,0)
|
||||
expect(topic.auto_close_at).to eq(Time.zone.local(2013,11,22,5,0))
|
||||
end
|
||||
end
|
||||
|
||||
it "sets a validation error when given a timestamp in the past" do
|
||||
Timecop.freeze(now) do
|
||||
topic.set_auto_close('2013-11-19 5:00', admin)
|
||||
topic.auto_close_at.should == Time.zone.local(2013,11,19,5,0)
|
||||
topic.errors[:auto_close_at].should be_present
|
||||
expect(topic.auto_close_at).to eq(Time.zone.local(2013,11,19,5,0))
|
||||
expect(topic.errors[:auto_close_at]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
it "can take a timestamp with timezone" do
|
||||
Timecop.freeze(now) do
|
||||
topic.set_auto_close('2013-11-25T01:35:00-08:00', admin)
|
||||
topic.auto_close_at.should == Time.utc(2013,11,25,9,35)
|
||||
expect(topic.auto_close_at).to eq(Time.utc(2013,11,25,9,35))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1192,17 +1192,17 @@ describe Topic do
|
|||
let(:user) { Fabricate.build(:user) }
|
||||
|
||||
it "returns none when there are no topics" do
|
||||
Topic.for_digest(user, 1.year.ago, top_order: true).should be_blank
|
||||
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
|
||||
end
|
||||
|
||||
it "doesn't return category topics" do
|
||||
Fabricate(:category)
|
||||
Topic.for_digest(user, 1.year.ago, top_order: true).should be_blank
|
||||
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
|
||||
end
|
||||
|
||||
it "returns regular topics" do
|
||||
topic = Fabricate(:topic)
|
||||
Topic.for_digest(user, 1.year.ago, top_order: true).should == [topic]
|
||||
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to eq([topic])
|
||||
end
|
||||
|
||||
it "doesn't return topics from muted categories" do
|
||||
|
@ -1212,7 +1212,7 @@ describe Topic do
|
|||
|
||||
CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id)
|
||||
|
||||
Topic.for_digest(user, 1.year.ago, top_order: true).should be_blank
|
||||
expect(Topic.for_digest(user, 1.year.ago, top_order: true)).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1222,13 +1222,13 @@ describe Topic do
|
|||
category = Fabricate(:category, read_restricted: true)
|
||||
Fabricate(:topic, category: category)
|
||||
|
||||
Topic.secured(Guardian.new(nil)).count.should == 0
|
||||
Topic.secured(Guardian.new(Fabricate(:admin))).count.should == 2
|
||||
expect(Topic.secured(Guardian.new(nil)).count).to eq(0)
|
||||
expect(Topic.secured(Guardian.new(Fabricate(:admin))).count).to eq(2)
|
||||
|
||||
# for_digest
|
||||
|
||||
Topic.for_digest(Fabricate(:user), 1.year.ago).count.should == 0
|
||||
Topic.for_digest(Fabricate(:admin), 1.year.ago).count.should == 1
|
||||
expect(Topic.for_digest(Fabricate(:user), 1.year.ago).count).to eq(0)
|
||||
expect(Topic.for_digest(Fabricate(:admin), 1.year.ago).count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1247,8 +1247,8 @@ describe Topic do
|
|||
let(:listable_topics_count_per_day) { {1.day.ago.to_date => 2, 2.days.ago.to_date => 1, Time.now.utc.to_date => 1 } }
|
||||
|
||||
it 'collect closed interval listable topics count' do
|
||||
Topic.listable_count_per_day(2.days.ago, Time.now).should include(listable_topics_count_per_day)
|
||||
Topic.listable_count_per_day(2.days.ago, Time.now).should_not include({4.days.ago.to_date => 1})
|
||||
expect(Topic.listable_count_per_day(2.days.ago, Time.now)).to include(listable_topics_count_per_day)
|
||||
expect(Topic.listable_count_per_day(2.days.ago, Time.now)).not_to include({4.days.ago.to_date => 1})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1257,16 +1257,16 @@ describe Topic do
|
|||
|
||||
it "is true if the category is secure" do
|
||||
category.stubs(:read_restricted).returns(true)
|
||||
Topic.new(:category => category).should be_read_restricted_category
|
||||
expect(Topic.new(:category => category)).to be_read_restricted_category
|
||||
end
|
||||
|
||||
it "is false if the category is not secure" do
|
||||
category.stubs(:read_restricted).returns(false)
|
||||
Topic.new(:category => category).should_not be_read_restricted_category
|
||||
expect(Topic.new(:category => category)).not_to be_read_restricted_category
|
||||
end
|
||||
|
||||
it "is false if there is no category" do
|
||||
Topic.new(:category => nil).should_not be_read_restricted_category
|
||||
expect(Topic.new(:category => nil)).not_to be_read_restricted_category
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1318,18 +1318,18 @@ describe Topic do
|
|||
topic_id = create_post(user: user).topic_id
|
||||
|
||||
freeze_time(start + 10.minutes)
|
||||
lambda {
|
||||
expect {
|
||||
create_post(user: user)
|
||||
}.should raise_exception
|
||||
}.to raise_exception
|
||||
|
||||
freeze_time(start + 20.minutes)
|
||||
create_post(user: user, topic_id: topic_id)
|
||||
|
||||
freeze_time(start + 30.minutes)
|
||||
|
||||
lambda {
|
||||
expect {
|
||||
create_post(user: user, topic_id: topic_id)
|
||||
}.should raise_exception
|
||||
}.to raise_exception
|
||||
end
|
||||
|
||||
describe ".count_exceeds_minimun?" do
|
||||
|
@ -1368,44 +1368,44 @@ describe Topic do
|
|||
end
|
||||
|
||||
it "is true with the correct settings and topic_embed" do
|
||||
topic.expandable_first_post?.should == true
|
||||
expect(topic.expandable_first_post?).to eq(true)
|
||||
end
|
||||
|
||||
it "is false if embeddable_host is blank" do
|
||||
SiteSetting.stubs(:embeddable_host).returns(nil)
|
||||
topic.expandable_first_post?.should == false
|
||||
expect(topic.expandable_first_post?).to eq(false)
|
||||
end
|
||||
|
||||
it "is false if embed_truncate? is false" do
|
||||
SiteSetting.stubs(:embed_truncate?).returns(false)
|
||||
topic.expandable_first_post?.should == false
|
||||
expect(topic.expandable_first_post?).to eq(false)
|
||||
end
|
||||
|
||||
it "is false if has_topic_embed? is false" do
|
||||
topic.stubs(:has_topic_embed?).returns(false)
|
||||
topic.expandable_first_post?.should == false
|
||||
expect(topic.expandable_first_post?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
it "has custom fields" do
|
||||
topic = Fabricate(:topic)
|
||||
topic.custom_fields["a"].should == nil
|
||||
expect(topic.custom_fields["a"]).to eq(nil)
|
||||
|
||||
topic.custom_fields["bob"] = "marley"
|
||||
topic.custom_fields["jack"] = "black"
|
||||
topic.save
|
||||
|
||||
topic = Topic.find(topic.id)
|
||||
topic.custom_fields.should == {"bob" => "marley", "jack" => "black"}
|
||||
expect(topic.custom_fields).to eq({"bob" => "marley", "jack" => "black"})
|
||||
end
|
||||
|
||||
it "doesn't validate the title again if it isn't changing" do
|
||||
SiteSetting.stubs(:min_topic_title_length).returns(5)
|
||||
topic = Fabricate(:topic, title: "Short")
|
||||
topic.should be_valid
|
||||
expect(topic).to be_valid
|
||||
|
||||
SiteSetting.stubs(:min_topic_title_length).returns(15)
|
||||
topic.last_posted_at = 1.minute.ago
|
||||
topic.save.should == true
|
||||
expect(topic.save).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,4 +5,4 @@ RSpec::Matchers.define :be_within_one_second_of do |expected_time|
|
|||
failure_message_for_should do |actual_time|
|
||||
"#{actual_time} is not within 1 second of #{expected_time}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue