mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Update rspec syntax to v3
update rspec syntax to v3 change syntax to rspec v3 oops. fix typo mailers classes with rspec3 syntax helpers with rspec3 syntax jobs with rspec3 syntax serializers with rspec3 syntax views with rspec3 syntax support to rspec3 syntax category spec with rspec3 syntax
This commit is contained in:
parent
fce74e64a1
commit
b3d769ff4f
80 changed files with 1245 additions and 1247 deletions
|
@ -4,10 +4,10 @@ describe ApplicationHelper do
|
|||
|
||||
describe "escape_unicode" do
|
||||
it "encodes tags" do
|
||||
helper.escape_unicode("<tag>").should == "\u003ctag>"
|
||||
expect(helper.escape_unicode("<tag>")).to eq("\u003ctag>")
|
||||
end
|
||||
it "survives junk text" do
|
||||
helper.escape_unicode("hello \xc3\x28 world").should =~ /hello.*world/
|
||||
expect(helper.escape_unicode("hello \xc3\x28 world")).to match(/hello.*world/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -19,38 +19,38 @@ describe ApplicationHelper do
|
|||
|
||||
it "is true if mobile_view is '1' in the session" do
|
||||
session[:mobile_view] = '1'
|
||||
helper.mobile_view?.should == true
|
||||
expect(helper.mobile_view?).to eq(true)
|
||||
end
|
||||
|
||||
it "is false if mobile_view is '0' in the session" do
|
||||
session[:mobile_view] = '0'
|
||||
helper.mobile_view?.should == false
|
||||
expect(helper.mobile_view?).to eq(false)
|
||||
end
|
||||
|
||||
context "mobile_view is not set" do
|
||||
it "is false if user agent is not mobile" do
|
||||
controller.request.stubs(:user_agent).returns('Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36')
|
||||
helper.mobile_view?.should be_falsey
|
||||
expect(helper.mobile_view?).to be_falsey
|
||||
end
|
||||
|
||||
it "is true for iPhone" do
|
||||
controller.request.stubs(:user_agent).returns('Mozilla/5.0 (iPhone; U; ru; CPU iPhone OS 4_2_1 like Mac OS X; ru) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5')
|
||||
helper.mobile_view?.should == true
|
||||
expect(helper.mobile_view?).to eq(true)
|
||||
end
|
||||
|
||||
it "is false for iPad" do
|
||||
controller.request.stubs(:user_agent).returns("Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3")
|
||||
helper.mobile_view?.should == false
|
||||
expect(helper.mobile_view?).to eq(false)
|
||||
end
|
||||
|
||||
it "is false for Nexus 10 tablet" do
|
||||
controller.request.stubs(:user_agent).returns("Mozilla/5.0 (Linux; Android 4.2.1; Nexus 10 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19")
|
||||
helper.mobile_view?.should be_falsey
|
||||
expect(helper.mobile_view?).to be_falsey
|
||||
end
|
||||
|
||||
it "is true for Nexus 7 tablet" do
|
||||
controller.request.stubs(:user_agent).returns("Mozilla/5.0 (Linux; Android 4.1.2; Nexus 7 Build/JZ054K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19")
|
||||
helper.mobile_view?.should == true
|
||||
expect(helper.mobile_view?).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -62,23 +62,23 @@ describe ApplicationHelper do
|
|||
|
||||
it "is false if mobile_view is '1' in the session" do
|
||||
session[:mobile_view] = '1'
|
||||
helper.mobile_view?.should == false
|
||||
expect(helper.mobile_view?).to eq(false)
|
||||
end
|
||||
|
||||
it "is false if mobile_view is '0' in the session" do
|
||||
session[:mobile_view] = '0'
|
||||
helper.mobile_view?.should == false
|
||||
expect(helper.mobile_view?).to eq(false)
|
||||
end
|
||||
|
||||
context "mobile_view is not set" do
|
||||
it "is false if user agent is not mobile" do
|
||||
controller.request.stubs(:user_agent).returns('Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36')
|
||||
helper.mobile_view?.should == false
|
||||
expect(helper.mobile_view?).to eq(false)
|
||||
end
|
||||
|
||||
it "is false for iPhone" do
|
||||
controller.request.stubs(:user_agent).returns('Mozilla/5.0 (iPhone; U; ru; CPU iPhone OS 4_2_1 like Mac OS X; ru) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148a Safari/6533.18.5')
|
||||
helper.mobile_view?.should == false
|
||||
expect(helper.mobile_view?).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,15 +5,15 @@ describe Jobs::BulkInvite do
|
|||
context '.execute' do
|
||||
|
||||
it 'raises an error when the filename is missing' do
|
||||
lambda { Jobs::BulkInvite.new.execute(identifier: '46-discoursecsv', chunks: '1') }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::BulkInvite.new.execute(identifier: '46-discoursecsv', chunks: '1') }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it 'raises an error when the identifier is missing' do
|
||||
lambda { Jobs::BulkInvite.new.execute(filename: 'discourse.csv', chunks: '1') }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::BulkInvite.new.execute(filename: 'discourse.csv', chunks: '1') }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it 'raises an error when the chunks is missing' do
|
||||
lambda { Jobs::BulkInvite.new.execute(filename: 'discourse.csv', identifier: '46-discoursecsv') }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::BulkInvite.new.execute(filename: 'discourse.csv', identifier: '46-discoursecsv') }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
context '.read_csv_file' do
|
||||
|
@ -24,7 +24,7 @@ describe Jobs::BulkInvite do
|
|||
it 'reads csv file' do
|
||||
bulk_invite.current_user = user
|
||||
bulk_invite.read_csv_file(csv_file)
|
||||
Invite.where(email: "robin@outlook.com").exists?.should == true
|
||||
expect(Invite.where(email: "robin@outlook.com").exists?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -41,7 +41,7 @@ describe Jobs::BulkInvite do
|
|||
|
||||
bulk_invite.current_user = user
|
||||
bulk_invite.send_invite(csv_info, 1)
|
||||
Invite.where(email: email).exists?.should == true
|
||||
expect(Invite.where(email: email).exists?).to eq(true)
|
||||
end
|
||||
|
||||
it 'creates an invite with group' do
|
||||
|
@ -51,8 +51,8 @@ describe Jobs::BulkInvite do
|
|||
bulk_invite.current_user = user
|
||||
bulk_invite.send_invite(csv_info, 1)
|
||||
invite = Invite.where(email: email).first
|
||||
invite.should be_present
|
||||
InvitedGroup.where(invite_id: invite.id, group_id: group.id).exists?.should == true
|
||||
expect(invite).to be_present
|
||||
expect(InvitedGroup.where(invite_id: invite.id, group_id: group.id).exists?).to eq(true)
|
||||
end
|
||||
|
||||
it 'creates an invite with topic' do
|
||||
|
@ -62,8 +62,8 @@ describe Jobs::BulkInvite do
|
|||
bulk_invite.current_user = user
|
||||
bulk_invite.send_invite(csv_info, 1)
|
||||
invite = Invite.where(email: email).first
|
||||
invite.should be_present
|
||||
TopicInvite.where(invite_id: invite.id, topic_id: topic.id).exists?.should == true
|
||||
expect(invite).to be_present
|
||||
expect(TopicInvite.where(invite_id: invite.id, topic_id: topic.id).exists?).to eq(true)
|
||||
end
|
||||
|
||||
it 'creates an invite with group and topic' do
|
||||
|
@ -74,9 +74,9 @@ describe Jobs::BulkInvite do
|
|||
bulk_invite.current_user = user
|
||||
bulk_invite.send_invite(csv_info, 1)
|
||||
invite = Invite.where(email: email).first
|
||||
invite.should be_present
|
||||
InvitedGroup.where(invite_id: invite.id, group_id: group.id).exists?.should == true
|
||||
TopicInvite.where(invite_id: invite.id, topic_id: topic.id).exists?.should == true
|
||||
expect(invite).to be_present
|
||||
expect(InvitedGroup.where(invite_id: invite.id, group_id: group.id).exists?).to eq(true)
|
||||
expect(TopicInvite.where(invite_id: invite.id, topic_id: topic.id).exists?).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,6 +7,6 @@ describe Jobs::CrawlTopicLink do
|
|||
let(:job) { Jobs::CrawlTopicLink.new }
|
||||
|
||||
it "needs a topic_link_id" do
|
||||
-> { job.execute({}) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { job.execute({}) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let!(:user_no_digests) { Fabricate(:active_user, email_digests: false, last_emailed_at: 8.days.ago, last_seen_at: 10.days.ago) }
|
||||
|
||||
it "doesn't return users with email disabled" do
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_no_digests.id).should == false
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_no_digests.id)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -36,7 +36,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let!(:user_emailed_recently) { Fabricate(:active_user, last_emailed_at: 6.days.ago) }
|
||||
|
||||
it "doesn't return users who have been emailed recently" do
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_emailed_recently.id).should == false
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user_emailed_recently.id)).to eq(false)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -45,7 +45,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let!(:inactive_user) { Fabricate(:user, active: false) }
|
||||
|
||||
it "doesn't return users who have been emailed recently" do
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(inactive_user.id).should == false
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(inactive_user.id)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -53,7 +53,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let!(:suspended_user) { Fabricate(:user, suspended_till: 1.week.from_now, suspended_at: 1.day.ago) }
|
||||
|
||||
it "doesn't return users who are suspended" do
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(suspended_user.id).should == false
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(suspended_user.id)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -63,12 +63,12 @@ describe Jobs::EnqueueDigestEmails do
|
|||
|
||||
it "doesn't return users who have been emailed recently" do
|
||||
user = user_visited_this_week
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user.id).should == false
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user.id)).to eq(false)
|
||||
end
|
||||
|
||||
it "does return users who have been emailed recently but have email_always set" do
|
||||
user = user_visited_this_week_email_always
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user.id).should == true
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids.include?(user.id)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -76,7 +76,7 @@ describe Jobs::EnqueueDigestEmails do
|
|||
let!(:user) { Fabricate(:active_user) }
|
||||
|
||||
it "returns the user" do
|
||||
Jobs::EnqueueDigestEmails.new.target_user_ids.should == [user.id]
|
||||
expect(Jobs::EnqueueDigestEmails.new.target_user_ids).to eq([user.id])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ describe Jobs::ExportCsvFile do
|
|||
|
||||
context '.execute' do
|
||||
it 'raises an error when the entity is missing' do
|
||||
lambda { Jobs::ExportCsvFile.new.execute(user_id: "1") }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::ExportCsvFile.new.execute(user_id: "1") }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -27,7 +27,7 @@ describe Jobs::ExportCsvFile do
|
|||
|
||||
user = to_hash(user_list_export.find{|u| u[0] == user.id})
|
||||
|
||||
user["external_id"].should == "123"
|
||||
user["external_email"].should == "test@test.com"
|
||||
expect(user["external_id"]).to eq("123")
|
||||
expect(user["external_email"]).to eq("test@test.com")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,11 +5,11 @@ require 'jobs/regular/process_post'
|
|||
describe Jobs::FeatureTopicUsers do
|
||||
|
||||
it "raises an error without a topic_id" do
|
||||
lambda { Jobs::FeatureTopicUsers.new.execute({}) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::FeatureTopicUsers.new.execute({}) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "raises an error with a missing topic_id" do
|
||||
lambda { Jobs::FeatureTopicUsers.new.execute(topic_id: 123) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::FeatureTopicUsers.new.execute(topic_id: 123) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
context 'with a topic' do
|
||||
|
@ -22,22 +22,22 @@ describe Jobs::FeatureTopicUsers do
|
|||
|
||||
it "won't feature the OP" do
|
||||
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
||||
topic.reload.featured_user_ids.include?(topic.user_id).should == false
|
||||
expect(topic.reload.featured_user_ids.include?(topic.user_id)).to eq(false)
|
||||
end
|
||||
|
||||
it "features the second poster" do
|
||||
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
||||
topic.reload.featured_user_ids.include?(coding_horror.id).should == true
|
||||
expect(topic.reload.featured_user_ids.include?(coding_horror.id)).to eq(true)
|
||||
end
|
||||
|
||||
it "will not feature the second poster if we supply their post to be ignored" do
|
||||
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id, except_post_id: second_post.id)
|
||||
topic.reload.featured_user_ids.include?(coding_horror.id).should == false
|
||||
expect(topic.reload.featured_user_ids.include?(coding_horror.id)).to eq(false)
|
||||
end
|
||||
|
||||
it "won't feature the last poster" do
|
||||
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
||||
topic.reload.featured_user_ids.include?(evil_trout.id).should == false
|
||||
expect(topic.reload.featured_user_ids.include?(evil_trout.id)).to eq(false)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -51,21 +51,21 @@ describe Jobs::FeatureTopicUsers do
|
|||
it "it works as expected" do
|
||||
|
||||
# It has 1 participant after creation
|
||||
topic.participant_count.should == 1
|
||||
expect(topic.participant_count).to eq(1)
|
||||
|
||||
# It still has 1 after featuring
|
||||
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
||||
topic.reload.participant_count.should == 1
|
||||
expect(topic.reload.participant_count).to eq(1)
|
||||
|
||||
# If the OP makes another post, it's still 1.
|
||||
create_post(topic: topic, user: post.user)
|
||||
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
||||
topic.reload.participant_count.should == 1
|
||||
expect(topic.reload.participant_count).to eq(1)
|
||||
|
||||
# If another users posts, it's 2.
|
||||
create_post(topic: topic, user: Fabricate(:evil_trout))
|
||||
Jobs::FeatureTopicUsers.new.execute(topic_id: topic.id)
|
||||
topic.reload.participant_count.should == 2
|
||||
expect(topic.reload.participant_count).to eq(2)
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ describe Jobs::InviteEmail do
|
|||
context '.execute' do
|
||||
|
||||
it 'raises an error when the invite_id is missing' do
|
||||
lambda { Jobs::InviteEmail.new.execute({}) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::InviteEmail.new.execute({}) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
context 'with an invite id' do
|
||||
|
|
|
@ -23,7 +23,7 @@ describe Jobs::Base do
|
|||
it 'handles correct jobs' do
|
||||
job = GoodJob.new
|
||||
job.perform({})
|
||||
job.count.should == 1
|
||||
expect(job.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'handles errors in multisite' do
|
||||
|
@ -33,7 +33,7 @@ describe Jobs::Base do
|
|||
|
||||
bad = BadJob.new
|
||||
expect{bad.perform({})}.to raise_error
|
||||
bad.fail_count.should == 3
|
||||
expect(bad.fail_count).to eq(3)
|
||||
end
|
||||
|
||||
it 'delegates the process call to execute' do
|
||||
|
|
|
@ -84,14 +84,14 @@ describe Jobs do
|
|||
job_to_keep2 = stub_everything(klass: 'Sidekiq::Extensions::DelayedClass', args: [YAML.dump(['Jobs::DrinkBeer', :delayed_perform, [{beer_id: 44}]])])
|
||||
job_to_keep2.expects(:delete).never
|
||||
Sidekiq::ScheduledSet.stubs(:new).returns( [job_to_keep1, job_to_delete, job_to_keep2] )
|
||||
Jobs.cancel_scheduled_job(:drink_beer, {beer_id: 42}).should == true
|
||||
expect(Jobs.cancel_scheduled_job(:drink_beer, {beer_id: 42})).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns false when no matching job is scheduled' do
|
||||
job_to_keep = stub_everything(klass: 'Sidekiq::Extensions::DelayedClass', args: [YAML.dump(['Jobs::DrinkBeer', :delayed_perform, [{beer_id: 43}]])])
|
||||
job_to_keep.expects(:delete).never
|
||||
Sidekiq::ScheduledSet.stubs(:new).returns( [job_to_keep] )
|
||||
Jobs.cancel_scheduled_job(:drink_beer, {beer_id: 42}).should == false
|
||||
expect(Jobs.cancel_scheduled_job(:drink_beer, {beer_id: 42})).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@ require_dependency 'jobs/regular/process_post'
|
|||
describe Jobs::NotifyMovedPosts do
|
||||
|
||||
it "raises an error without post_ids" do
|
||||
lambda { Jobs::NotifyMovedPosts.new.execute(moved_by_id: 1234) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::NotifyMovedPosts.new.execute(moved_by_id: 1234) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "raises an error without moved_by_id" do
|
||||
lambda { Jobs::NotifyMovedPosts.new.execute(post_ids: [1,2,3]) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::NotifyMovedPosts.new.execute(post_ids: [1,2,3]) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
|
||||
|
@ -22,12 +22,12 @@ describe Jobs::NotifyMovedPosts do
|
|||
let(:moved_post_notifications) { Notification.where(notification_type: Notification.types[:moved_post]) }
|
||||
|
||||
it "should create two notifications" do
|
||||
lambda { Jobs::NotifyMovedPosts.new.execute(post_ids: [p1.id, p2.id, p3.id], moved_by_id: admin.id) }.should change(moved_post_notifications, :count).by(2)
|
||||
expect { Jobs::NotifyMovedPosts.new.execute(post_ids: [p1.id, p2.id, p3.id], moved_by_id: admin.id) }.to change(moved_post_notifications, :count).by(2)
|
||||
end
|
||||
|
||||
context 'when moved by one of the posters' do
|
||||
it "create one notifications, because the poster is the mover" do
|
||||
lambda { Jobs::NotifyMovedPosts.new.execute(post_ids: [p1.id, p2.id, p3.id], moved_by_id: p1.user_id) }.should change(moved_post_notifications, :count).by(1)
|
||||
expect { Jobs::NotifyMovedPosts.new.execute(post_ids: [p1.id, p2.id, p3.id], moved_by_id: p1.user_id) }.to change(moved_post_notifications, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -116,13 +116,13 @@ describe Jobs::PollMailbox do
|
|||
poller.handle_mail(email)
|
||||
|
||||
topic = Topic.where(category: category).where.not(id: category.topic_id).last
|
||||
topic.should be_present
|
||||
topic.title.should == "We should have a post-by-email-feature"
|
||||
expect(topic).to be_present
|
||||
expect(topic.title).to eq("We should have a post-by-email-feature")
|
||||
|
||||
post = topic.posts.first
|
||||
post.cooked.strip.should == expected_post.strip
|
||||
expect(post.cooked.strip).to eq(expected_post.strip)
|
||||
|
||||
email.should be_deleted
|
||||
expect(email).to be_deleted
|
||||
end
|
||||
|
||||
describe "with insufficient trust" do
|
||||
|
@ -144,8 +144,8 @@ describe Jobs::PollMailbox do
|
|||
expect_success
|
||||
poller.handle_mail(email)
|
||||
topic = Topic.where(category: category).where.not(id: category.topic_id).last
|
||||
topic.should be_present
|
||||
topic.title.should == "We should have a post-by-email-feature"
|
||||
expect(topic).to be_present
|
||||
expect(topic.title).to eq("We should have a post-by-email-feature")
|
||||
ensure
|
||||
category.email_in_allow_strangers = false
|
||||
category.save
|
||||
|
@ -179,7 +179,7 @@ describe Jobs::PollMailbox do
|
|||
assert new_post.present?
|
||||
assert_equal expected_post.strip, new_post.cooked.strip
|
||||
|
||||
email.should be_deleted
|
||||
expect(email).to be_deleted
|
||||
end
|
||||
|
||||
it "works with multiple To addresses" do
|
||||
|
@ -192,7 +192,7 @@ describe Jobs::PollMailbox do
|
|||
assert new_post.present?
|
||||
assert_equal expected_post.strip, new_post.cooked.strip
|
||||
|
||||
email.should be_deleted
|
||||
expect(email).to be_deleted
|
||||
end
|
||||
|
||||
describe "with the wrong reply key" do
|
||||
|
@ -202,7 +202,7 @@ describe Jobs::PollMailbox do
|
|||
expect_exception Email::Receiver::EmailLogNotFound
|
||||
|
||||
poller.handle_mail(email)
|
||||
email.should be_deleted
|
||||
expect(email).to be_deleted
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -227,7 +227,7 @@ describe Jobs::PollMailbox do
|
|||
expect_exception Email::Receiver::TopicClosedError
|
||||
|
||||
poller.handle_mail(email)
|
||||
email.should be_deleted
|
||||
expect(email).to be_deleted
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -252,7 +252,7 @@ describe Jobs::PollMailbox do
|
|||
expect_exception Email::Receiver::TopicNotFoundError
|
||||
|
||||
poller.handle_mail(email)
|
||||
email.should be_deleted
|
||||
expect(email).to be_deleted
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -264,7 +264,7 @@ describe Jobs::PollMailbox do
|
|||
expect_exception Email::Receiver::EmailLogNotFound
|
||||
|
||||
poller.handle_mail(email)
|
||||
email.should be_deleted
|
||||
expect(email).to be_deleted
|
||||
end
|
||||
|
||||
it "a no content reply raises an EmptyEmailError" do
|
||||
|
@ -272,7 +272,7 @@ describe Jobs::PollMailbox do
|
|||
expect_exception Email::Receiver::EmptyEmailError
|
||||
|
||||
poller.handle_mail(email)
|
||||
email.should be_deleted
|
||||
expect(email).to be_deleted
|
||||
end
|
||||
|
||||
it "a fully empty email raises an EmptyEmailError" do
|
||||
|
@ -280,7 +280,7 @@ describe Jobs::PollMailbox do
|
|||
expect_exception Email::Receiver::EmptyEmailError
|
||||
|
||||
poller.handle_mail(email)
|
||||
email.should be_deleted
|
||||
expect(email).to be_deleted
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'jobs/regular/process_post'
|
|||
describe Jobs::ProcessPost do
|
||||
|
||||
it "returns when the post cannot be found" do
|
||||
lambda { Jobs::ProcessPost.new.perform(post_id: 1, sync_exec: true) }.should_not raise_error
|
||||
expect { Jobs::ProcessPost.new.perform(post_id: 1, sync_exec: true) }.not_to raise_error
|
||||
end
|
||||
|
||||
context 'with a post' do
|
||||
|
@ -19,7 +19,7 @@ describe Jobs::ProcessPost do
|
|||
cooked = post.cooked
|
||||
|
||||
post.reload
|
||||
post.cooked.should == cooked
|
||||
expect(post.cooked).to eq(cooked)
|
||||
|
||||
Jobs::ProcessPost.new.execute(post_id: post.id, cook: true)
|
||||
end
|
||||
|
@ -31,19 +31,19 @@ describe Jobs::ProcessPost do
|
|||
Jobs::ProcessPost.new.execute(post_id: post.id, cook: true)
|
||||
|
||||
post.reload
|
||||
post.cooked.should == cooked
|
||||
expect(post.cooked).to eq(cooked)
|
||||
end
|
||||
|
||||
it 'processes posts' do
|
||||
|
||||
post = Fabricate(:post, raw: "<img src='#{Discourse.base_url_no_prefix}/awesome/picture.png'>")
|
||||
post.cooked.should =~ /http/
|
||||
expect(post.cooked).to match(/http/)
|
||||
|
||||
Jobs::ProcessPost.new.execute(post_id: post.id)
|
||||
post.reload
|
||||
|
||||
# subtle but cooked post processor strip this stuff, this ensures all the code gets a workout
|
||||
post.cooked.should_not =~ /http/
|
||||
expect(post.cooked).not_to match(/http/)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,11 +4,11 @@ require 'jobs/regular/send_system_message'
|
|||
describe Jobs::SendSystemMessage do
|
||||
|
||||
it "raises an error without a user_id" do
|
||||
lambda { Jobs::SendSystemMessage.new.execute(message_type: 'welcome_invite') }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::SendSystemMessage.new.execute(message_type: 'welcome_invite') }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "raises an error without a message_type" do
|
||||
lambda { Jobs::SendSystemMessage.new.execute(user_id: 1234) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::SendSystemMessage.new.execute(user_id: 1234) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
context 'with valid parameters' do
|
||||
|
|
|
@ -5,7 +5,7 @@ describe Jobs::TestEmail do
|
|||
|
||||
context '.execute' do
|
||||
it 'raises an error when the address is missing' do
|
||||
lambda { Jobs::TestEmail.new.execute({}) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::TestEmail.new.execute({}) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
context 'with an address' do
|
||||
|
|
|
@ -23,7 +23,7 @@ describe Jobs::Tl3Promotions do
|
|||
def create_leader_user
|
||||
user = Fabricate(:user, trust_level: TrustLevel[2])
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(true)
|
||||
Promotion.new(user).review_tl2.should == true
|
||||
expect(Promotion.new(user).review_tl2).to eq(true)
|
||||
user
|
||||
end
|
||||
|
||||
|
@ -40,7 +40,7 @@ describe Jobs::Tl3Promotions do
|
|||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
|
||||
run_job
|
||||
user.reload.trust_level.should == TrustLevel[2]
|
||||
expect(user.reload.trust_level).to eq(TrustLevel[2])
|
||||
end
|
||||
|
||||
it "doesn't demote if user was promoted recently" do
|
||||
|
@ -52,7 +52,7 @@ describe Jobs::Tl3Promotions do
|
|||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(true)
|
||||
run_job
|
||||
user.reload.trust_level.should == TrustLevel[3]
|
||||
expect(user.reload.trust_level).to eq(TrustLevel[3])
|
||||
end
|
||||
|
||||
it "doesn't demote if user hasn't lost requirements (low water mark)" do
|
||||
|
@ -64,7 +64,7 @@ describe Jobs::Tl3Promotions do
|
|||
TrustLevel3Requirements.any_instance.stubs(:requirements_met?).returns(false)
|
||||
TrustLevel3Requirements.any_instance.stubs(:requirements_lost?).returns(false)
|
||||
run_job
|
||||
user.reload.trust_level.should == TrustLevel[3]
|
||||
expect(user.reload.trust_level).to eq(TrustLevel[3])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,8 +4,8 @@ describe Jobs::UpdateGravatar do
|
|||
|
||||
it "picks gravatar if system avatar is picked and gravatar was just downloaded" do
|
||||
user = User.create!(username: "bob", name: "bob", email: "a@a.com")
|
||||
user.uploaded_avatar_id.should == nil
|
||||
user.user_avatar.gravatar_upload_id.should == nil
|
||||
expect(user.uploaded_avatar_id).to eq(nil)
|
||||
expect(user.user_avatar.gravatar_upload_id).to eq(nil)
|
||||
|
||||
png = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==")
|
||||
FakeWeb.register_uri(:get, "http://www.gravatar.com/avatar/d10ca8d11301c2f4993ac2279ce4b930.png?s=500&d=404", body: png)
|
||||
|
@ -15,7 +15,7 @@ describe Jobs::UpdateGravatar do
|
|||
user.refresh_avatar
|
||||
user.reload
|
||||
|
||||
user.uploaded_avatar_id.should == user.user_avatar.gravatar_upload_id
|
||||
expect(user.uploaded_avatar_id).to eq(user.user_avatar.gravatar_upload_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,15 +12,15 @@ describe Jobs::UserEmail do
|
|||
let(:mailer) { Mail::Message.new(to: user.email) }
|
||||
|
||||
it "raises an error when there is no user" do
|
||||
lambda { Jobs::UserEmail.new.execute(type: :digest) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::UserEmail.new.execute(type: :digest) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "raises an error when there is no type" do
|
||||
lambda { Jobs::UserEmail.new.execute(user_id: user.id) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::UserEmail.new.execute(user_id: user.id) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "raises an error when the type doesn't exist" do
|
||||
lambda { Jobs::UserEmail.new.execute(type: :no_method, user_id: user.id) }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { Jobs::UserEmail.new.execute(type: :no_method, user_id: user.id) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "doesn't call the mailer when the user is missing" do
|
||||
|
@ -34,7 +34,7 @@ describe Jobs::UserEmail do
|
|||
UserNotifications.expects(:authorize_email).returns(mailer)
|
||||
Email::Sender.any_instance.expects(:send)
|
||||
Jobs::UserEmail.new.execute(type: :authorize_email, user_id: user.id, to_address: 'jake@adventuretime.ooo')
|
||||
mailer.to.should == ['jake@adventuretime.ooo']
|
||||
expect(mailer.to).to eq(['jake@adventuretime.ooo'])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ describe TestMailer do
|
|||
it "works" do
|
||||
test_mailer = TestMailer.send_test('marcheline@adventuretime.ooo')
|
||||
|
||||
test_mailer.from.should == [SiteSetting.notification_email]
|
||||
test_mailer.to.should == ['marcheline@adventuretime.ooo']
|
||||
test_mailer.subject.should be_present
|
||||
test_mailer.body.should be_present
|
||||
expect(test_mailer.from).to eq([SiteSetting.notification_email])
|
||||
expect(test_mailer.to).to eq(['marcheline@adventuretime.ooo'])
|
||||
expect(test_mailer.subject).to be_present
|
||||
expect(test_mailer.body).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ describe UserNotifications do
|
|||
reply3.hidden = true
|
||||
reply3.save
|
||||
|
||||
UserNotifications.get_context_posts(reply4, nil).count.should == 1
|
||||
expect(UserNotifications.get_context_posts(reply4, nil).count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,10 +29,10 @@ describe UserNotifications do
|
|||
subject { UserNotifications.signup(user) }
|
||||
|
||||
it "works" do
|
||||
subject.to.should == [user.email]
|
||||
subject.subject.should be_present
|
||||
subject.from.should == [SiteSetting.notification_email]
|
||||
subject.body.should be_present
|
||||
expect(subject.to).to eq([user.email])
|
||||
expect(subject.subject).to be_present
|
||||
expect(subject.from).to eq([SiteSetting.notification_email])
|
||||
expect(subject.body).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -42,10 +42,10 @@ describe UserNotifications do
|
|||
subject { UserNotifications.forgot_password(user) }
|
||||
|
||||
it "works" do
|
||||
subject.to.should == [user.email]
|
||||
subject.subject.should be_present
|
||||
subject.from.should == [SiteSetting.notification_email]
|
||||
subject.body.should be_present
|
||||
expect(subject.to).to eq([user.email])
|
||||
expect(subject.subject).to be_present
|
||||
expect(subject.from).to eq([SiteSetting.notification_email])
|
||||
expect(subject.body).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -57,7 +57,7 @@ describe UserNotifications do
|
|||
context "without new topics" do
|
||||
|
||||
it "doesn't send the email" do
|
||||
subject.to.should be_blank
|
||||
expect(subject.to).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -70,11 +70,11 @@ describe UserNotifications do
|
|||
end
|
||||
|
||||
it "works" do
|
||||
subject.to.should == [user.email]
|
||||
subject.subject.should be_present
|
||||
subject.from.should == [SiteSetting.notification_email]
|
||||
subject.html_part.body.to_s.should be_present
|
||||
subject.text_part.body.to_s.should be_present
|
||||
expect(subject.to).to eq([user.email])
|
||||
expect(subject.subject).to be_present
|
||||
expect(subject.from).to eq([SiteSetting.notification_email])
|
||||
expect(subject.html_part.body.to_s).to be_present
|
||||
expect(subject.text_part.body.to_s).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -100,32 +100,32 @@ describe UserNotifications do
|
|||
expect(mail.subject).to match(/India/)
|
||||
|
||||
# 2 respond to links cause we have 1 context post
|
||||
mail.html_part.to_s.scan(/To respond/).count.should == 2
|
||||
expect(mail.html_part.to_s.scan(/To respond/).count).to eq(2)
|
||||
|
||||
# 1 unsubscribe
|
||||
mail.html_part.to_s.scan(/To unsubscribe/).count.should == 1
|
||||
expect(mail.html_part.to_s.scan(/To unsubscribe/).count).to eq(1)
|
||||
|
||||
# side effect, topic user is updated with post number
|
||||
tu = TopicUser.get(post.topic_id, response.user)
|
||||
tu.last_emailed_post_number.should == response.post_number
|
||||
expect(tu.last_emailed_post_number).to eq(response.post_number)
|
||||
|
||||
# in mailing list mode user_replies is not sent through
|
||||
response.user.mailing_list_mode = true
|
||||
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
|
||||
|
||||
if rails_master?
|
||||
mail.message.class.should == ActionMailer::Base::NullMail
|
||||
expect(mail.message.class).to eq(ActionMailer::Base::NullMail)
|
||||
else
|
||||
mail.class.should == ActionMailer::Base::NullMail
|
||||
expect(mail.class).to eq(ActionMailer::Base::NullMail)
|
||||
end
|
||||
|
||||
response.user.mailing_list_mode = nil
|
||||
mail = UserNotifications.user_replied(response.user, post: response, notification: notification)
|
||||
|
||||
if rails_master?
|
||||
mail.message.class.should_not == ActionMailer::Base::NullMail
|
||||
expect(mail.message.class).not_to eq(ActionMailer::Base::NullMail)
|
||||
else
|
||||
mail.class.should_not == ActionMailer::Base::NullMail
|
||||
expect(mail.class).not_to eq(ActionMailer::Base::NullMail)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -151,14 +151,14 @@ describe UserNotifications do
|
|||
expect(mail.subject).not_to match(/Uncategorized/)
|
||||
|
||||
# 2 respond to links cause we have 1 context post
|
||||
mail.html_part.to_s.scan(/To respond/).count.should == 2
|
||||
expect(mail.html_part.to_s.scan(/To respond/).count).to eq(2)
|
||||
|
||||
# 1 unsubscribe link
|
||||
mail.html_part.to_s.scan(/To unsubscribe/).count.should == 1
|
||||
expect(mail.html_part.to_s.scan(/To unsubscribe/).count).to eq(1)
|
||||
|
||||
# side effect, topic user is updated with post number
|
||||
tu = TopicUser.get(post.topic_id, response.user)
|
||||
tu.last_emailed_post_number.should == response.post_number
|
||||
expect(tu.last_emailed_post_number).to eq(response.post_number)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -180,14 +180,14 @@ describe UserNotifications do
|
|||
expect(mail.subject).to match("[PM]")
|
||||
|
||||
# 1 respond to link
|
||||
mail.html_part.to_s.scan(/To respond/).count.should == 1
|
||||
expect(mail.html_part.to_s.scan(/To respond/).count).to eq(1)
|
||||
|
||||
# 1 unsubscribe link
|
||||
mail.html_part.to_s.scan(/To unsubscribe/).count.should == 1
|
||||
expect(mail.html_part.to_s.scan(/To unsubscribe/).count).to eq(1)
|
||||
|
||||
# side effect, topic user is updated with post number
|
||||
tu = TopicUser.get(topic.id, response.user)
|
||||
tu.last_emailed_post_number.should == response.post_number
|
||||
expect(tu.last_emailed_post_number).to eq(response.post_number)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ describe VersionMailer do
|
|||
before { SiteSetting.stubs(:contact_email).returns('') }
|
||||
|
||||
it "doesn't send the email" do
|
||||
subject.to.should be_blank
|
||||
expect(subject.to).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -15,10 +15,10 @@ describe VersionMailer do
|
|||
before { SiteSetting.stubs(:contact_email).returns('me@example.com') }
|
||||
|
||||
it "works" do
|
||||
subject.to.should == ['me@example.com']
|
||||
subject.subject.should be_present
|
||||
subject.from.should == [SiteSetting.notification_email]
|
||||
subject.body.should be_present
|
||||
expect(subject.to).to eq(['me@example.com'])
|
||||
expect(subject.subject).to be_present
|
||||
expect(subject.from).to eq([SiteSetting.notification_email])
|
||||
expect(subject.body).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -7,17 +7,17 @@ describe AdminDashboardData do
|
|||
|
||||
it 'returns nil when running in production mode' do
|
||||
Rails.stubs(env: ActiveSupport::StringInquirer.new('production'))
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when running in development mode' do
|
||||
Rails.stubs(env: ActiveSupport::StringInquirer.new('development'))
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when running in test mode' do
|
||||
Rails.stubs(env: ActiveSupport::StringInquirer.new('test'))
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -26,17 +26,17 @@ describe AdminDashboardData do
|
|||
|
||||
it 'returns nil when host_names is set' do
|
||||
Discourse.stubs(:current_hostname).returns('something.com')
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when host_name is localhost' do
|
||||
Discourse.stubs(:current_hostname).returns('localhost')
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when host_name is production.localhost' do
|
||||
Discourse.stubs(:current_hostname).returns('production.localhost')
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -45,12 +45,12 @@ describe AdminDashboardData do
|
|||
|
||||
it 'returns nil when gc params are set' do
|
||||
ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(90000000)
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when gc params are not set' do
|
||||
ENV.stubs(:[]).with('RUBY_GC_MALLOC_LIMIT').returns(nil)
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -60,31 +60,31 @@ describe AdminDashboardData do
|
|||
it 'returns nil when sidekiq processed a job recently' do
|
||||
Jobs.stubs(:last_job_performed_at).returns(1.minute.ago)
|
||||
Jobs.stubs(:queued).returns(0)
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil when last job processed was a long time ago, but no jobs are queued' do
|
||||
Jobs.stubs(:last_job_performed_at).returns(7.days.ago)
|
||||
Jobs.stubs(:queued).returns(0)
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil when no jobs have ever been processed, but no jobs are queued' do
|
||||
Jobs.stubs(:last_job_performed_at).returns(nil)
|
||||
Jobs.stubs(:queued).returns(0)
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when no jobs were processed recently and some jobs are queued' do
|
||||
Jobs.stubs(:last_job_performed_at).returns(20.minutes.ago)
|
||||
Jobs.stubs(:queued).returns(1)
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when no jobs have ever been processed, and some jobs are queued' do
|
||||
Jobs.stubs(:last_job_performed_at).returns(nil)
|
||||
Jobs.stubs(:queued).returns(1)
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -93,17 +93,17 @@ describe AdminDashboardData do
|
|||
|
||||
it 'returns nil when total ram is 1 GB' do
|
||||
MemInfo.any_instance.stubs(:mem_total).returns(1025272)
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil when total ram cannot be determined' do
|
||||
MemInfo.any_instance.stubs(:mem_total).returns(nil)
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when total ram is less than 1 GB' do
|
||||
MemInfo.any_instance.stubs(:mem_total).returns(512636)
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -184,7 +184,7 @@ describe AdminDashboardData do
|
|||
context 'when disabled' do
|
||||
it 'returns nil' do
|
||||
SiteSetting.stubs(enable_setting).returns(false)
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -196,25 +196,25 @@ describe AdminDashboardData do
|
|||
it 'returns nil key and secret are set' do
|
||||
SiteSetting.stubs(key).returns('12313213')
|
||||
SiteSetting.stubs(secret).returns('12312313123')
|
||||
subject.should == nil
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when key is not set' do
|
||||
SiteSetting.stubs(key).returns('')
|
||||
SiteSetting.stubs(secret).returns('12312313123')
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when secret is not set' do
|
||||
SiteSetting.stubs(key).returns('123123')
|
||||
SiteSetting.stubs(secret).returns('')
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
|
||||
it 'returns a string when key and secret are not set' do
|
||||
SiteSetting.stubs(key).returns('')
|
||||
SiteSetting.stubs(secret).returns('')
|
||||
subject.should_not == nil
|
||||
expect(subject).to_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,14 +3,14 @@ require 'spec_helper'
|
|||
require_dependency 'api_key'
|
||||
|
||||
describe ApiKey do
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :created_by }
|
||||
it { is_expected.to belong_to :user }
|
||||
it { is_expected.to belong_to :created_by }
|
||||
|
||||
it { should validate_presence_of :key }
|
||||
it { is_expected.to validate_presence_of :key }
|
||||
|
||||
pending 'validates uniqueness of user_id' do
|
||||
Fabricate(:api_key)
|
||||
should validate_uniqueness_of(:user_id)
|
||||
is_expected.to validate_uniqueness_of(:user_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,9 +2,16 @@ require 'spec_helper'
|
|||
require_dependency 'badge'
|
||||
|
||||
describe Badge do
|
||||
it { is_expected.to belong_to(:badge_type) }
|
||||
it { is_expected.to belong_to(:badge_grouping) }
|
||||
it { is_expected.to have_many(:user_badges).dependent(:destroy) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:name) }
|
||||
it { is_expected.to validate_presence_of(:badge_type) }
|
||||
it { is_expected.to validate_uniqueness_of(:name) }
|
||||
|
||||
it 'has a valid system attribute for new badges' do
|
||||
Badge.create!(name: "test", badge_type_id: 1).system?.should == false
|
||||
expect(Badge.create!(name: "test", badge_type_id: 1).system?).to be false
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require_dependency 'badge_type'
|
|||
|
||||
describe BadgeType do
|
||||
|
||||
it { should validate_presence_of :name }
|
||||
it { should validate_uniqueness_of :name }
|
||||
it { is_expected.to validate_presence_of :name }
|
||||
it { is_expected.to validate_uniqueness_of :name }
|
||||
|
||||
end
|
||||
|
|
|
@ -2,8 +2,8 @@ require 'spec_helper'
|
|||
|
||||
describe CategoryFeaturedTopic do
|
||||
|
||||
it { should belong_to :category }
|
||||
it { should belong_to :topic }
|
||||
it { is_expected.to belong_to :category }
|
||||
it { is_expected.to belong_to :topic }
|
||||
|
||||
context 'feature_topics_for' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
@ -21,7 +21,7 @@ describe CategoryFeaturedTopic do
|
|||
_uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
|
||||
|
||||
CategoryFeaturedTopic.feature_topics_for(category)
|
||||
CategoryFeaturedTopic.count.should == 1
|
||||
expect(CategoryFeaturedTopic.count).to be(1)
|
||||
|
||||
end
|
||||
|
||||
|
@ -29,7 +29,7 @@ describe CategoryFeaturedTopic do
|
|||
invisible_post = PostCreator.create(user, raw: "Don't look at this post because it's awful.", title: "not visible to anyone", category: category.id)
|
||||
invisible_post.topic.update_status('visible', false, Fabricate(:admin))
|
||||
CategoryFeaturedTopic.feature_topics_for(category)
|
||||
CategoryFeaturedTopic.count.should == 1
|
||||
expect(CategoryFeaturedTopic.count).to be(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,9 +2,8 @@ require 'spec_helper'
|
|||
|
||||
describe CategoryFeaturedUser do
|
||||
|
||||
it { should belong_to :category }
|
||||
it { should belong_to :user }
|
||||
|
||||
it { is_expected.to belong_to :category }
|
||||
it { is_expected.to belong_to :user }
|
||||
|
||||
context 'featuring users' do
|
||||
|
||||
|
@ -14,11 +13,11 @@ describe CategoryFeaturedUser do
|
|||
end
|
||||
|
||||
it 'has a featured user' do
|
||||
CategoryFeaturedUser.count.should_not == 0
|
||||
expect(CategoryFeaturedUser.count).to be(1)
|
||||
end
|
||||
|
||||
it 'returns the user via the category association' do
|
||||
@category.featured_users.should be_present
|
||||
expect(@category.featured_users).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,26 +4,26 @@ require 'spec_helper'
|
|||
require_dependency 'post_creator'
|
||||
|
||||
describe Category do
|
||||
it { should validate_presence_of :user_id }
|
||||
it { should validate_presence_of :name }
|
||||
it { is_expected.to validate_presence_of :user_id }
|
||||
it { is_expected.to validate_presence_of :name }
|
||||
|
||||
it 'validates uniqueness of name' do
|
||||
Fabricate(:category)
|
||||
should validate_uniqueness_of(:name).scoped_to(:parent_category_id)
|
||||
is_expected.to validate_uniqueness_of(:name).scoped_to(:parent_category_id)
|
||||
end
|
||||
|
||||
it 'validates uniqueness in case insensitive way' do
|
||||
Fabricate(:category, name: "Cats")
|
||||
c = Fabricate.build(:category, name: "cats")
|
||||
c.should_not be_valid
|
||||
c.errors[:name].should be_present
|
||||
cats = Fabricate.build(:category, name: "cats")
|
||||
expect(cats).to_not be_valid
|
||||
expect(cats.errors[:name]).to be_present
|
||||
end
|
||||
|
||||
describe "last_updated_at" do
|
||||
it "returns a number value of when the category was last updated" do
|
||||
last = Category.last_updated_at
|
||||
last.should be_present
|
||||
last.to_i.should == last
|
||||
expect(last).to be_present
|
||||
expect(last.to_i).to eq(last)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -31,8 +31,8 @@ describe Category do
|
|||
it "can determine read_restricted" do
|
||||
read_restricted, resolved = Category.resolve_permissions(:everyone => :full)
|
||||
|
||||
read_restricted.should == false
|
||||
resolved.should == []
|
||||
expect(read_restricted).to be false
|
||||
expect(resolved).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -64,24 +64,24 @@ describe Category do
|
|||
can_read_category.save
|
||||
|
||||
guardian = Guardian.new(admin)
|
||||
Category.topic_create_allowed(guardian).count.should == 5
|
||||
Category.post_create_allowed(guardian).count.should == 5
|
||||
Category.secured(guardian).count.should == 5
|
||||
expect(Category.topic_create_allowed(guardian).count).to be(5)
|
||||
expect(Category.post_create_allowed(guardian).count).to be(5)
|
||||
expect(Category.secured(guardian).count).to be(5)
|
||||
|
||||
guardian = Guardian.new(user)
|
||||
Category.secured(guardian).count.should == 5
|
||||
Category.post_create_allowed(guardian).count.should == 4
|
||||
Category.topic_create_allowed(guardian).count.should == 3 # explicitly allowed once, default allowed once
|
||||
expect(Category.secured(guardian).count).to be(5)
|
||||
expect(Category.post_create_allowed(guardian).count).to be(4)
|
||||
expect(Category.topic_create_allowed(guardian).count).to be(3) # explicitly allowed once, default allowed once
|
||||
|
||||
# everyone has special semantics, test it as well
|
||||
can_post_category.set_permissions(:everyone => :create_post)
|
||||
can_post_category.save
|
||||
|
||||
Category.post_create_allowed(guardian).count.should == 4
|
||||
expect(Category.post_create_allowed(guardian).count).to be(4)
|
||||
|
||||
# anonymous has permission to create no topics
|
||||
guardian = Guardian.new(nil)
|
||||
Category.post_create_allowed(guardian).count.should == 0
|
||||
expect(Category.post_create_allowed(guardian).count).to be(0)
|
||||
|
||||
end
|
||||
|
||||
|
@ -94,15 +94,15 @@ describe Category do
|
|||
let(:group) { Fabricate(:group) }
|
||||
|
||||
it "secures categories correctly" do
|
||||
category.read_restricted?.should == false
|
||||
expect(category.read_restricted?).to be false
|
||||
|
||||
category.set_permissions({})
|
||||
category.read_restricted?.should == true
|
||||
expect(category.read_restricted?).to be true
|
||||
|
||||
category.set_permissions(:everyone => :full)
|
||||
category.read_restricted?.should == false
|
||||
expect(category.read_restricted?).to be false
|
||||
|
||||
user.secure_categories.should be_empty
|
||||
expect(user.secure_categories).to be_empty
|
||||
|
||||
group.add(user)
|
||||
group.save
|
||||
|
@ -111,7 +111,7 @@ describe Category do
|
|||
category.save
|
||||
|
||||
user.reload
|
||||
user.secure_categories.should == [category]
|
||||
expect(user.secure_categories).to eq([category])
|
||||
end
|
||||
|
||||
it "lists all secured categories correctly" do
|
||||
|
@ -123,48 +123,48 @@ describe Category do
|
|||
category_2.set_permissions(group.id => :full)
|
||||
category_2.save
|
||||
|
||||
Category.secured.should =~ [uncategorized]
|
||||
Category.secured(Guardian.new(user)).should =~ [uncategorized,category, category_2]
|
||||
expect(Category.secured).to match_array([uncategorized])
|
||||
expect(Category.secured(Guardian.new(user))).to match_array([uncategorized,category, category_2])
|
||||
end
|
||||
end
|
||||
|
||||
it "strips leading blanks" do
|
||||
Fabricate(:category, name: " music").name.should == "music"
|
||||
expect(Fabricate(:category, name: " music").name).to eq("music")
|
||||
end
|
||||
|
||||
it "strips trailing blanks" do
|
||||
Fabricate(:category, name: "bugs ").name.should == "bugs"
|
||||
expect(Fabricate(:category, name: "bugs ").name).to eq("bugs")
|
||||
end
|
||||
|
||||
it "strips leading and trailing blanks" do
|
||||
Fabricate(:category, name: " blanks ").name.should == "blanks"
|
||||
expect(Fabricate(:category, name: " blanks ").name).to eq("blanks")
|
||||
end
|
||||
|
||||
it "sets name_lower" do
|
||||
Fabricate(:category, name: "Not MySQL").name_lower.should == "not mysql"
|
||||
expect(Fabricate(:category, name: "Not MySQL").name_lower).to eq("not mysql")
|
||||
end
|
||||
|
||||
it "has custom fields" do
|
||||
category = Fabricate(:category, name: " music")
|
||||
category.custom_fields["a"].should == nil
|
||||
expect(category.custom_fields["a"]).to be_nil
|
||||
|
||||
category.custom_fields["bob"] = "marley"
|
||||
category.custom_fields["jack"] = "black"
|
||||
category.save
|
||||
|
||||
category = Category.find(category.id)
|
||||
category.custom_fields.should == {"bob" => "marley", "jack" => "black"}
|
||||
expect(category.custom_fields).to eq({"bob" => "marley", "jack" => "black"})
|
||||
end
|
||||
|
||||
describe "short name" do
|
||||
let!(:category) { Fabricate(:category, name: 'xx') }
|
||||
|
||||
it "creates the category" do
|
||||
category.should be_present
|
||||
expect(category).to be_present
|
||||
end
|
||||
|
||||
it 'has one topic' do
|
||||
Topic.where(category_id: category.id).count.should == 1
|
||||
expect(Topic.where(category_id: category.id).count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -172,14 +172,14 @@ describe Category do
|
|||
let(:category) { Fabricate(:category, name: "测试") }
|
||||
|
||||
it "creates a blank slug, this is OK." do
|
||||
category.slug.should be_blank
|
||||
category.slug_for_url.should == "#{category.id}-category"
|
||||
expect(category.slug).to be_blank
|
||||
expect(category.slug_for_url).to eq("#{category.id}-category")
|
||||
end
|
||||
|
||||
it "creates a localized slug if default locale is zh_CN" do
|
||||
SiteSetting.default_locale = 'zh_CN'
|
||||
category.slug.should_not be_blank
|
||||
category.slug_for_url.should == "ce-shi"
|
||||
expect(category.slug).to_not be_blank
|
||||
expect(category.slug_for_url).to eq("ce-shi")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -187,15 +187,15 @@ describe Category do
|
|||
let(:category) { Fabricate(:category, name: "2") }
|
||||
|
||||
it 'creates a blank slug' do
|
||||
category.slug.should be_blank
|
||||
category.slug_for_url.should == "#{category.id}-category"
|
||||
expect(category.slug).to be_blank
|
||||
expect(category.slug_for_url).to eq("#{category.id}-category")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'custom slug can be provided' do
|
||||
it 'has the custom value' do
|
||||
c = Fabricate(:category, name: "Cats", slug: "cats-category")
|
||||
c.slug.should eq("cats-category")
|
||||
expect(c.slug).to eq("cats-category")
|
||||
end
|
||||
|
||||
it 'and be sanitized' do
|
||||
|
@ -206,17 +206,17 @@ describe Category do
|
|||
it 'fails if custom slug is duplicate with existing' do
|
||||
c1 = Fabricate(:category, name: "Cats", slug: "cats")
|
||||
c2 = Fabricate.build(:category, name: "More Cats", slug: "cats")
|
||||
c2.should_not be_valid
|
||||
c2.errors[:slug].should be_present
|
||||
expect(c2).to_not be_valid
|
||||
expect(c2.errors[:slug]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
describe 'description_text' do
|
||||
it 'correctly generates text description as needed' do
|
||||
c = Category.new
|
||||
c.description_text.should == nil
|
||||
expect(c.description_text).to be_nil
|
||||
c.description = "<hello <a>test</a>."
|
||||
c.description_text.should == "<hello test."
|
||||
expect(c.description_text).to eq("<hello test.")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -227,63 +227,63 @@ describe Category do
|
|||
end
|
||||
|
||||
it 'is created correctly' do
|
||||
@category.slug.should == 'amazing-category'
|
||||
@category.slug_for_url.should == @category.slug
|
||||
expect(@category.slug).to eq('amazing-category')
|
||||
expect(@category.slug_for_url).to eq(@category.slug)
|
||||
|
||||
@category.description.should be_blank
|
||||
expect(@category.description).to be_blank
|
||||
|
||||
Topic.where(category_id: @category).count.should == 1
|
||||
expect(Topic.where(category_id: @category).count).to eq(1)
|
||||
|
||||
@topic.should be_present
|
||||
expect(@topic).to be_present
|
||||
|
||||
@topic.category.should == @category
|
||||
expect(@topic.category).to eq(@category)
|
||||
|
||||
@topic.should be_visible
|
||||
expect(@topic).to be_visible
|
||||
|
||||
@topic.pinned_at.should be_present
|
||||
expect(@topic.pinned_at).to be_present
|
||||
|
||||
Guardian.new(@category.user).can_delete?(@topic).should == false
|
||||
expect(Guardian.new(@category.user).can_delete?(@topic)).to be false
|
||||
|
||||
@topic.posts.count.should == 1
|
||||
expect(@topic.posts.count).to eq(1)
|
||||
|
||||
@category.topic_url.should be_present
|
||||
expect(@category.topic_url).to be_present
|
||||
|
||||
@category.posts_week.should == 0
|
||||
@category.posts_month.should == 0
|
||||
@category.posts_year.should == 0
|
||||
expect(@category.posts_week).to eq(0)
|
||||
expect(@category.posts_month).to eq(0)
|
||||
expect(@category.posts_year).to eq(0)
|
||||
|
||||
@category.topics_week.should == 0
|
||||
@category.topics_month.should == 0
|
||||
@category.topics_year.should == 0
|
||||
expect(@category.topics_week).to eq(0)
|
||||
expect(@category.topics_month).to eq(0)
|
||||
expect(@category.topics_year).to eq(0)
|
||||
end
|
||||
|
||||
it "renames the definition when renamed" do
|
||||
@category.update_attributes(name: 'Troutfishing')
|
||||
@topic.reload
|
||||
@topic.title.should =~ /Troutfishing/
|
||||
expect(@topic.title).to match /Troutfishing/
|
||||
end
|
||||
|
||||
it "doesn't raise an error if there is no definition topic to rename (uncategorized)" do
|
||||
-> { @category.update_attributes(name: 'Troutfishing', topic_id: nil) }.should_not raise_error
|
||||
expect { @category.update_attributes(name: 'Troutfishing', topic_id: nil) }.to_not raise_error
|
||||
end
|
||||
|
||||
it "should not set its description topic to auto-close" do
|
||||
category = Fabricate(:category, name: 'Closing Topics', auto_close_hours: 1)
|
||||
category.topic.auto_close_at.should == nil
|
||||
expect(category.topic.auto_close_at).to be_nil
|
||||
end
|
||||
|
||||
describe "creating a new category with the same slug" do
|
||||
it "should have a blank slug if at the same level" do
|
||||
category = Fabricate(:category, name: "Amazing Categóry")
|
||||
category.slug.should be_blank
|
||||
category.slug_for_url.should == "#{category.id}-category"
|
||||
expect(category.slug).to be_blank
|
||||
expect(category.slug_for_url).to eq("#{category.id}-category")
|
||||
end
|
||||
|
||||
it "doesn't have a blank slug if not at the same level" do
|
||||
parent = Fabricate(:category, name: 'Other parent')
|
||||
category = Fabricate(:category, name: "Amazing Categóry", parent_category_id: parent.id)
|
||||
category.slug.should == 'amazing-category'
|
||||
category.slug_for_url.should == "amazing-category"
|
||||
expect(category.slug).to eq('amazing-category')
|
||||
expect(category.slug_for_url).to eq("amazing-category")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -296,9 +296,9 @@ describe Category do
|
|||
end
|
||||
|
||||
it 'does not cause changes' do
|
||||
@category.topic_count.should == 0
|
||||
@topic.category.should == @category
|
||||
@category.topic.should == @topic
|
||||
expect(@category.topic_count).to eq(0)
|
||||
expect(@topic.category).to eq(@category)
|
||||
expect(@category.topic).to eq(@topic)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -308,8 +308,8 @@ describe Category do
|
|||
Fabricate(:category, slug: "the-slug")
|
||||
c2 = Fabricate(:category, slug: "different-slug")
|
||||
c2.slug = "the-slug"
|
||||
c2.should_not be_valid
|
||||
c2.errors[:slug].should be_present
|
||||
expect(c2).to_not be_valid
|
||||
expect(c2.errors[:slug]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -322,8 +322,8 @@ describe Category do
|
|||
end
|
||||
|
||||
it 'is deleted correctly' do
|
||||
Category.exists?(id: @category_id).should == false
|
||||
Topic.exists?(id: @topic_id).should == false
|
||||
expect(Category.exists?(id: @category_id)).to be false
|
||||
expect(Topic.exists?(id: @topic_id)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -333,15 +333,15 @@ describe Category do
|
|||
post = create_post(category: category.name)
|
||||
|
||||
category.reload
|
||||
category.latest_post_id.should == post.id
|
||||
category.latest_topic_id.should == post.topic_id
|
||||
expect(category.latest_post_id).to eq(post.id)
|
||||
expect(category.latest_topic_id).to eq(post.topic_id)
|
||||
|
||||
post2 = create_post(category: category.name)
|
||||
post3 = create_post(topic_id: post.topic_id, category: category.name)
|
||||
|
||||
category.reload
|
||||
category.latest_post_id.should == post3.id
|
||||
category.latest_topic_id.should == post2.topic_id
|
||||
expect(category.latest_post_id).to eq(post3.id)
|
||||
expect(category.latest_topic_id).to eq(post2.topic_id)
|
||||
|
||||
post3.reload
|
||||
|
||||
|
@ -349,7 +349,7 @@ describe Category do
|
|||
destroyer.destroy
|
||||
|
||||
category.reload
|
||||
category.latest_post_id.should == post2.id
|
||||
expect(category.latest_post_id).to eq(post2.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -366,14 +366,14 @@ describe Category do
|
|||
end
|
||||
|
||||
it 'updates topic stats' do
|
||||
@category.topics_week.should == 1
|
||||
@category.topics_month.should == 1
|
||||
@category.topics_year.should == 1
|
||||
@category.topic_count.should == 1
|
||||
@category.post_count.should == 1
|
||||
@category.posts_year.should == 1
|
||||
@category.posts_month.should == 1
|
||||
@category.posts_week.should == 1
|
||||
expect(@category.topics_week).to eq(1)
|
||||
expect(@category.topics_month).to eq(1)
|
||||
expect(@category.topics_year).to eq(1)
|
||||
expect(@category.topic_count).to eq(1)
|
||||
expect(@category.post_count).to eq(1)
|
||||
expect(@category.posts_year).to eq(1)
|
||||
expect(@category.posts_month).to eq(1)
|
||||
expect(@category.posts_week).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -387,14 +387,14 @@ describe Category do
|
|||
end
|
||||
|
||||
it 'does not count deleted topics' do
|
||||
@category.topics_week.should == 0
|
||||
@category.topic_count.should == 0
|
||||
@category.topics_month.should == 0
|
||||
@category.topics_year.should == 0
|
||||
@category.post_count.should == 0
|
||||
@category.posts_year.should == 0
|
||||
@category.posts_month.should == 0
|
||||
@category.posts_week.should == 0
|
||||
expect(@category.topics_week).to eq(0)
|
||||
expect(@category.topic_count).to eq(0)
|
||||
expect(@category.topics_month).to eq(0)
|
||||
expect(@category.topics_year).to eq(0)
|
||||
expect(@category.post_count).to eq(0)
|
||||
expect(@category.posts_year).to eq(0)
|
||||
expect(@category.posts_month).to eq(0)
|
||||
expect(@category.posts_week).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -410,10 +410,10 @@ describe Category do
|
|||
end
|
||||
|
||||
it "doesn't count each version of a post" do
|
||||
@category.post_count.should == 1
|
||||
@category.posts_year.should == 1
|
||||
@category.posts_month.should == 1
|
||||
@category.posts_week.should == 1
|
||||
expect(@category.post_count).to eq(1)
|
||||
expect(@category.posts_year).to eq(1)
|
||||
expect(@category.posts_month).to eq(1)
|
||||
expect(@category.posts_week).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -426,14 +426,14 @@ describe Category do
|
|||
end
|
||||
|
||||
it 'updates topic stats' do
|
||||
@uncategorized.topics_week.should == 1
|
||||
@uncategorized.topics_month.should == 1
|
||||
@uncategorized.topics_year.should == 1
|
||||
@uncategorized.topic_count.should == 1
|
||||
@uncategorized.post_count.should == 1
|
||||
@uncategorized.posts_year.should == 1
|
||||
@uncategorized.posts_month.should == 1
|
||||
@uncategorized.posts_week.should == 1
|
||||
expect(@uncategorized.topics_week).to eq(1)
|
||||
expect(@uncategorized.topics_month).to eq(1)
|
||||
expect(@uncategorized.topics_year).to eq(1)
|
||||
expect(@uncategorized.topic_count).to eq(1)
|
||||
expect(@uncategorized.post_count).to eq(1)
|
||||
expect(@uncategorized.posts_year).to eq(1)
|
||||
expect(@uncategorized.posts_month).to eq(1)
|
||||
expect(@uncategorized.posts_week).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -458,12 +458,12 @@ describe Category do
|
|||
let(:cat) { Category.where(id: SiteSetting.uncategorized_category_id).first }
|
||||
|
||||
it "reports as `uncategorized?`" do
|
||||
cat.should be_uncategorized
|
||||
expect(cat).to be_uncategorized
|
||||
end
|
||||
|
||||
it "cannot have a parent category" do
|
||||
cat.parent_category_id = Fabricate(:category).id
|
||||
cat.should_not be_valid
|
||||
expect(cat).to_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -473,27 +473,26 @@ describe Category do
|
|||
|
||||
it "can be associated with a parent category" do
|
||||
sub_category = Fabricate.build(:category, parent_category_id: parent_category.id, user: user)
|
||||
sub_category.should be_valid
|
||||
sub_category.parent_category.should == parent_category
|
||||
expect(sub_category).to be_valid
|
||||
expect(sub_category.parent_category).to eq(parent_category)
|
||||
end
|
||||
|
||||
it "cannot associate a category with itself" do
|
||||
category = Fabricate(:category, user: user)
|
||||
category.parent_category_id = category.id
|
||||
category.should_not be_valid
|
||||
expect(category).to_not be_valid
|
||||
end
|
||||
|
||||
it "cannot have a category two levels deep" do
|
||||
sub_category = Fabricate(:category, parent_category_id: parent_category.id, user: user)
|
||||
nested_sub_category = Fabricate.build(:category, parent_category_id: sub_category.id, user: user)
|
||||
nested_sub_category.should_not be_valid
|
||||
|
||||
expect(nested_sub_category).to_not be_valid
|
||||
end
|
||||
|
||||
describe ".query_parent_category" do
|
||||
it "should return the parent category id given a parent slug" do
|
||||
parent_category.name = "Amazing Category"
|
||||
parent_category.id.should == Category.query_parent_category(parent_category.slug)
|
||||
expect(parent_category.id).to eq(Category.query_parent_category(parent_category.slug))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -501,7 +500,7 @@ describe Category do
|
|||
it "should return the category" do
|
||||
category = Fabricate(:category, name: "Amazing Category", parent_category_id: parent_category.id, user: user)
|
||||
parent_category.name = "Amazing Parent Category"
|
||||
category.should == Category.query_category(category.slug, parent_category.id)
|
||||
expect(category).to eq(Category.query_category(category.slug, parent_category.id))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -512,10 +511,10 @@ describe Category do
|
|||
c1 = Fabricate(:category, email_in: 'lower@example.com')
|
||||
c2 = Fabricate(:category, email_in: 'UPPER@EXAMPLE.COM')
|
||||
c3 = Fabricate(:category, email_in: 'Mixed.Case@Example.COM')
|
||||
Category.find_by_email('LOWER@EXAMPLE.COM').should == c1
|
||||
Category.find_by_email('upper@example.com').should == c2
|
||||
Category.find_by_email('mixed.case@example.com').should == c3
|
||||
Category.find_by_email('MIXED.CASE@EXAMPLE.COM').should == c3
|
||||
expect(Category.find_by_email('LOWER@EXAMPLE.COM')).to eq(c1)
|
||||
expect(Category.find_by_email('upper@example.com')).to eq(c2)
|
||||
expect(Category.find_by_email('mixed.case@example.com')).to eq(c3)
|
||||
expect(Category.find_by_email('MIXED.CASE@EXAMPLE.COM')).to eq(c3)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,13 +13,13 @@ describe CategoryUser do
|
|||
watching = CategoryUser.where(user_id: user.id, notification_level: CategoryUser.notification_levels[:watching])
|
||||
|
||||
CategoryUser.batch_set(user, :watching, [category1.id, category2.id])
|
||||
watching.pluck(:category_id).sort.should == [category1.id, category2.id]
|
||||
expect(watching.pluck(:category_id).sort).to eq [category1.id, category2.id]
|
||||
|
||||
CategoryUser.batch_set(user, :watching, [])
|
||||
watching.count.should == 0
|
||||
expect(watching.count).to eq 0
|
||||
|
||||
CategoryUser.batch_set(user, :watching, [category2.id])
|
||||
watching.count.should == 1
|
||||
expect(watching.count).to eq 1
|
||||
end
|
||||
|
||||
|
||||
|
@ -43,14 +43,15 @@ describe CategoryUser do
|
|||
muted_post = create_post(category: muted_category)
|
||||
tracked_post = create_post(category: tracked_category)
|
||||
|
||||
Notification.where(user_id: user.id, topic_id: watched_post.topic_id).count.should == 1
|
||||
Notification.where(user_id: user.id, topic_id: tracked_post.topic_id).count.should == 0
|
||||
expect(Notification.where(user_id: user.id, topic_id: watched_post.topic_id).count).to eq 1
|
||||
expect(Notification.where(user_id: user.id, topic_id: tracked_post.topic_id).count).to eq 0
|
||||
|
||||
tu = TopicUser.get(tracked_post.topic, user)
|
||||
tu.notification_level.should == TopicUser.notification_levels[:tracking]
|
||||
tu.notifications_reason_id.should == TopicUser.notification_reasons[:auto_track_category]
|
||||
expect(tu.notification_level).to eq TopicUser.notification_levels[:tracking]
|
||||
expect(tu.notifications_reason_id).to eq TopicUser.notification_reasons[:auto_track_category]
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,13 +3,13 @@ require 'spec_helper'
|
|||
describe ColorSchemeColor do
|
||||
def test_invalid_hex(hex)
|
||||
c = described_class.new(hex: hex)
|
||||
c.should_not be_valid
|
||||
c.errors[:hex].should be_present
|
||||
expect(c).not_to be_valid
|
||||
expect(c.errors[:hex]).to be_present
|
||||
end
|
||||
|
||||
it "validates hex value" do
|
||||
['fff', 'ffffff', '333333', '333', '0BeeF0'].each do |hex|
|
||||
described_class.new(hex: hex).should be_valid
|
||||
expect(described_class.new(hex: hex)).to be_valid
|
||||
end
|
||||
['fffff', 'ffff', 'ff', 'f', '00000', '00', 'cheese', '#666666', '#666', '555 666'].each do |hex|
|
||||
test_invalid_hex(hex)
|
||||
|
|
|
@ -11,10 +11,10 @@ describe ColorScheme do
|
|||
describe "new" do
|
||||
it "can take colors" do
|
||||
c = described_class.new(valid_params)
|
||||
c.colors.size.should == valid_colors.size
|
||||
c.colors.first.should be_a(ColorSchemeColor)
|
||||
expect(c.colors.size).to eq valid_colors.size
|
||||
expect(c.colors.first).to be_a(ColorSchemeColor)
|
||||
expect {
|
||||
c.save.should == true
|
||||
expect(c.save).to eq true
|
||||
}.to change { ColorSchemeColor.count }.by(valid_colors.size)
|
||||
end
|
||||
end
|
||||
|
@ -32,22 +32,22 @@ describe ColorScheme do
|
|||
|
||||
it "creates a new color scheme" do
|
||||
c = described_class.create_from_base(name: 'Yellow', colors: {first_one: 'FFFF00', third_one: 'F00D33'})
|
||||
c.colors.size.should == base_colors.size
|
||||
expect(c.colors.size).to eq base_colors.size
|
||||
first = c.colors.find {|x| x.name == 'first_one'}
|
||||
second = c.colors.find {|x| x.name == 'second_one'}
|
||||
third = c.colors.find {|x| x.name == 'third_one'}
|
||||
first.hex.should == 'FFFF00'
|
||||
second.hex.should == base_colors[:second_one]
|
||||
third.hex.should == 'F00D33'
|
||||
expect(first.hex).to eq 'FFFF00'
|
||||
expect(second.hex).to eq base_colors[:second_one]
|
||||
expect(third.hex).to eq 'F00D33'
|
||||
end
|
||||
|
||||
context "hex_for_name without anything enabled" do
|
||||
it "returns nil for a missing attribute" do
|
||||
described_class.hex_for_name('undefined').should == nil
|
||||
expect(described_class.hex_for_name('undefined')).to eq nil
|
||||
end
|
||||
|
||||
it "returns the base color for an attribute" do
|
||||
described_class.hex_for_name('second_one').should == base_colors[:second_one]
|
||||
expect(described_class.hex_for_name('second_one')).to eq base_colors[:second_one]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -65,14 +65,14 @@ describe ColorScheme do
|
|||
|
||||
describe "#enabled" do
|
||||
it "returns nil when there is no enabled record" do
|
||||
described_class.enabled.should == nil
|
||||
expect(described_class.enabled).to eq nil
|
||||
end
|
||||
|
||||
it "returns the enabled color scheme" do
|
||||
described_class.hex_for_name('$primary_background_color').should == nil
|
||||
expect(described_class.hex_for_name('$primary_background_color')).to eq nil
|
||||
c = described_class.create(valid_params.merge(enabled: true))
|
||||
described_class.enabled.id.should == c.id
|
||||
described_class.hex_for_name('$primary_background_color').should == "FFBB00"
|
||||
expect(described_class.enabled.id).to eq c.id
|
||||
expect(described_class.hex_for_name('$primary_background_color')).to eq "FFBB00"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,16 +3,16 @@ require 'spec_helper'
|
|||
describe DigestEmailSiteSetting do
|
||||
describe 'valid_value?' do
|
||||
it 'returns true for a valid value as an int' do
|
||||
DigestEmailSiteSetting.valid_value?(1).should == true
|
||||
expect(DigestEmailSiteSetting.valid_value?(1)).to eq true
|
||||
end
|
||||
|
||||
it 'returns true for a valid value as a string' do
|
||||
DigestEmailSiteSetting.valid_value?('1').should == true
|
||||
expect(DigestEmailSiteSetting.valid_value?('1')).to eq true
|
||||
end
|
||||
|
||||
it 'returns false for an invalid value' do
|
||||
DigestEmailSiteSetting.valid_value?(1.5).should == false
|
||||
DigestEmailSiteSetting.valid_value?('7 dogs').should == false
|
||||
expect(DigestEmailSiteSetting.valid_value?(1.5)).to eq false
|
||||
expect(DigestEmailSiteSetting.valid_value?('7 dogs')).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,13 +25,13 @@ describe DiscourseSingleSignOn do
|
|||
end
|
||||
|
||||
def test_parsed(parsed, sso)
|
||||
parsed.nonce.should == sso.nonce
|
||||
parsed.email.should == sso.email
|
||||
parsed.username.should == sso.username
|
||||
parsed.name.should == sso.name
|
||||
parsed.external_id.should == sso.external_id
|
||||
parsed.custom_fields["a"].should == "Aa"
|
||||
parsed.custom_fields["b.b"].should == "B.b"
|
||||
expect(parsed.nonce).to eq sso.nonce
|
||||
expect(parsed.email).to eq sso.email
|
||||
expect(parsed.username).to eq sso.username
|
||||
expect(parsed.name).to eq sso.name
|
||||
expect(parsed.external_id).to eq sso.external_id
|
||||
expect(parsed.custom_fields["a"]).to eq "Aa"
|
||||
expect(parsed.custom_fields["b.b"]).to eq "B.b"
|
||||
end
|
||||
|
||||
it "can do round trip parsing correctly" do
|
||||
|
@ -43,9 +43,9 @@ describe DiscourseSingleSignOn do
|
|||
|
||||
sso = SingleSignOn.parse(sso.payload, "test")
|
||||
|
||||
sso.name.should == "sam saffron"
|
||||
sso.username.should == "sam"
|
||||
sso.email.should == "sam@sam.com"
|
||||
expect(sso.name).to eq "sam saffron"
|
||||
expect(sso.username).to eq "sam"
|
||||
expect(sso.email).to eq "sam@sam.com"
|
||||
end
|
||||
|
||||
it "can lookup or create user when name is blank" do
|
||||
|
@ -57,14 +57,14 @@ describe DiscourseSingleSignOn do
|
|||
sso.email = "test@test.com"
|
||||
sso.external_id = "A"
|
||||
user = sso.lookup_or_create_user
|
||||
user.should_not == nil
|
||||
expect(user).to_not be_nil
|
||||
end
|
||||
|
||||
it "can fill in data on way back" do
|
||||
sso = make_sso
|
||||
|
||||
url, payload = sso.to_url.split("?")
|
||||
url.should == sso.sso_url
|
||||
expect(url).to eq sso.sso_url
|
||||
parsed = SingleSignOn.parse(payload, "supersecret")
|
||||
|
||||
test_parsed(parsed, sso)
|
||||
|
@ -74,10 +74,10 @@ describe DiscourseSingleSignOn do
|
|||
sso = make_sso
|
||||
sso.sso_url = "http://tcdev7.wpengine.com/?action=showlogin"
|
||||
|
||||
sso.to_url.split('?').size.should == 2
|
||||
expect(sso.to_url.split('?').size).to eq 2
|
||||
|
||||
url, payload = sso.to_url.split("?")
|
||||
url.should == "http://tcdev7.wpengine.com/"
|
||||
expect(url).to eq "http://tcdev7.wpengine.com/"
|
||||
parsed = SingleSignOn.parse(payload, "supersecret")
|
||||
|
||||
test_parsed(parsed, sso)
|
||||
|
@ -87,20 +87,20 @@ describe DiscourseSingleSignOn do
|
|||
_ , payload = DiscourseSingleSignOn.generate_url.split("?")
|
||||
|
||||
sso = DiscourseSingleSignOn.parse(payload)
|
||||
sso.nonce_valid?.should == true
|
||||
expect(sso.nonce_valid?).to eq true
|
||||
|
||||
sso.expire_nonce!
|
||||
|
||||
sso.nonce_valid?.should == false
|
||||
expect(sso.nonce_valid?).to eq false
|
||||
|
||||
end
|
||||
|
||||
it "generates a correct sso url" do
|
||||
|
||||
url, payload = DiscourseSingleSignOn.generate_url.split("?")
|
||||
url.should == @sso_url
|
||||
expect(url).to eq @sso_url
|
||||
|
||||
sso = DiscourseSingleSignOn.parse(payload)
|
||||
sso.nonce.should_not == nil
|
||||
expect(sso.nonce).to_not be_nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,12 +3,12 @@ require 'spec_helper'
|
|||
describe DraftSequence do
|
||||
it 'should produce next sequence for a key' do
|
||||
u = Fabricate(:user)
|
||||
DraftSequence.next!(u, 'test').should == 1
|
||||
DraftSequence.next!(u, 'test').should == 2
|
||||
expect(DraftSequence.next!(u, 'test')).to eq 1
|
||||
expect(DraftSequence.next!(u, 'test')).to eq 2
|
||||
end
|
||||
|
||||
it 'should return 0 by default' do
|
||||
u = Fabricate(:user)
|
||||
DraftSequence.current(u, 'test').should == 0
|
||||
expect(DraftSequence.current(u, 'test')).to eq 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,32 +6,32 @@ describe Draft do
|
|||
end
|
||||
it "can get a draft by user" do
|
||||
Draft.set(@user, "test", 0, "data")
|
||||
Draft.get(@user, "test", 0).should == "data"
|
||||
expect(Draft.get(@user, "test", 0)).to eq "data"
|
||||
end
|
||||
|
||||
it "uses the user id and key correctly" do
|
||||
Draft.set(@user, "test", 0,"data")
|
||||
Draft.get(Fabricate.build(:coding_horror), "test", 0).should == nil
|
||||
expect(Draft.get(Fabricate.build(:coding_horror), "test", 0)).to eq nil
|
||||
end
|
||||
|
||||
it "should overwrite draft data correctly" do
|
||||
Draft.set(@user, "test", 0, "data")
|
||||
Draft.set(@user, "test", 0, "new data")
|
||||
Draft.get(@user, "test", 0).should == "new data"
|
||||
expect(Draft.get(@user, "test", 0)).to eq "new data"
|
||||
end
|
||||
|
||||
it "should clear drafts on request" do
|
||||
Draft.set(@user, "test", 0, "data")
|
||||
Draft.clear(@user, "test", 0)
|
||||
Draft.get(@user, "test", 0).should == nil
|
||||
expect(Draft.get(@user, "test", 0)).to eq nil
|
||||
end
|
||||
|
||||
it "should disregard old draft if sequence decreases" do
|
||||
Draft.set(@user, "test", 0, "data")
|
||||
Draft.set(@user, "test", 1, "hello")
|
||||
Draft.set(@user, "test", 0, "foo")
|
||||
Draft.get(@user, "test", 0).should == nil
|
||||
Draft.get(@user, "test", 1).should == "hello"
|
||||
expect(Draft.get(@user, "test", 0)).to eq nil
|
||||
expect(Draft.get(@user, "test", 1)).to eq "hello"
|
||||
end
|
||||
|
||||
|
||||
|
@ -41,7 +41,7 @@ describe Draft do
|
|||
Draft.set(u, Draft::NEW_TOPIC, 0, 'my draft')
|
||||
_t = Fabricate(:topic, user: u)
|
||||
s = DraftSequence.current(u, Draft::NEW_TOPIC)
|
||||
Draft.get(u, Draft::NEW_TOPIC, s).should == nil
|
||||
expect(Draft.get(u, Draft::NEW_TOPIC, s)).to eq nil
|
||||
end
|
||||
|
||||
it 'nukes new pm draft after a pm is created' do
|
||||
|
@ -49,7 +49,7 @@ describe Draft do
|
|||
Draft.set(u, Draft::NEW_PRIVATE_MESSAGE, 0, 'my draft')
|
||||
t = Fabricate(:topic, user: u, archetype: Archetype.private_message, category_id: nil)
|
||||
s = DraftSequence.current(t.user, Draft::NEW_PRIVATE_MESSAGE)
|
||||
Draft.get(u, Draft::NEW_PRIVATE_MESSAGE, s).should == nil
|
||||
expect(Draft.get(u, Draft::NEW_PRIVATE_MESSAGE, s)).to eq nil
|
||||
end
|
||||
|
||||
it 'does not nuke new topic draft after a pm is created' do
|
||||
|
@ -57,7 +57,7 @@ describe Draft do
|
|||
Draft.set(u, Draft::NEW_TOPIC, 0, 'my draft')
|
||||
t = Fabricate(:topic, user: u, archetype: Archetype.private_message, category_id: nil)
|
||||
s = DraftSequence.current(t.user, Draft::NEW_TOPIC)
|
||||
Draft.get(u, Draft::NEW_TOPIC, s).should == 'my draft'
|
||||
expect(Draft.get(u, Draft::NEW_TOPIC, s)).to eq 'my draft'
|
||||
end
|
||||
|
||||
it 'nukes the post draft when a post is created' do
|
||||
|
@ -67,7 +67,7 @@ describe Draft do
|
|||
Draft.set(p.user, p.topic.draft_key, 0,'hello')
|
||||
|
||||
PostCreator.new(user, raw: Fabricate.build(:post).raw).create
|
||||
Draft.get(p.user, p.topic.draft_key, DraftSequence.current(p.user, p.topic.draft_key)).should == nil
|
||||
expect(Draft.get(p.user, p.topic.draft_key, DraftSequence.current(p.user, p.topic.draft_key))).to eq nil
|
||||
end
|
||||
|
||||
it 'nukes the post draft when a post is revised' do
|
||||
|
@ -75,10 +75,9 @@ describe Draft do
|
|||
Draft.set(p.user, p.topic.draft_key, 0,'hello')
|
||||
p.revise(p.user, { raw: 'another test' })
|
||||
s = DraftSequence.current(p.user, p.topic.draft_key)
|
||||
Draft.get(p.user, p.topic.draft_key, s).should == nil
|
||||
expect(Draft.get(p.user, p.topic.draft_key, s)).to eq nil
|
||||
end
|
||||
|
||||
it 'increases the sequence number when a post is revised' do
|
||||
end
|
||||
it 'increases the sequence number when a post is revised'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,19 +2,19 @@ require 'spec_helper'
|
|||
|
||||
describe EmailLog do
|
||||
|
||||
it { should belong_to :user }
|
||||
it { should validate_presence_of :to_address }
|
||||
it { should validate_presence_of :email_type }
|
||||
it { is_expected.to belong_to :user }
|
||||
it { is_expected.to validate_presence_of :to_address }
|
||||
it { is_expected.to validate_presence_of :email_type }
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
context 'after_create' do
|
||||
context 'with user' do
|
||||
it 'updates the last_emailed_at value for the user' do
|
||||
lambda {
|
||||
expect {
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email)
|
||||
user.reload
|
||||
}.should change(user, :last_emailed_at)
|
||||
}.to change(user, :last_emailed_at)
|
||||
end
|
||||
|
||||
it "doesn't update last_emailed_at if skipped is true" do
|
||||
|
@ -30,7 +30,7 @@ describe EmailLog do
|
|||
it "counts sent emails" do
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email)
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, skipped: true)
|
||||
described_class.count_per_day(1.day.ago, Time.now).first[1].should == 1
|
||||
expect(described_class.count_per_day(1.day.ago, Time.now).first[1]).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@ require 'spec_helper'
|
|||
|
||||
describe EmailToken do
|
||||
|
||||
it { should validate_presence_of :user_id }
|
||||
it { should validate_presence_of :email }
|
||||
it { should belong_to :user }
|
||||
it { is_expected.to validate_presence_of :user_id }
|
||||
it { is_expected.to validate_presence_of :email }
|
||||
it { is_expected.to belong_to :user }
|
||||
|
||||
|
||||
context '#create' do
|
||||
|
@ -13,64 +13,62 @@ describe EmailToken do
|
|||
let!(:email_token) { user.email_tokens.create(email: 'bubblegum@adevnturetime.ooo') }
|
||||
|
||||
it 'should create the email token' do
|
||||
email_token.should be_present
|
||||
expect(email_token).to be_present
|
||||
end
|
||||
|
||||
it 'should downcase the email' do
|
||||
token = user.email_tokens.create(email: "UpperCaseSoWoW@GMail.com")
|
||||
token.email.should == "uppercasesowow@gmail.com"
|
||||
expect(token.email).to eq "uppercasesowow@gmail.com"
|
||||
end
|
||||
|
||||
it 'is valid' do
|
||||
email_token.should be_valid
|
||||
expect(email_token).to be_valid
|
||||
end
|
||||
|
||||
it 'has a token' do
|
||||
email_token.token.should be_present
|
||||
expect(email_token.token).to be_present
|
||||
end
|
||||
|
||||
it 'is not confirmed' do
|
||||
email_token.should_not be_confirmed
|
||||
expect(email_token).to_not be_confirmed
|
||||
end
|
||||
|
||||
it 'is not expired' do
|
||||
email_token.should_not be_expired
|
||||
expect(email_token).to_not be_expired
|
||||
end
|
||||
|
||||
it 'marks the older token as expired' do
|
||||
original_token.reload
|
||||
original_token.should be_expired
|
||||
expect(original_token).to be_expired
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
context '#confirm' do
|
||||
|
||||
let(:user) { Fabricate(:user, active: false) }
|
||||
let(:email_token) { user.email_tokens.first }
|
||||
|
||||
it 'returns nil with a nil token' do
|
||||
EmailToken.confirm(nil).should be_blank
|
||||
expect(EmailToken.confirm(nil)).to be_blank
|
||||
end
|
||||
|
||||
it 'returns nil with a made up token' do
|
||||
EmailToken.confirm(EmailToken.generate_token).should be_blank
|
||||
expect(EmailToken.confirm(EmailToken.generate_token)).to be_blank
|
||||
end
|
||||
|
||||
it 'returns nil unless the token is the right length' do
|
||||
EmailToken.confirm('a').should be_blank
|
||||
expect(EmailToken.confirm('a')).to be_blank
|
||||
end
|
||||
|
||||
it 'returns nil when a token is expired' do
|
||||
email_token.update_column(:expired, true)
|
||||
EmailToken.confirm(email_token.token).should be_blank
|
||||
expect(EmailToken.confirm(email_token.token)).to be_blank
|
||||
end
|
||||
|
||||
it 'returns nil when a token is older than a specific time' do
|
||||
SiteSetting.email_token_valid_hours = 10
|
||||
email_token.update_column(:created_at, 11.hours.ago)
|
||||
EmailToken.confirm(email_token.token).should be_blank
|
||||
expect(EmailToken.confirm(email_token.token)).to be_blank
|
||||
end
|
||||
|
||||
context 'taken email address' do
|
||||
|
@ -81,7 +79,7 @@ describe EmailToken do
|
|||
end
|
||||
|
||||
it 'returns nil when the email has been taken since the token has been generated' do
|
||||
EmailToken.confirm(email_token.token).should be_blank
|
||||
expect(EmailToken.confirm(email_token.token)).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -89,7 +87,7 @@ describe EmailToken do
|
|||
context 'welcome message' do
|
||||
it 'sends a welcome message when the user is activated' do
|
||||
user = EmailToken.confirm(email_token.token)
|
||||
user.send_welcome_message.should == true
|
||||
expect(user.send_welcome_message).to eq true
|
||||
end
|
||||
|
||||
context "when using the code a second time" do
|
||||
|
@ -98,7 +96,7 @@ describe EmailToken do
|
|||
SiteSetting.email_token_grace_period_hours = 1
|
||||
EmailToken.confirm(email_token.token)
|
||||
user = EmailToken.confirm(email_token.token)
|
||||
user.send_welcome_message.should == false
|
||||
expect(user.send_welcome_message).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -109,34 +107,30 @@ describe EmailToken do
|
|||
let!(:confirmed_user) { EmailToken.confirm(email_token.token) }
|
||||
|
||||
it "returns the correct user" do
|
||||
confirmed_user.should == user
|
||||
expect(confirmed_user).to eq user
|
||||
end
|
||||
|
||||
it 'marks the user as active' do
|
||||
confirmed_user.reload
|
||||
confirmed_user.should be_active
|
||||
expect(confirmed_user).to be_active
|
||||
end
|
||||
|
||||
it 'marks the token as confirmed' do
|
||||
email_token.reload
|
||||
email_token.should be_confirmed
|
||||
expect(email_token).to be_confirmed
|
||||
end
|
||||
|
||||
it "can be confirmed again" do
|
||||
EmailToken.stubs(:confirm_valid_after).returns(1.hour.ago)
|
||||
|
||||
EmailToken.confirm(email_token.token).should == user
|
||||
expect(EmailToken.confirm(email_token.token)).to eq user
|
||||
|
||||
# Unless `confirm_valid_after` has passed
|
||||
EmailToken.stubs(:confirm_valid_after).returns(1.hour.from_now)
|
||||
EmailToken.confirm(email_token.token).should be_blank
|
||||
expect(EmailToken.confirm(email_token.token)).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ describe ErrorLog do
|
|||
it "creates a non empty file on first call" do
|
||||
ErrorLog.clear_all!
|
||||
ErrorLog.add_row!(hello: "world")
|
||||
File.exists?(ErrorLog.filename).should == true
|
||||
expect(File.exists?(ErrorLog.filename)).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,7 +38,7 @@ describe ErrorLog do
|
|||
ErrorLog.each do |h|
|
||||
i += 1
|
||||
end
|
||||
i.should == 2
|
||||
expect(i).to eq 2
|
||||
end
|
||||
|
||||
it "is able to skip rows" do
|
||||
|
@ -51,7 +51,7 @@ describe ErrorLog do
|
|||
ErrorLog.skip(3) do |h|
|
||||
i += 1
|
||||
end
|
||||
i.should == 1
|
||||
expect(i).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'tempfile'
|
|||
describe GlobalSetting::EnvProvider do
|
||||
it "can detect keys from env" do
|
||||
ENV['DISCOURSE_BLA'] = '1'
|
||||
GlobalSetting::EnvProvider.new.keys.should include(:bla)
|
||||
expect(GlobalSetting::EnvProvider.new.keys).to include(:bla)
|
||||
end
|
||||
end
|
||||
describe GlobalSetting::FileProvider do
|
||||
|
@ -20,13 +20,13 @@ describe GlobalSetting::FileProvider do
|
|||
|
||||
provider = GlobalSetting::FileProvider.from(f.path)
|
||||
|
||||
provider.lookup(:a,"").should == 1000
|
||||
provider.lookup(:b,"").should == "10 # = 00"
|
||||
provider.lookup(:c,"").should == "10 # = 00"
|
||||
provider.lookup(:d,"bob").should == nil
|
||||
provider.lookup(:e,"bob").should == "bob"
|
||||
expect(provider.lookup(:a,"")).to eq 1000
|
||||
expect(provider.lookup(:b,"")).to eq "10 # = 00"
|
||||
expect(provider.lookup(:c,"")).to eq "10 # = 00"
|
||||
expect(provider.lookup(:d,"bob")).to eq nil
|
||||
expect(provider.lookup(:e,"bob")).to eq "bob"
|
||||
|
||||
provider.keys.sort.should == [:a, :b, :c, :d]
|
||||
expect(provider.keys.sort).to eq [:a, :b, :c, :d]
|
||||
|
||||
f.unlink
|
||||
end
|
||||
|
@ -38,7 +38,7 @@ describe GlobalSetting::FileProvider do
|
|||
|
||||
provider = GlobalSetting::FileProvider.from(f.path)
|
||||
|
||||
provider.lookup(:a,"").should == 500
|
||||
expect(provider.lookup(:a,"")).to eq 500
|
||||
|
||||
f.unlink
|
||||
end
|
||||
|
|
|
@ -15,23 +15,23 @@ describe Group do
|
|||
|
||||
it "is invalid for blank" do
|
||||
group.name = ""
|
||||
group.valid?.should == false
|
||||
expect(group.valid?).to eq false
|
||||
end
|
||||
|
||||
it "is valid for a longer name" do
|
||||
group.name = "this_is_a_name"
|
||||
group.valid?.should == true
|
||||
expect(group.valid?).to eq true
|
||||
end
|
||||
|
||||
it "is invalid for non names" do
|
||||
group.name = "this is_a_name"
|
||||
group.valid?.should == false
|
||||
expect(group.valid?).to eq false
|
||||
end
|
||||
|
||||
it "is invalid for case-insensitive existing names" do
|
||||
build(:group, name: 'this_is_a_name').save
|
||||
group.name = 'This_Is_A_Name'
|
||||
group.valid?.should == false
|
||||
expect(group.valid?).to eq false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,52 +54,52 @@ describe Group do
|
|||
|
||||
Group.refresh_automatic_groups!(:admins, :staff, :moderators)
|
||||
|
||||
real_admins.should == [admin.id]
|
||||
real_moderators.should == [moderator.id]
|
||||
real_staff.sort.should == [moderator.id,admin.id].sort
|
||||
expect(real_admins).to eq [admin.id]
|
||||
expect(real_moderators).to eq [moderator.id]
|
||||
expect(real_staff.sort).to eq [moderator.id,admin.id].sort
|
||||
|
||||
admin.admin = false
|
||||
admin.save
|
||||
|
||||
Group.refresh_automatic_group!(:admins)
|
||||
real_admins.should == []
|
||||
expect(real_admins).to be_empty
|
||||
|
||||
moderator.revoke_moderation!
|
||||
|
||||
admin.grant_admin!
|
||||
real_admins.should == [admin.id]
|
||||
real_staff.should == [admin.id]
|
||||
expect(real_admins).to eq [admin.id]
|
||||
expect(real_staff).to eq [admin.id]
|
||||
|
||||
admin.revoke_admin!
|
||||
real_admins.should == []
|
||||
real_staff.should == []
|
||||
expect(real_admins).to be_empty
|
||||
expect(real_staff).to be_empty
|
||||
|
||||
admin.grant_moderation!
|
||||
real_moderators.should == [admin.id]
|
||||
real_staff.should == [admin.id]
|
||||
expect(real_moderators).to eq [admin.id]
|
||||
expect(real_staff).to eq [admin.id]
|
||||
|
||||
admin.revoke_moderation!
|
||||
real_admins.should == []
|
||||
real_staff.should == []
|
||||
expect(real_admins).to be_empty
|
||||
expect(real_staff).to eq []
|
||||
end
|
||||
|
||||
it "Correctly updates automatic trust level groups" do
|
||||
user = Fabricate(:user)
|
||||
Group[:trust_level_0].user_ids.should include user.id
|
||||
expect(Group[:trust_level_0].user_ids).to include user.id
|
||||
|
||||
user.change_trust_level!(TrustLevel[1])
|
||||
|
||||
Group[:trust_level_1].user_ids.should include user.id
|
||||
expect(Group[:trust_level_1].user_ids).to include user.id
|
||||
|
||||
user.change_trust_level!(TrustLevel[2])
|
||||
|
||||
Group[:trust_level_1].user_ids.should include user.id
|
||||
Group[:trust_level_2].user_ids.should include user.id
|
||||
expect(Group[:trust_level_1].user_ids).to include user.id
|
||||
expect(Group[:trust_level_2].user_ids).to include user.id
|
||||
|
||||
user2 = Fabricate(:coding_horror)
|
||||
user2.change_trust_level!(TrustLevel[3])
|
||||
|
||||
Group[:trust_level_2].user_ids.sort.should == [-1, user.id, user2.id].sort
|
||||
expect(Group[:trust_level_2].user_ids.sort).to eq [-1, user.id, user2.id].sort
|
||||
end
|
||||
|
||||
it "Correctly updates all automatic groups upon request" do
|
||||
|
@ -112,26 +112,25 @@ describe Group do
|
|||
Group.refresh_automatic_groups!
|
||||
|
||||
groups = Group.includes(:users).to_a
|
||||
groups.count.should == Group::AUTO_GROUPS.count
|
||||
expect(groups.count).to eq Group::AUTO_GROUPS.count
|
||||
|
||||
g = groups.find{|g| g.id == Group::AUTO_GROUPS[:admins]}
|
||||
g.users.count.should == 2
|
||||
g.user_count.should == 2
|
||||
expect(g.users.count).to eq 2
|
||||
expect(g.user_count).to eq 2
|
||||
|
||||
g = groups.find{|g| g.id == Group::AUTO_GROUPS[:staff]}
|
||||
g.users.count.should == 2
|
||||
g.user_count.should == 2
|
||||
|
||||
expect(g.users.count).to eq 2
|
||||
expect(g.user_count).to eq 2
|
||||
|
||||
g = groups.find{|g| g.id == Group::AUTO_GROUPS[:trust_level_1]}
|
||||
# admin, system and user
|
||||
g.users.count.should == 3
|
||||
g.user_count.should == 3
|
||||
expect(g.users.count).to eq 3
|
||||
expect(g.user_count).to eq 3
|
||||
|
||||
g = groups.find{|g| g.id == Group::AUTO_GROUPS[:trust_level_2]}
|
||||
# system and user
|
||||
g.users.count.should == 2
|
||||
g.user_count.should == 2
|
||||
expect(g.users.count).to eq 2
|
||||
expect(g.user_count).to eq 2
|
||||
|
||||
end
|
||||
|
||||
|
@ -149,12 +148,12 @@ describe Group do
|
|||
# no side effects please
|
||||
g.usernames = usernames
|
||||
g.reload
|
||||
g.users.count.should == 1
|
||||
expect(g.users.count).to eq 1
|
||||
|
||||
g.usernames = usernames
|
||||
g.save!
|
||||
|
||||
g.usernames.split(",").sort.should == usernames.split(",").sort
|
||||
expect(g.usernames.split(",").sort).to eq usernames.split(",").sort
|
||||
end
|
||||
|
||||
it "correctly destroys groups" do
|
||||
|
@ -166,31 +165,31 @@ describe Group do
|
|||
|
||||
g.destroy
|
||||
|
||||
User.where(id: u1.id).count.should == 1
|
||||
GroupUser.where(group_id: g.id).count.should == 0
|
||||
expect(User.where(id: u1.id).count).to eq 1
|
||||
expect(GroupUser.where(group_id: g.id).count).to eq 0
|
||||
end
|
||||
|
||||
|
||||
it "has custom fields" do
|
||||
group = Fabricate(:group)
|
||||
group.custom_fields["a"].should == nil
|
||||
expect(group.custom_fields["a"]).to be_nil
|
||||
|
||||
group.custom_fields["hugh"] = "jackman"
|
||||
group.custom_fields["jack"] = "black"
|
||||
group.save
|
||||
|
||||
group = Group.find(group.id)
|
||||
group.custom_fields.should == {"hugh" => "jackman", "jack" => "black"}
|
||||
expect(group.custom_fields).to eq({"hugh" => "jackman", "jack" => "black"})
|
||||
end
|
||||
|
||||
it "allows you to lookup a new group by name" do
|
||||
group = Fabricate(:group)
|
||||
group.id.should == Group[group.name].id
|
||||
group.id.should == Group[group.name.to_sym].id
|
||||
expect(group.id).to eq Group[group.name].id
|
||||
expect(group.id).to eq Group[group.name.to_sym].id
|
||||
end
|
||||
|
||||
it "can find desired groups correctly" do
|
||||
Group.desired_trust_level_groups(2).sort.should == [10,11,12]
|
||||
expect(Group.desired_trust_level_groups(2).sort).to eq [10,11,12]
|
||||
end
|
||||
|
||||
|
||||
|
@ -198,11 +197,11 @@ describe Group do
|
|||
user = Fabricate(:user, trust_level: 2)
|
||||
Group.user_trust_level_change!(user.id, 2)
|
||||
|
||||
user.groups.map(&:name).sort.should == ["trust_level_0","trust_level_1", "trust_level_2"]
|
||||
expect(user.groups.map(&:name).sort).to eq ["trust_level_0","trust_level_1", "trust_level_2"]
|
||||
|
||||
Group.user_trust_level_change!(user.id, 0)
|
||||
user.reload
|
||||
user.groups.map(&:name).sort.should == ["trust_level_0"]
|
||||
expect(user.groups.map(&:name).sort).to eq ["trust_level_0"]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -15,14 +15,14 @@ describe IncomingLink do
|
|||
it "increases the incoming link counts" do
|
||||
link = incoming_link
|
||||
|
||||
link.domain.should == "twitter.com"
|
||||
link.post_id.should == post.id
|
||||
expect(link.domain).to eq "twitter.com"
|
||||
expect(link.post_id).to eq post.id
|
||||
|
||||
post.reload
|
||||
post.incoming_link_count.should == 1
|
||||
expect(post.incoming_link_count).to eq 1
|
||||
|
||||
topic.reload
|
||||
topic.incoming_link_count.should == 1
|
||||
expect(topic.incoming_link_count).to eq 1
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -63,22 +63,22 @@ describe IncomingLink do
|
|||
|
||||
it "does nothing if referer is empty" do
|
||||
add(post_id: 1)
|
||||
IncomingLink.count.should == 0
|
||||
expect(IncomingLink.count).to eq 0
|
||||
end
|
||||
|
||||
it "does nothing if referer is same as host" do
|
||||
add(post_id: 1, host: 'somesite.com', referer: 'http://somesite.com')
|
||||
IncomingLink.count.should == 0
|
||||
expect(IncomingLink.count).to eq 0
|
||||
end
|
||||
|
||||
it "tracks not visits for invalid referers" do
|
||||
add(post_id: 1, referer: 'bang bang bang')
|
||||
IncomingLink.count.should == 0
|
||||
expect(IncomingLink.count).to eq 0
|
||||
end
|
||||
|
||||
it "expects to be called with referer and user id" do
|
||||
add(host: "test.com", referer: 'http://some.other.site.com', post_id: 1)
|
||||
IncomingLink.count.should == 1
|
||||
expect(IncomingLink.count).to eq 1
|
||||
end
|
||||
|
||||
it "is able to look up user_id and log it from the GET params" do
|
||||
|
@ -86,7 +86,7 @@ describe IncomingLink do
|
|||
add(host: 'test.com', username: "bob", post_id: 1)
|
||||
|
||||
first = IncomingLink.first
|
||||
first.user_id.should == user.id
|
||||
expect(first.user_id).to eq user.id
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -39,19 +39,19 @@ describe IncomingLinksReport do
|
|||
end
|
||||
|
||||
r = IncomingLinksReport.find('top_referrers').as_json
|
||||
r[:data].should == [
|
||||
expect(r[:data]).to eq [
|
||||
{username: p1.user.username, num_clicks: 7 + 2, num_topics: 2},
|
||||
{username: p2.user.username, num_clicks: 3, num_topics: 1}
|
||||
]
|
||||
|
||||
r = IncomingLinksReport.find('top_traffic_sources').as_json
|
||||
r[:data].should == [
|
||||
expect(r[:data]).to eq [
|
||||
{domain: 'test.com', num_clicks: 7, num_topics: 1},
|
||||
{domain: 'foo.com', num_clicks: 3 + 2, num_topics: 1}
|
||||
]
|
||||
|
||||
r = IncomingLinksReport.find('top_referred_topics').as_json
|
||||
r[:data].should == [
|
||||
expect(r[:data]).to eq [
|
||||
{topic_id: p1.topic.id, topic_title: p1.topic.title, topic_slug: p1.topic.slug, num_clicks: 7},
|
||||
{topic_id: p2.topic.id, topic_title: p2.topic.title, topic_slug: p2.topic.slug, num_clicks: 2 + 3},
|
||||
]
|
||||
|
@ -75,16 +75,16 @@ describe IncomingLinksReport do
|
|||
end
|
||||
|
||||
it 'returns localized titles' do
|
||||
top_referrers[:title].should be_present
|
||||
top_referrers[:xaxis].should be_present
|
||||
top_referrers[:ytitles].should be_present
|
||||
top_referrers[:ytitles][:num_clicks].should be_present
|
||||
top_referrers[:ytitles][:num_topics].should be_present
|
||||
expect(top_referrers[:title]).to be_present
|
||||
expect(top_referrers[:xaxis]).to be_present
|
||||
expect(top_referrers[:ytitles]).to be_present
|
||||
expect(top_referrers[:ytitles][:num_clicks]).to be_present
|
||||
expect(top_referrers[:ytitles][:num_topics]).to be_present
|
||||
end
|
||||
|
||||
it 'with no IncomingLink records, it returns correct data' do
|
||||
IncomingLink.delete_all
|
||||
top_referrers[:data].size.should == 0
|
||||
expect(top_referrers[:data].size).to eq 0
|
||||
end
|
||||
|
||||
it 'with some IncomingLink records, it returns correct data' do
|
||||
|
@ -98,8 +98,8 @@ describe IncomingLinksReport do
|
|||
Fabricate(:incoming_link, user: bob, post: post1).save
|
||||
end
|
||||
|
||||
top_referrers[:data][0].should == {username: 'amy', num_clicks: 3, num_topics: 2}
|
||||
top_referrers[:data][1].should == {username: 'bob', num_clicks: 2, num_topics: 1}
|
||||
expect(top_referrers[:data][0]).to eq({username: 'amy', num_clicks: 3, num_topics: 2})
|
||||
expect(top_referrers[:data][1]).to eq({username: 'bob', num_clicks: 2, num_topics: 1})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -115,24 +115,24 @@ describe IncomingLinksReport do
|
|||
|
||||
it 'returns localized titles' do
|
||||
stub_empty_traffic_source_data
|
||||
top_traffic_sources[:title].should be_present
|
||||
top_traffic_sources[:xaxis].should be_present
|
||||
top_traffic_sources[:ytitles].should be_present
|
||||
top_traffic_sources[:ytitles][:num_clicks].should be_present
|
||||
top_traffic_sources[:ytitles][:num_topics].should be_present
|
||||
top_traffic_sources[:ytitles][:num_users].should be_present
|
||||
expect(top_traffic_sources[:title]).to be_present
|
||||
expect(top_traffic_sources[:xaxis]).to be_present
|
||||
expect(top_traffic_sources[:ytitles]).to be_present
|
||||
expect(top_traffic_sources[:ytitles][:num_clicks]).to be_present
|
||||
expect(top_traffic_sources[:ytitles][:num_topics]).to be_present
|
||||
expect(top_traffic_sources[:ytitles][:num_users]).to be_present
|
||||
end
|
||||
|
||||
it 'with no IncomingLink records, it returns correct data' do
|
||||
stub_empty_traffic_source_data
|
||||
top_traffic_sources[:data].size.should == 0
|
||||
expect(top_traffic_sources[:data].size).to eq 0
|
||||
end
|
||||
|
||||
it 'with some IncomingLink records, it returns correct data' do
|
||||
IncomingLinksReport.stubs(:link_count_per_domain).returns({'twitter.com' => 8, 'facebook.com' => 3})
|
||||
IncomingLinksReport.stubs(:topic_count_per_domain).returns({'twitter.com' => 2, 'facebook.com' => 3})
|
||||
top_traffic_sources[:data][0].should == {domain: 'twitter.com', num_clicks: 8, num_topics: 2}
|
||||
top_traffic_sources[:data][1].should == {domain: 'facebook.com', num_clicks: 3, num_topics: 3}
|
||||
expect(top_traffic_sources[:data][0]).to eq({domain: 'twitter.com', num_clicks: 8, num_topics: 2})
|
||||
expect(top_traffic_sources[:data][1]).to eq({domain: 'facebook.com', num_clicks: 3, num_topics: 3})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -146,15 +146,15 @@ describe IncomingLinksReport do
|
|||
|
||||
it 'returns localized titles' do
|
||||
stub_empty_referred_topics_data
|
||||
top_referred_topics[:title].should be_present
|
||||
top_referred_topics[:xaxis].should be_present
|
||||
top_referred_topics[:ytitles].should be_present
|
||||
top_referred_topics[:ytitles][:num_clicks].should be_present
|
||||
expect(top_referred_topics[:title]).to be_present
|
||||
expect(top_referred_topics[:xaxis]).to be_present
|
||||
expect(top_referred_topics[:ytitles]).to be_present
|
||||
expect(top_referred_topics[:ytitles][:num_clicks]).to be_present
|
||||
end
|
||||
|
||||
it 'with no IncomingLink records, it returns correct data' do
|
||||
stub_empty_referred_topics_data
|
||||
top_referred_topics[:data].size.should == 0
|
||||
expect(top_referred_topics[:data].size).to eq 0
|
||||
end
|
||||
|
||||
it 'with some IncomingLink records, it returns correct data' do
|
||||
|
@ -163,8 +163,8 @@ describe IncomingLinksReport do
|
|||
IncomingLinksReport.stubs(:link_count_per_topic).returns({topic1.id => 8, topic2.id => 3})
|
||||
Topic.stubs(:select).returns(Topic); Topic.stubs(:where).returns(Topic) # bypass some activerecord methods
|
||||
Topic.stubs(:all).returns([topic1, topic2])
|
||||
top_referred_topics[:data][0].should == {topic_id: topic1.id, topic_title: topic1.title, topic_slug: topic1.slug, num_clicks: 8 }
|
||||
top_referred_topics[:data][1].should == {topic_id: topic2.id, topic_title: topic2.title, topic_slug: topic2.slug, num_clicks: 3 }
|
||||
expect(top_referred_topics[:data][0]).to eq({topic_id: topic1.id, topic_title: topic1.title, topic_slug: topic1.slug, num_clicks: 8 })
|
||||
expect(top_referred_topics[:data][1]).to eq({topic_id: topic2.id, topic_title: topic2.title, topic_slug: topic2.slug, num_clicks: 3 })
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ describe InviteRedeemer do
|
|||
describe '#create_for_email' do
|
||||
let(:user) { InviteRedeemer.create_user_from_invite(Fabricate(:invite, email: 'walter.white@email.com'), 'walter', 'Walter White') }
|
||||
it "should be created correctly" do
|
||||
user.username.should == 'walter'
|
||||
user.name.should == 'Walter White'
|
||||
user.should be_active
|
||||
user.email.should == 'walter.white@email.com'
|
||||
expect(user.username).to eq('walter')
|
||||
expect(user.name).to eq('Walter White')
|
||||
expect(user).to be_active
|
||||
expect(user.email).to eq('walter.white@email.com')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Invite do
|
||||
|
||||
it { should validate_presence_of :invited_by_id }
|
||||
it { is_expected.to validate_presence_of :invited_by_id }
|
||||
|
||||
let(:iceking) { 'iceking@adventuretime.ooo' }
|
||||
|
||||
|
@ -12,11 +12,11 @@ describe Invite do
|
|||
let(:invite) { Invite.create(email: user.email, invited_by: coding_horror) }
|
||||
|
||||
it "should not allow an invite with the same email as an existing user" do
|
||||
invite.should_not be_valid
|
||||
expect(invite).not_to be_valid
|
||||
end
|
||||
|
||||
it "should not allow a user to invite themselves" do
|
||||
invite.email_already_exists.should == true
|
||||
expect(invite.email_already_exists).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -26,12 +26,12 @@ describe Invite do
|
|||
let(:invite) { Invite.create(email: "test@mailinator.com", invited_by: coding_horror) }
|
||||
|
||||
it "should not allow an invite with blacklisted email" do
|
||||
invite.should_not be_valid
|
||||
expect(invite).not_to be_valid
|
||||
end
|
||||
|
||||
it "should allow an invite with non-blacklisted email" do
|
||||
invite = Fabricate(:invite, email: "test@mail.com", invited_by: coding_horror)
|
||||
invite.should be_valid
|
||||
expect(invite).to be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -42,12 +42,12 @@ describe Invite do
|
|||
subject { Fabricate(:invite) }
|
||||
|
||||
it "works" do
|
||||
subject.invite_key.should be_present
|
||||
subject.email_already_exists.should == false
|
||||
expect(subject.invite_key).to be_present
|
||||
expect(subject.email_already_exists).to eq(false)
|
||||
end
|
||||
|
||||
it 'should store a lower case version of the email' do
|
||||
subject.email.should == iceking
|
||||
expect(subject.email).to eq(iceking)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -67,7 +67,7 @@ describe Invite do
|
|||
invite = topic.invite_by_email(inviter, iceking)
|
||||
invite.destroy
|
||||
invite = topic.invite_by_email(inviter, iceking)
|
||||
invite.should be_present
|
||||
expect(invite).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -77,8 +77,8 @@ describe Invite do
|
|||
end
|
||||
|
||||
it 'belongs to the topic' do
|
||||
topic.invites.should == [@invite]
|
||||
@invite.topics.should == [topic]
|
||||
expect(topic.invites).to eq([@invite])
|
||||
expect(@invite.topics).to eq([topic])
|
||||
end
|
||||
|
||||
context 'when added by another user' do
|
||||
|
@ -86,18 +86,18 @@ describe Invite do
|
|||
let(:new_invite) { topic.invite_by_email(coding_horror, iceking) }
|
||||
|
||||
it 'returns a different invite' do
|
||||
new_invite.should_not == @invite
|
||||
new_invite.invite_key.should_not == @invite.invite_key
|
||||
new_invite.topics.should == [topic]
|
||||
expect(new_invite).not_to eq(@invite)
|
||||
expect(new_invite.invite_key).not_to eq(@invite.invite_key)
|
||||
expect(new_invite.topics).to eq([topic])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'when adding a duplicate' do
|
||||
it 'returns the original invite' do
|
||||
topic.invite_by_email(inviter, 'iceking@adventuretime.ooo').should == @invite
|
||||
topic.invite_by_email(inviter, 'iceking@ADVENTURETIME.ooo').should == @invite
|
||||
topic.invite_by_email(inviter, 'ICEKING@adventuretime.ooo').should == @invite
|
||||
expect(topic.invite_by_email(inviter, 'iceking@adventuretime.ooo')).to eq(@invite)
|
||||
expect(topic.invite_by_email(inviter, 'iceking@ADVENTURETIME.ooo')).to eq(@invite)
|
||||
expect(topic.invite_by_email(inviter, 'ICEKING@adventuretime.ooo')).to eq(@invite)
|
||||
end
|
||||
|
||||
it 'returns a new invite if the other has expired' do
|
||||
|
@ -105,8 +105,8 @@ describe Invite do
|
|||
@invite.created_at = 2.days.ago
|
||||
@invite.save
|
||||
new_invite = topic.invite_by_email(inviter, 'iceking@adventuretime.ooo')
|
||||
new_invite.should_not == @invite
|
||||
new_invite.should_not be_expired
|
||||
expect(new_invite).not_to eq(@invite)
|
||||
expect(new_invite).not_to be_expired
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -115,9 +115,9 @@ describe Invite do
|
|||
|
||||
it 'should be the same invite' do
|
||||
@new_invite = another_topic.invite_by_email(inviter, iceking)
|
||||
@new_invite.should == @invite
|
||||
another_topic.invites.should == [@invite]
|
||||
@invite.topics.should =~ [topic, another_topic]
|
||||
expect(@new_invite).to eq(@invite)
|
||||
expect(another_topic.invites).to eq([@invite])
|
||||
expect(@invite.topics).to match_array([topic, another_topic])
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -132,10 +132,10 @@ describe Invite do
|
|||
|
||||
it "works" do
|
||||
# doesn't create an invite
|
||||
invite.should be_blank
|
||||
expect(invite).to be_blank
|
||||
|
||||
# gives the user permission to access the topic
|
||||
topic.allowed_users.include?(coding_horror).should == true
|
||||
expect(topic.allowed_users.include?(coding_horror)).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -145,23 +145,23 @@ describe Invite do
|
|||
let(:invite) { Fabricate(:invite) }
|
||||
|
||||
it 'creates a notification for the invitee' do
|
||||
lambda { invite.redeem }.should change(Notification, :count)
|
||||
expect { invite.redeem }.to change(Notification, :count)
|
||||
end
|
||||
|
||||
it 'wont redeem an expired invite' do
|
||||
SiteSetting.expects(:invite_expiry_days).returns(10)
|
||||
invite.update_column(:created_at, 20.days.ago)
|
||||
invite.redeem.should be_blank
|
||||
expect(invite.redeem).to be_blank
|
||||
end
|
||||
|
||||
it 'wont redeem a deleted invite' do
|
||||
invite.destroy
|
||||
invite.redeem.should be_blank
|
||||
expect(invite.redeem).to be_blank
|
||||
end
|
||||
|
||||
it "won't redeem an invalidated invite" do
|
||||
invite.invalidated_at = 1.day.ago
|
||||
invite.redeem.should be_blank
|
||||
expect(invite.redeem).to be_blank
|
||||
end
|
||||
|
||||
context 'enqueues a job to email "set password" instructions' do
|
||||
|
@ -198,14 +198,14 @@ describe Invite do
|
|||
invite.save
|
||||
|
||||
user = invite.redeem
|
||||
user.groups.count.should == 1
|
||||
expect(user.groups.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
context "invite trust levels" do
|
||||
it "returns the trust level in default_invitee_trust_level" do
|
||||
SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel[3])
|
||||
invite.redeem.trust_level.should == TrustLevel[3]
|
||||
expect(invite.redeem.trust_level).to eq(TrustLevel[3])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -213,7 +213,7 @@ describe Invite do
|
|||
it 'correctly activates accounts' do
|
||||
SiteSetting.stubs(:must_approve_users).returns(true)
|
||||
user = invite.redeem
|
||||
user.approved?.should == true
|
||||
expect(user.approved?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -222,9 +222,9 @@ describe Invite do
|
|||
let!(:user) { invite.redeem }
|
||||
|
||||
it 'works correctly' do
|
||||
user.is_a?(User).should == true
|
||||
user.send_welcome_message.should == true
|
||||
user.trust_level.should == SiteSetting.default_invitee_trust_level
|
||||
expect(user.is_a?(User)).to eq(true)
|
||||
expect(user.send_welcome_message).to eq(true)
|
||||
expect(user.trust_level).to eq(SiteSetting.default_invitee_trust_level)
|
||||
end
|
||||
|
||||
context 'after redeeming' do
|
||||
|
@ -234,10 +234,10 @@ describe Invite do
|
|||
|
||||
it 'works correctly' do
|
||||
# has set the user_id attribute
|
||||
invite.user.should == user
|
||||
expect(invite.user).to eq(user)
|
||||
|
||||
# returns true for redeemed
|
||||
invite.should be_redeemed
|
||||
expect(invite).to be_redeemed
|
||||
end
|
||||
|
||||
|
||||
|
@ -248,7 +248,7 @@ describe Invite do
|
|||
end
|
||||
|
||||
it 'will not redeem twice' do
|
||||
invite.redeem.should be_blank
|
||||
expect(invite.redeem).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -258,8 +258,8 @@ describe Invite do
|
|||
end
|
||||
|
||||
it 'will not redeem twice' do
|
||||
invite.redeem.should be_present
|
||||
invite.redeem.send_welcome_message.should == false
|
||||
expect(invite.redeem).to be_present
|
||||
expect(invite.redeem.send_welcome_message).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -278,8 +278,8 @@ describe Invite do
|
|||
it 'adds the user to the topic_users' do
|
||||
user = invite.redeem
|
||||
topic.reload
|
||||
topic.allowed_users.include?(user).should == true
|
||||
Guardian.new(user).can_see?(topic).should == true
|
||||
expect(topic.allowed_users.include?(user)).to eq(true)
|
||||
expect(Guardian.new(user).can_see?(topic)).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -291,7 +291,7 @@ describe Invite do
|
|||
|
||||
it 'adds the user to the topic_users' do
|
||||
topic.reload
|
||||
topic.allowed_users.include?(user).should == true
|
||||
expect(topic.allowed_users.include?(user)).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -303,19 +303,19 @@ describe Invite do
|
|||
let(:another_topic) { Fabricate(:topic, category_id: nil, archetype: "private_message", user: coding_horror) }
|
||||
|
||||
it 'adds the user to the topic_users of the first topic' do
|
||||
topic.allowed_users.include?(user).should == true
|
||||
another_topic.allowed_users.include?(user).should == true
|
||||
expect(topic.allowed_users.include?(user)).to eq(true)
|
||||
expect(another_topic.allowed_users.include?(user)).to eq(true)
|
||||
another_invite.reload
|
||||
another_invite.should_not be_redeemed
|
||||
expect(another_invite).not_to be_redeemed
|
||||
end
|
||||
|
||||
context 'if they redeem the other invite afterwards' do
|
||||
|
||||
it 'returns the same user' do
|
||||
result = another_invite.redeem
|
||||
result.should == user
|
||||
expect(result).to eq(user)
|
||||
another_invite.reload
|
||||
another_invite.should be_redeemed
|
||||
expect(another_invite).to be_redeemed
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -366,7 +366,7 @@ describe Invite do
|
|||
|
||||
invites = Invite.find_redeemed_invites_from(inviter)
|
||||
|
||||
invites.size.should == 1
|
||||
expect(invites.size).to eq(1)
|
||||
expect(invites.first).to eq redeemed_invite
|
||||
end
|
||||
end
|
||||
|
@ -376,22 +376,22 @@ describe Invite do
|
|||
subject { described_class.invalidate_for_email(email) }
|
||||
|
||||
it 'returns nil if there is no invite for the given email' do
|
||||
subject.should == nil
|
||||
expect(subject).to eq(nil)
|
||||
end
|
||||
|
||||
it 'sets the matching invite to be invalid' do
|
||||
invite = Fabricate(:invite, invited_by: Fabricate(:user), user_id: nil, email: email)
|
||||
subject.should == invite
|
||||
subject.link_valid?.should == false
|
||||
subject.should be_valid
|
||||
expect(subject).to eq(invite)
|
||||
expect(subject.link_valid?).to eq(false)
|
||||
expect(subject).to be_valid
|
||||
end
|
||||
|
||||
it 'sets the matching invite to be invalid without being case-sensitive' do
|
||||
invite = Fabricate(:invite, invited_by: Fabricate(:user), user_id: nil, email: 'invite.me2@Example.COM')
|
||||
result = described_class.invalidate_for_email('invite.me2@EXAMPLE.com')
|
||||
result.should == invite
|
||||
result.link_valid?.should == false
|
||||
result.should be_valid
|
||||
expect(result).to eq(invite)
|
||||
expect(result.link_valid?).to eq(false)
|
||||
expect(result).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -403,13 +403,13 @@ describe Invite do
|
|||
it 'redeems the invite from email' do
|
||||
result = Invite.redeem_from_email(user.email)
|
||||
invite.reload
|
||||
invite.should be_redeemed
|
||||
expect(invite).to be_redeemed
|
||||
end
|
||||
|
||||
it 'does not redeem the invite if email does not match' do
|
||||
result = Invite.redeem_from_email('test24@example.com')
|
||||
invite.reload
|
||||
invite.should_not be_redeemed
|
||||
expect(invite).not_to be_redeemed
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -422,13 +422,13 @@ describe Invite do
|
|||
it 'redeems the invite from token' do
|
||||
result = Invite.redeem_from_token(invite.invite_key, user.email)
|
||||
invite.reload
|
||||
invite.should be_redeemed
|
||||
expect(invite).to be_redeemed
|
||||
end
|
||||
|
||||
it 'does not redeem the invite if token does not match' do
|
||||
result = Invite.redeem_from_token("bae0071f995bb4b6f756e80b383778b5", user.email)
|
||||
invite.reload
|
||||
invite.should_not be_redeemed
|
||||
expect(invite).not_to be_redeemed
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -5,12 +5,12 @@ describe Permalink do
|
|||
describe "new record" do
|
||||
it "strips blanks" do
|
||||
permalink = described_class.create(url: " my/old/url ")
|
||||
permalink.url.should == "my/old/url"
|
||||
expect(permalink.url).to eq("my/old/url")
|
||||
end
|
||||
|
||||
it "removes leading slash" do
|
||||
permalink = described_class.create(url: "/my/old/url")
|
||||
permalink.url.should == "my/old/url"
|
||||
expect(permalink.url).to eq("my/old/url")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,49 +24,49 @@ describe Permalink do
|
|||
|
||||
it "returns a topic url when topic_id is set" do
|
||||
permalink.topic_id = topic.id
|
||||
target_url.should == topic.relative_url
|
||||
expect(target_url).to eq(topic.relative_url)
|
||||
end
|
||||
|
||||
it "returns nil when topic_id is set but topic is not found" do
|
||||
permalink.topic_id = 99999
|
||||
target_url.should == nil
|
||||
expect(target_url).to eq(nil)
|
||||
end
|
||||
|
||||
it "returns a post url when post_id is set" do
|
||||
permalink.post_id = post.id
|
||||
target_url.should == post.url
|
||||
expect(target_url).to eq(post.url)
|
||||
end
|
||||
|
||||
it "returns nil when post_id is set but post is not found" do
|
||||
permalink.post_id = 99999
|
||||
target_url.should == nil
|
||||
expect(target_url).to eq(nil)
|
||||
end
|
||||
|
||||
it "returns a post url when post_id and topic_id are both set" do
|
||||
permalink.post_id = post.id
|
||||
permalink.topic_id = topic.id
|
||||
target_url.should == post.url
|
||||
expect(target_url).to eq(post.url)
|
||||
end
|
||||
|
||||
it "returns a category url when category_id is set" do
|
||||
permalink.category_id = category.id
|
||||
target_url.should == category.url
|
||||
expect(target_url).to eq(category.url)
|
||||
end
|
||||
|
||||
it "returns nil when category_id is set but category is not found" do
|
||||
permalink.category_id = 99999
|
||||
target_url.should == nil
|
||||
expect(target_url).to eq(nil)
|
||||
end
|
||||
|
||||
it "returns a post url when topic_id, post_id, and category_id are all set for some reason" do
|
||||
permalink.post_id = post.id
|
||||
permalink.topic_id = topic.id
|
||||
permalink.category_id = category.id
|
||||
target_url.should == post.url
|
||||
expect(target_url).to eq(post.url)
|
||||
end
|
||||
|
||||
it "returns nil when nothing is set" do
|
||||
target_url.should == nil
|
||||
expect(target_url).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,10 +2,10 @@ require 'spec_helper'
|
|||
require_dependency 'post_destroyer'
|
||||
|
||||
describe PostAction do
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :post }
|
||||
it { should belong_to :post_action_type }
|
||||
it { should rate_limit }
|
||||
it { is_expected.to belong_to :user }
|
||||
it { is_expected.to belong_to :post }
|
||||
it { is_expected.to belong_to :post_action_type }
|
||||
it { is_expected.to rate_limit }
|
||||
|
||||
let(:moderator) { Fabricate(:moderator) }
|
||||
let(:codinghorror) { Fabricate(:coding_horror) }
|
||||
|
@ -20,7 +20,7 @@ describe PostAction do
|
|||
it "doesn't generate title longer than 255 characters" do
|
||||
topic = create_topic(title: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc sit amet rutrum neque. Pellentesque suscipit vehicula facilisis. Phasellus lacus sapien, aliquam nec convallis sit amet, vestibulum laoreet ante. Curabitur et pellentesque tortor. Donec non.")
|
||||
post = create_post(topic: topic)
|
||||
-> { PostAction.act(admin, post, PostActionType.types[:notify_user], message: "WAT") }.should_not raise_error
|
||||
expect { PostAction.act(admin, post, PostActionType.types[:notify_user], message: "WAT") }.not_to raise_error
|
||||
end
|
||||
|
||||
it "notify moderators integration test" do
|
||||
|
@ -35,37 +35,37 @@ describe PostAction do
|
|||
.where('topics.archetype' => Archetype.private_message)
|
||||
.to_a
|
||||
|
||||
posts.count.should == 1
|
||||
action.related_post_id.should == posts[0].id.to_i
|
||||
posts[0].subtype.should == TopicSubtype.notify_moderators
|
||||
expect(posts.count).to eq(1)
|
||||
expect(action.related_post_id).to eq(posts[0].id.to_i)
|
||||
expect(posts[0].subtype).to eq(TopicSubtype.notify_moderators)
|
||||
|
||||
topic = posts[0].topic
|
||||
|
||||
# Moderators should be invited to the private topic, otherwise they're not permitted to see it
|
||||
topic_user_ids = topic.topic_users(true).map {|x| x.user_id}
|
||||
topic_user_ids.should include(codinghorror.id)
|
||||
topic_user_ids.should include(mod.id)
|
||||
expect(topic_user_ids).to include(codinghorror.id)
|
||||
expect(topic_user_ids).to include(mod.id)
|
||||
|
||||
# Notification level should be "Watching" for everyone
|
||||
topic.topic_users(true).map(&:notification_level).uniq.should == [TopicUser.notification_levels[:watching]]
|
||||
expect(topic.topic_users(true).map(&:notification_level).uniq).to eq([TopicUser.notification_levels[:watching]])
|
||||
|
||||
# reply to PM should not clear flag
|
||||
PostCreator.new(mod, topic_id: posts[0].topic_id, raw: "This is my test reply to the user, it should clear flags").create
|
||||
action.reload
|
||||
action.deleted_at.should == nil
|
||||
expect(action.deleted_at).to eq(nil)
|
||||
|
||||
# Acting on the flag should post an automated status message
|
||||
topic.posts.count.should == 2
|
||||
expect(topic.posts.count).to eq(2)
|
||||
PostAction.agree_flags!(post, admin)
|
||||
topic.reload
|
||||
topic.posts.count.should == 3
|
||||
topic.posts.last.post_type.should == Post.types[:moderator_action]
|
||||
expect(topic.posts.count).to eq(3)
|
||||
expect(topic.posts.last.post_type).to eq(Post.types[:moderator_action])
|
||||
|
||||
# Clearing the flags should not post another automated status message
|
||||
PostAction.act(mod, post, PostActionType.types[:notify_moderators], message: "another special message")
|
||||
PostAction.clear_flags!(post, admin)
|
||||
topic.reload
|
||||
topic.posts.count.should == 3
|
||||
expect(topic.posts.count).to eq(3)
|
||||
end
|
||||
|
||||
describe 'notify_moderators' do
|
||||
|
@ -100,39 +100,39 @@ describe PostAction do
|
|||
end
|
||||
|
||||
it "increments the numbers correctly" do
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
expect(PostAction.flagged_posts_count).to eq(0)
|
||||
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:off_topic])
|
||||
PostAction.flagged_posts_count.should == 1
|
||||
expect(PostAction.flagged_posts_count).to eq(1)
|
||||
|
||||
PostAction.clear_flags!(post, Discourse.system_user)
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
expect(PostAction.flagged_posts_count).to eq(0)
|
||||
end
|
||||
|
||||
it "should reset counts when a topic is deleted" do
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:off_topic])
|
||||
post.topic.trash!
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
expect(PostAction.flagged_posts_count).to eq(0)
|
||||
end
|
||||
|
||||
it "should ignore validated flags" do
|
||||
post = create_post
|
||||
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:off_topic])
|
||||
post.hidden.should == false
|
||||
post.hidden_at.should be_blank
|
||||
expect(post.hidden).to eq(false)
|
||||
expect(post.hidden_at).to be_blank
|
||||
PostAction.defer_flags!(post, admin)
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
expect(PostAction.flagged_posts_count).to eq(0)
|
||||
|
||||
post.reload
|
||||
post.hidden.should == false
|
||||
post.hidden_at.should be_blank
|
||||
expect(post.hidden).to eq(false)
|
||||
expect(post.hidden_at).to be_blank
|
||||
|
||||
PostAction.hide_post!(post, PostActionType.types[:off_topic])
|
||||
|
||||
post.reload
|
||||
post.hidden.should == true
|
||||
post.hidden_at.should be_present
|
||||
expect(post.hidden).to eq(true)
|
||||
expect(post.hidden_at).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -144,18 +144,18 @@ describe PostAction do
|
|||
PostAction.act(codinghorror, second_post, PostActionType.types[:like])
|
||||
|
||||
post.topic.reload
|
||||
post.topic.like_count.should == 2
|
||||
expect(post.topic.like_count).to eq(2)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "when a user bookmarks something" do
|
||||
it "increases the post's bookmark count when saved" do
|
||||
lambda { bookmark.save; post.reload }.should change(post, :bookmark_count).by(1)
|
||||
expect { bookmark.save; post.reload }.to change(post, :bookmark_count).by(1)
|
||||
end
|
||||
|
||||
it "increases the forum topic's bookmark count when saved" do
|
||||
lambda { bookmark.save; post.topic.reload }.should change(post.topic, :bookmark_count).by(1)
|
||||
expect { bookmark.save; post.topic.reload }.to change(post.topic, :bookmark_count).by(1)
|
||||
end
|
||||
|
||||
describe 'when deleted' do
|
||||
|
@ -170,11 +170,11 @@ describe PostAction do
|
|||
end
|
||||
|
||||
it 'reduces the bookmark count of the post' do
|
||||
lambda { post.reload }.should change(post, :bookmark_count).by(-1)
|
||||
expect { post.reload }.to change(post, :bookmark_count).by(-1)
|
||||
end
|
||||
|
||||
it 'reduces the bookmark count of the forum topic' do
|
||||
lambda { @topic.reload }.should change(post.topic, :bookmark_count).by(-1)
|
||||
expect { @topic.reload }.to change(post.topic, :bookmark_count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -183,27 +183,27 @@ describe PostAction do
|
|||
it 'should increase the `like_count` and `like_score` when a user likes something' do
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||
post.reload
|
||||
post.like_count.should == 1
|
||||
post.like_score.should == 1
|
||||
expect(post.like_count).to eq(1)
|
||||
expect(post.like_score).to eq(1)
|
||||
post.topic.reload
|
||||
post.topic.like_count.should == 1
|
||||
expect(post.topic.like_count).to eq(1)
|
||||
|
||||
# When a staff member likes it
|
||||
PostAction.act(moderator, post, PostActionType.types[:like])
|
||||
post.reload
|
||||
post.like_count.should == 2
|
||||
post.like_score.should == 4
|
||||
expect(post.like_count).to eq(2)
|
||||
expect(post.like_score).to eq(4)
|
||||
|
||||
# Removing likes
|
||||
PostAction.remove_act(codinghorror, post, PostActionType.types[:like])
|
||||
post.reload
|
||||
post.like_count.should == 1
|
||||
post.like_score.should == 3
|
||||
expect(post.like_count).to eq(1)
|
||||
expect(post.like_score).to eq(3)
|
||||
|
||||
PostAction.remove_act(moderator, post, PostActionType.types[:like])
|
||||
post.reload
|
||||
post.like_count.should == 0
|
||||
post.like_score.should == 0
|
||||
expect(post.like_count).to eq(0)
|
||||
expect(post.like_score).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -212,27 +212,27 @@ describe PostAction do
|
|||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||
PostAction.remove_act(codinghorror, post, PostActionType.types[:like])
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||
PostAction.where(post: post).with_deleted.count.should == 1
|
||||
expect(PostAction.where(post: post).with_deleted.count).to eq(1)
|
||||
PostAction.remove_act(codinghorror, post, PostActionType.types[:like])
|
||||
|
||||
# Check that we don't lose consistency into negatives
|
||||
post.reload.like_count.should == 0
|
||||
expect(post.reload.like_count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when a user votes for something' do
|
||||
it 'should increase the vote counts when a user votes' do
|
||||
lambda {
|
||||
expect {
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:vote])
|
||||
post.reload
|
||||
}.should change(post, :vote_count).by(1)
|
||||
}.to change(post, :vote_count).by(1)
|
||||
end
|
||||
|
||||
it 'should increase the forum topic vote count when a user votes' do
|
||||
lambda {
|
||||
expect {
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:vote])
|
||||
post.topic.reload
|
||||
}.should change(post.topic, :vote_count).by(1)
|
||||
}.to change(post.topic, :vote_count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -245,32 +245,32 @@ describe PostAction do
|
|||
SiteSetting.stubs(:flags_required_to_hide_post).returns(7)
|
||||
|
||||
# A post with no flags has 0 for flag counts
|
||||
PostAction.flag_counts_for(post.id).should == [0, 0]
|
||||
expect(PostAction.flag_counts_for(post.id)).to eq([0, 0])
|
||||
|
||||
flag = PostAction.act(eviltrout, post, PostActionType.types[:spam])
|
||||
PostAction.flag_counts_for(post.id).should == [0, 1]
|
||||
expect(PostAction.flag_counts_for(post.id)).to eq([0, 1])
|
||||
|
||||
# If staff takes action, it is ranked higher
|
||||
PostAction.act(admin, post, PostActionType.types[:spam], take_action: true)
|
||||
PostAction.flag_counts_for(post.id).should == [0, 8]
|
||||
expect(PostAction.flag_counts_for(post.id)).to eq([0, 8])
|
||||
|
||||
# If a flag is dismissed
|
||||
PostAction.clear_flags!(post, admin)
|
||||
PostAction.flag_counts_for(post.id).should == [8, 0]
|
||||
expect(PostAction.flag_counts_for(post.id)).to eq([8, 0])
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not allow you to flag stuff with the same reason more than once' do
|
||||
post = Fabricate(:post)
|
||||
PostAction.act(eviltrout, post, PostActionType.types[:spam])
|
||||
lambda { PostAction.act(eviltrout, post, PostActionType.types[:off_topic]) }.should raise_error(PostAction::AlreadyActed)
|
||||
expect { PostAction.act(eviltrout, post, PostActionType.types[:off_topic]) }.to raise_error(PostAction::AlreadyActed)
|
||||
end
|
||||
|
||||
it 'allows you to flag stuff with another reason' do
|
||||
post = Fabricate(:post)
|
||||
PostAction.act(eviltrout, post, PostActionType.types[:spam])
|
||||
PostAction.remove_act(eviltrout, post, PostActionType.types[:spam])
|
||||
lambda { PostAction.act(eviltrout, post, PostActionType.types[:off_topic]) }.should_not raise_error()
|
||||
expect { PostAction.act(eviltrout, post, PostActionType.types[:off_topic]) }.not_to raise_error()
|
||||
end
|
||||
|
||||
it 'should update counts when you clear flags' do
|
||||
|
@ -278,12 +278,12 @@ describe PostAction do
|
|||
PostAction.act(eviltrout, post, PostActionType.types[:spam])
|
||||
|
||||
post.reload
|
||||
post.spam_count.should == 1
|
||||
expect(post.spam_count).to eq(1)
|
||||
|
||||
PostAction.clear_flags!(post, Discourse.system_user)
|
||||
|
||||
post.reload
|
||||
post.spam_count.should == 0
|
||||
expect(post.spam_count).to eq(0)
|
||||
end
|
||||
|
||||
it 'should follow the rules for automatic hiding workflow' do
|
||||
|
@ -298,38 +298,38 @@ describe PostAction do
|
|||
|
||||
post.reload
|
||||
|
||||
post.hidden.should == true
|
||||
post.hidden_at.should be_present
|
||||
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached]
|
||||
post.topic.visible.should == false
|
||||
expect(post.hidden).to eq(true)
|
||||
expect(post.hidden_at).to be_present
|
||||
expect(post.hidden_reason_id).to eq(Post.hidden_reasons[:flag_threshold_reached])
|
||||
expect(post.topic.visible).to eq(false)
|
||||
|
||||
post.revise(post.user, { raw: post.raw + " ha I edited it " })
|
||||
|
||||
post.reload
|
||||
|
||||
post.hidden.should == false
|
||||
post.hidden_reason_id.should == nil
|
||||
post.hidden_at.should be_blank
|
||||
post.topic.visible.should == true
|
||||
expect(post.hidden).to eq(false)
|
||||
expect(post.hidden_reason_id).to eq(nil)
|
||||
expect(post.hidden_at).to be_blank
|
||||
expect(post.topic.visible).to eq(true)
|
||||
|
||||
PostAction.act(eviltrout, post, PostActionType.types[:spam])
|
||||
PostAction.act(walterwhite, post, PostActionType.types[:off_topic])
|
||||
|
||||
post.reload
|
||||
|
||||
post.hidden.should == true
|
||||
post.hidden_at.should be_present
|
||||
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again]
|
||||
post.topic.visible.should == false
|
||||
expect(post.hidden).to eq(true)
|
||||
expect(post.hidden_at).to be_present
|
||||
expect(post.hidden_reason_id).to eq(Post.hidden_reasons[:flag_threshold_reached_again])
|
||||
expect(post.topic.visible).to eq(false)
|
||||
|
||||
post.revise(post.user, { raw: post.raw + " ha I edited it again " })
|
||||
|
||||
post.reload
|
||||
|
||||
post.hidden.should == true
|
||||
post.hidden_at.should be_present
|
||||
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again]
|
||||
post.topic.visible.should == false
|
||||
expect(post.hidden).to eq(true)
|
||||
expect(post.hidden_at).to be_present
|
||||
expect(post.hidden_reason_id).to eq(Post.hidden_reasons[:flag_threshold_reached_again])
|
||||
expect(post.topic.visible).to eq(false)
|
||||
end
|
||||
|
||||
it "hide tl0 posts that are flagged as spam by a tl3 user" do
|
||||
|
@ -342,23 +342,23 @@ describe PostAction do
|
|||
|
||||
post.reload
|
||||
|
||||
post.hidden.should == true
|
||||
post.hidden_at.should be_present
|
||||
post.hidden_reason_id.should == Post.hidden_reasons[:flagged_by_tl3_user]
|
||||
expect(post.hidden).to eq(true)
|
||||
expect(post.hidden_at).to be_present
|
||||
expect(post.hidden_reason_id).to eq(Post.hidden_reasons[:flagged_by_tl3_user])
|
||||
end
|
||||
|
||||
it "can flag the topic instead of a post" do
|
||||
post1 = create_post
|
||||
post2 = create_post(topic: post1.topic)
|
||||
post_action = PostAction.act(Fabricate(:user), post1, PostActionType.types[:spam], { flag_topic: true })
|
||||
post_action.targets_topic.should == true
|
||||
expect(post_action.targets_topic).to eq(true)
|
||||
end
|
||||
|
||||
it "will flag the first post if you flag a topic but there is only one post in the topic" do
|
||||
post = create_post
|
||||
post_action = PostAction.act(Fabricate(:user), post, PostActionType.types[:spam], { flag_topic: true })
|
||||
post_action.targets_topic.should == false
|
||||
post_action.post_id.should == post.id
|
||||
expect(post_action.targets_topic).to eq(false)
|
||||
expect(post_action.post_id).to eq(post.id)
|
||||
end
|
||||
|
||||
it "will unhide the post when a moderator undos the flag on which s/he took action" do
|
||||
|
@ -368,12 +368,12 @@ describe PostAction do
|
|||
PostAction.act(moderator, post, PostActionType.types[:spam], { take_action: true })
|
||||
|
||||
post.reload
|
||||
post.hidden.should == true
|
||||
expect(post.hidden).to eq(true)
|
||||
|
||||
PostAction.remove_act(moderator, post, PostActionType.types[:spam])
|
||||
|
||||
post.reload
|
||||
post.hidden.should == false
|
||||
expect(post.hidden).to eq(false)
|
||||
end
|
||||
|
||||
it "will automatically close a topic due to large community flagging" do
|
||||
|
@ -395,7 +395,7 @@ describe PostAction do
|
|||
PostAction.act(flagger, post1, PostActionType.types[:inappropriate])
|
||||
end
|
||||
|
||||
topic.reload.closed.should == false
|
||||
expect(topic.reload.closed).to eq(false)
|
||||
|
||||
# clean up
|
||||
PostAction.where(post: post1).delete_all
|
||||
|
@ -405,7 +405,7 @@ describe PostAction do
|
|||
PostAction.act(flagger1, post, PostActionType.types[:inappropriate])
|
||||
end
|
||||
|
||||
topic.reload.closed.should == false
|
||||
expect(topic.reload.closed).to eq(false)
|
||||
|
||||
# clean up
|
||||
PostAction.where(post: [post1, post2, post3]).delete_all
|
||||
|
@ -417,7 +417,7 @@ describe PostAction do
|
|||
end
|
||||
end
|
||||
|
||||
topic.reload.closed.should == true
|
||||
expect(topic.reload.closed).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -428,10 +428,10 @@ describe PostAction do
|
|||
# flags are already being tested
|
||||
all_types_except_flags = PostActionType.types.except(PostActionType.flag_types)
|
||||
all_types_except_flags.values.each do |action|
|
||||
lambda do
|
||||
expect do
|
||||
PostAction.act(eviltrout, post, action)
|
||||
PostAction.act(eviltrout, post, action)
|
||||
end.should raise_error(PostAction::AlreadyActed)
|
||||
end.to raise_error(PostAction::AlreadyActed)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,10 +13,10 @@ describe PostAlertObserver do
|
|||
context 'liking' do
|
||||
context 'when liking a post' do
|
||||
it 'creates a notification' do
|
||||
lambda {
|
||||
expect {
|
||||
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
||||
# one like (welcome badge deferred)
|
||||
}.should change(Notification, :count).by(1)
|
||||
}.to change(Notification, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -26,18 +26,18 @@ describe PostAlertObserver do
|
|||
end
|
||||
|
||||
it 'removes a notification' do
|
||||
lambda {
|
||||
expect {
|
||||
PostAction.remove_act(evil_trout, post, PostActionType.types[:like])
|
||||
}.should change(Notification, :count).by(-1)
|
||||
}.to change(Notification, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when editing a post' do
|
||||
it 'notifies a user of the revision' do
|
||||
lambda {
|
||||
expect {
|
||||
post.revise(evil_trout, { raw: "world is the new body of the message" })
|
||||
}.should change(post.user.notifications, :count).by(1)
|
||||
}.to change(post.user.notifications, :count).by(1)
|
||||
end
|
||||
|
||||
context "edit notifications are disabled" do
|
||||
|
@ -46,15 +46,15 @@ describe PostAlertObserver do
|
|||
|
||||
|
||||
it 'notifies a user of the revision made by another user' do
|
||||
lambda {
|
||||
expect {
|
||||
post.revise(evil_trout, { raw: "world is the new body of the message" })
|
||||
}.should change(post.user.notifications, :count).by(1)
|
||||
}.to change(post.user.notifications, :count).by(1)
|
||||
end
|
||||
|
||||
it 'does not notifiy a user of the revision made by the system user' do
|
||||
lambda {
|
||||
expect {
|
||||
post.revise(Discourse.system_user, { raw: "world is the new body of the message" })
|
||||
}.should_not change(post.user.notifications, :count)
|
||||
}.not_to change(post.user.notifications, :count)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -71,20 +71,20 @@ describe PostAlertObserver do
|
|||
end
|
||||
|
||||
it "won't notify someone who can't see the post" do
|
||||
lambda {
|
||||
expect {
|
||||
Guardian.any_instance.expects(:can_see?).with(instance_of(Post)).returns(false)
|
||||
mention_post
|
||||
PostAlerter.new.after_create_post(mention_post)
|
||||
PostAlerter.new.after_save_post(mention_post)
|
||||
}.should_not change(evil_trout.notifications, :count)
|
||||
}.not_to change(evil_trout.notifications, :count)
|
||||
end
|
||||
|
||||
it 'creates like notifications' do
|
||||
other_user = Fabricate(:user)
|
||||
topic.allowed_users << user << other_user
|
||||
lambda {
|
||||
expect {
|
||||
PostAction.act(other_user, mention_post, PostActionType.types[:like])
|
||||
}.should change(user.notifications, :count)
|
||||
}.to change(user.notifications, :count)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -46,44 +46,44 @@ describe PostAnalyzer do
|
|||
describe "raw_links" do
|
||||
it "returns a blank collection for a post with no links" do
|
||||
post_analyzer = PostAnalyzer.new(raw_no_links, default_topic_id)
|
||||
post_analyzer.raw_links.should be_blank
|
||||
expect(post_analyzer.raw_links).to be_blank
|
||||
end
|
||||
|
||||
it "finds a link within markdown" do
|
||||
post_analyzer = PostAnalyzer.new(raw_one_link_md, default_topic_id)
|
||||
post_analyzer.raw_links.should == ["http://www.imdb.com/name/nm2225369"]
|
||||
expect(post_analyzer.raw_links).to eq(["http://www.imdb.com/name/nm2225369"])
|
||||
end
|
||||
|
||||
it "can find two links from html" do
|
||||
post_analyzer = PostAnalyzer.new(raw_two_links_html, default_topic_id)
|
||||
post_analyzer.raw_links.should == ["http://disneyland.disney.go.com/", "http://reddit.com"]
|
||||
expect(post_analyzer.raw_links).to eq(["http://disneyland.disney.go.com/", "http://reddit.com"])
|
||||
end
|
||||
|
||||
it "can find three links without markup" do
|
||||
post_analyzer = PostAnalyzer.new(raw_three_links, default_topic_id)
|
||||
post_analyzer.raw_links.should == ["http://discourse.org", "http://discourse.org/another_url", "http://www.imdb.com/name/nm2225369"]
|
||||
expect(post_analyzer.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
|
||||
post_analyzer = PostAnalyzer.new(raw_no_links, default_topic_id)
|
||||
post_analyzer.linked_hosts.should be_blank
|
||||
expect(post_analyzer.linked_hosts).to be_blank
|
||||
end
|
||||
|
||||
it "returns the host and a count for links" do
|
||||
post_analyzer = PostAnalyzer.new(raw_two_links_html, default_topic_id)
|
||||
post_analyzer.linked_hosts.should == {"disneyland.disney.go.com" => 1, "reddit.com" => 1}
|
||||
expect(post_analyzer.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
|
||||
post_analyzer = PostAnalyzer.new(raw_three_links, default_topic_id)
|
||||
post_analyzer.linked_hosts.should == {"discourse.org" => 1, "www.imdb.com" => 1}
|
||||
expect(post_analyzer.linked_hosts).to eq({"discourse.org" => 1, "www.imdb.com" => 1})
|
||||
end
|
||||
|
||||
it 'returns blank for ipv6 output' do
|
||||
post_analyzer = PostAnalyzer.new('PING www.google.com(lb-in-x93.1e100.net) 56 data bytes', default_topic_id)
|
||||
post_analyzer.linked_hosts.should be_blank
|
||||
expect(post_analyzer.linked_hosts).to be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -98,38 +98,38 @@ describe PostAnalyzer do
|
|||
|
||||
it "returns 0 images for an empty post" do
|
||||
post_analyzer = PostAnalyzer.new("Hello world", nil)
|
||||
post_analyzer.image_count.should == 0
|
||||
expect(post_analyzer.image_count).to eq(0)
|
||||
end
|
||||
|
||||
it "finds images from markdown" do
|
||||
post_analyzer = PostAnalyzer.new(raw_post_one_image_md, default_topic_id)
|
||||
post_analyzer.image_count.should == 1
|
||||
expect(post_analyzer.image_count).to eq(1)
|
||||
end
|
||||
|
||||
it "finds images from HTML" do
|
||||
post_analyzer = PostAnalyzer.new(raw_post_two_images_html, default_topic_id)
|
||||
post_analyzer.image_count.should == 2
|
||||
expect(post_analyzer.image_count).to eq(2)
|
||||
end
|
||||
|
||||
it "doesn't count avatars as images" do
|
||||
post_analyzer = PostAnalyzer.new(raw_post_with_avatars, default_topic_id)
|
||||
post_analyzer.image_count.should == 0
|
||||
expect(post_analyzer.image_count).to eq(0)
|
||||
end
|
||||
|
||||
it "doesn't count favicons as images" do
|
||||
post_analyzer = PostAnalyzer.new(raw_post_with_favicon, default_topic_id)
|
||||
post_analyzer.image_count.should == 0
|
||||
expect(post_analyzer.image_count).to eq(0)
|
||||
end
|
||||
|
||||
it "doesn't count thumbnails as images" do
|
||||
post_analyzer = PostAnalyzer.new(raw_post_with_thumbnail, default_topic_id)
|
||||
post_analyzer.image_count.should == 0
|
||||
expect(post_analyzer.image_count).to eq(0)
|
||||
end
|
||||
|
||||
it "doesn't count whitelisted images" do
|
||||
Post.stubs(:white_listed_image_classes).returns(["classy"])
|
||||
post_analyzer = PostAnalyzer.new(raw_post_with_two_classy_images, default_topic_id)
|
||||
post_analyzer.image_count.should == 0
|
||||
expect(post_analyzer.image_count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -140,23 +140,23 @@ describe PostAnalyzer do
|
|||
|
||||
it "returns 0 links for an empty post" do
|
||||
post_analyzer = PostAnalyzer.new("Hello world", nil)
|
||||
post_analyzer.link_count.should == 0
|
||||
expect(post_analyzer.link_count).to eq(0)
|
||||
end
|
||||
|
||||
it "returns 0 links for a post with mentions" do
|
||||
post_analyzer = PostAnalyzer.new(raw_post_with_mentions, default_topic_id)
|
||||
post_analyzer.link_count.should == 0
|
||||
expect(post_analyzer.link_count).to eq(0)
|
||||
end
|
||||
|
||||
it "finds links from markdown" do
|
||||
Oneboxer.stubs :onebox
|
||||
post_analyzer = PostAnalyzer.new(raw_post_one_link_md, default_topic_id)
|
||||
post_analyzer.link_count.should == 1
|
||||
expect(post_analyzer.link_count).to eq(1)
|
||||
end
|
||||
|
||||
it "finds links from HTML" do
|
||||
post_analyzer = PostAnalyzer.new(raw_post_two_links_html, default_topic_id)
|
||||
post_analyzer.link_count.should == 2
|
||||
expect(post_analyzer.link_count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -165,42 +165,42 @@ describe PostAnalyzer do
|
|||
|
||||
it "returns an empty array with no matches" do
|
||||
post_analyzer = PostAnalyzer.new("Hello Jake and Finn!", default_topic_id)
|
||||
post_analyzer.raw_mentions.should == []
|
||||
expect(post_analyzer.raw_mentions).to eq([])
|
||||
end
|
||||
|
||||
it "returns lowercase unique versions of the mentions" do
|
||||
post_analyzer = PostAnalyzer.new("@Jake @Finn @Jake", default_topic_id)
|
||||
post_analyzer.raw_mentions.should == ['jake', 'finn']
|
||||
expect(post_analyzer.raw_mentions).to eq(['jake', 'finn'])
|
||||
end
|
||||
|
||||
it "ignores pre" do
|
||||
post_analyzer = PostAnalyzer.new("<pre>@Jake</pre> @Finn", default_topic_id)
|
||||
post_analyzer.raw_mentions.should == ['finn']
|
||||
expect(post_analyzer.raw_mentions).to eq(['finn'])
|
||||
end
|
||||
|
||||
it "catches content between pre tags" do
|
||||
post_analyzer = PostAnalyzer.new("<pre>hello</pre> @Finn <pre></pre>", default_topic_id)
|
||||
post_analyzer.raw_mentions.should == ['finn']
|
||||
expect(post_analyzer.raw_mentions).to eq(['finn'])
|
||||
end
|
||||
|
||||
it "ignores code" do
|
||||
post_analyzer = PostAnalyzer.new("@Jake `@Finn`", default_topic_id)
|
||||
post_analyzer.raw_mentions.should == ['jake']
|
||||
expect(post_analyzer.raw_mentions).to eq(['jake'])
|
||||
end
|
||||
|
||||
it "ignores code in markdown-formatted code blocks" do
|
||||
post_analyzer = PostAnalyzer.new(" @Jake @Finn\n@Ryan", default_topic_id)
|
||||
post_analyzer.raw_mentions.should == ['ryan']
|
||||
expect(post_analyzer.raw_mentions).to eq(['ryan'])
|
||||
end
|
||||
|
||||
it "ignores quotes" do
|
||||
post_analyzer = PostAnalyzer.new("[quote=\"Evil Trout\"]@Jake[/quote] @Finn", default_topic_id)
|
||||
post_analyzer.raw_mentions.should == ['finn']
|
||||
expect(post_analyzer.raw_mentions).to eq(['finn'])
|
||||
end
|
||||
|
||||
it "handles underscore in username" do
|
||||
post_analyzer = PostAnalyzer.new("@Jake @Finn @Jake_Old", default_topic_id)
|
||||
post_analyzer.raw_mentions.should == ['jake', 'finn', 'jake_old']
|
||||
expect(post_analyzer.raw_mentions).to eq(['jake', 'finn', 'jake_old'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe PostDetail do
|
||||
it { should belong_to :post }
|
||||
it { is_expected.to belong_to :post }
|
||||
|
||||
it { should validate_presence_of :key }
|
||||
it { should validate_presence_of :value }
|
||||
it { should validate_uniqueness_of(:key).scoped_to(:post_id) }
|
||||
it { is_expected.to validate_presence_of :key }
|
||||
it { is_expected.to validate_presence_of :value }
|
||||
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:post_id) }
|
||||
end
|
||||
|
|
|
@ -36,14 +36,14 @@ describe PostMover do
|
|||
context "errors" do
|
||||
|
||||
it "raises an error when one of the posts doesn't exist" do
|
||||
lambda { topic.move_posts(user, [1003], title: "new testing topic name") }.should raise_error(Discourse::InvalidParameters)
|
||||
expect { topic.move_posts(user, [1003], title: "new testing topic name") }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "raises an error and does not create a topic if no posts were moved" do
|
||||
Topic.count.tap do |original_topic_count|
|
||||
lambda {
|
||||
expect {
|
||||
topic.move_posts(user, [], title: "new testing topic name")
|
||||
}.should raise_error(Discourse::InvalidParameters)
|
||||
}.to raise_error(Discourse::InvalidParameters)
|
||||
|
||||
expect(Topic.count).to eq original_topic_count
|
||||
end
|
||||
|
@ -61,41 +61,41 @@ describe PostMover do
|
|||
let!(:new_topic) { topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id) }
|
||||
|
||||
it "works correctly" do
|
||||
TopicUser.find_by(user_id: user.id, topic_id: topic.id).last_read_post_number.should == p3.post_number
|
||||
expect(TopicUser.find_by(user_id: user.id, topic_id: topic.id).last_read_post_number).to eq(p3.post_number)
|
||||
|
||||
new_topic.should be_present
|
||||
new_topic.featured_user1_id.should == another_user.id
|
||||
new_topic.like_count.should == 1
|
||||
expect(new_topic).to be_present
|
||||
expect(new_topic.featured_user1_id).to eq(another_user.id)
|
||||
expect(new_topic.like_count).to eq(1)
|
||||
|
||||
new_topic.category.should == category
|
||||
topic.featured_user1_id.should be_blank
|
||||
new_topic.posts.by_post_number.should =~ [p2, p4]
|
||||
expect(new_topic.category).to eq(category)
|
||||
expect(topic.featured_user1_id).to be_blank
|
||||
expect(new_topic.posts.by_post_number).to match_array([p2, p4])
|
||||
|
||||
new_topic.reload
|
||||
new_topic.posts_count.should == 2
|
||||
new_topic.highest_post_number.should == 2
|
||||
new_topic.last_post_user_id.should == new_topic.posts.last.user_id
|
||||
expect(new_topic.posts_count).to eq(2)
|
||||
expect(new_topic.highest_post_number).to eq(2)
|
||||
expect(new_topic.last_post_user_id).to eq(new_topic.posts.last.user_id)
|
||||
expect(new_topic.last_posted_at).to be_present
|
||||
|
||||
p2.reload
|
||||
p2.sort_order.should == 1
|
||||
p2.post_number.should == 1
|
||||
p2.topic_links.first.topic_id.should == new_topic.id
|
||||
expect(p2.sort_order).to eq(1)
|
||||
expect(p2.post_number).to eq(1)
|
||||
expect(p2.topic_links.first.topic_id).to eq(new_topic.id)
|
||||
|
||||
p4.reload
|
||||
p4.post_number.should == 2
|
||||
p4.sort_order.should == 2
|
||||
expect(p4.post_number).to eq(2)
|
||||
expect(p4.sort_order).to eq(2)
|
||||
|
||||
topic.reload
|
||||
topic.featured_user1_id.should be_blank
|
||||
topic.like_count.should == 0
|
||||
topic.posts_count.should == 2
|
||||
topic.posts.by_post_number.should =~ [p1, p3]
|
||||
topic.highest_post_number.should == p3.post_number
|
||||
expect(topic.featured_user1_id).to be_blank
|
||||
expect(topic.like_count).to eq(0)
|
||||
expect(topic.posts_count).to eq(2)
|
||||
expect(topic.posts.by_post_number).to match_array([p1, p3])
|
||||
expect(topic.highest_post_number).to eq(p3.post_number)
|
||||
|
||||
# both the like and was_liked user actions should be correct
|
||||
action = UserAction.find_by(user_id: another_user.id)
|
||||
action.target_topic_id.should == new_topic.id
|
||||
expect(action.target_topic_id).to eq(new_topic.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -106,43 +106,43 @@ describe PostMover do
|
|||
let!(:moved_to) { topic.move_posts(user, [p2.id, p4.id], destination_topic_id: destination_topic.id)}
|
||||
|
||||
it "works correctly" do
|
||||
moved_to.should == destination_topic
|
||||
expect(moved_to).to eq(destination_topic)
|
||||
|
||||
# Check out new topic
|
||||
moved_to.reload
|
||||
moved_to.posts_count.should == 3
|
||||
moved_to.highest_post_number.should == 3
|
||||
moved_to.featured_user1_id.should == another_user.id
|
||||
moved_to.like_count.should == 1
|
||||
moved_to.category_id.should == SiteSetting.uncategorized_category_id
|
||||
expect(moved_to.posts_count).to eq(3)
|
||||
expect(moved_to.highest_post_number).to eq(3)
|
||||
expect(moved_to.featured_user1_id).to eq(another_user.id)
|
||||
expect(moved_to.like_count).to eq(1)
|
||||
expect(moved_to.category_id).to eq(SiteSetting.uncategorized_category_id)
|
||||
|
||||
# Posts should be re-ordered
|
||||
p2.reload
|
||||
p2.sort_order.should == 2
|
||||
p2.post_number.should == 2
|
||||
p2.topic_id.should == moved_to.id
|
||||
p2.reply_count.should == 1
|
||||
p2.reply_to_post_number.should == nil
|
||||
expect(p2.sort_order).to eq(2)
|
||||
expect(p2.post_number).to eq(2)
|
||||
expect(p2.topic_id).to eq(moved_to.id)
|
||||
expect(p2.reply_count).to eq(1)
|
||||
expect(p2.reply_to_post_number).to eq(nil)
|
||||
|
||||
p4.reload
|
||||
p4.post_number.should == 3
|
||||
p4.sort_order.should == 3
|
||||
p4.topic_id.should == moved_to.id
|
||||
p4.reply_count.should == 0
|
||||
p4.reply_to_post_number.should == 2
|
||||
expect(p4.post_number).to eq(3)
|
||||
expect(p4.sort_order).to eq(3)
|
||||
expect(p4.topic_id).to eq(moved_to.id)
|
||||
expect(p4.reply_count).to eq(0)
|
||||
expect(p4.reply_to_post_number).to eq(2)
|
||||
|
||||
# Check out the original topic
|
||||
topic.reload
|
||||
topic.posts_count.should == 2
|
||||
topic.highest_post_number.should == 3
|
||||
topic.featured_user1_id.should be_blank
|
||||
topic.like_count.should == 0
|
||||
topic.posts_count.should == 2
|
||||
topic.posts.by_post_number.should =~ [p1, p3]
|
||||
topic.highest_post_number.should == p3.post_number
|
||||
expect(topic.posts_count).to eq(2)
|
||||
expect(topic.highest_post_number).to eq(3)
|
||||
expect(topic.featured_user1_id).to be_blank
|
||||
expect(topic.like_count).to eq(0)
|
||||
expect(topic.posts_count).to eq(2)
|
||||
expect(topic.posts.by_post_number).to match_array([p1, p3])
|
||||
expect(topic.highest_post_number).to eq(p3.post_number)
|
||||
|
||||
# Should update last reads
|
||||
TopicUser.find_by(user_id: user.id, topic_id: topic.id).last_read_post_number.should == p3.post_number
|
||||
expect(TopicUser.find_by(user_id: user.id, topic_id: topic.id).last_read_post_number).to eq(p3.post_number)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -151,36 +151,36 @@ describe PostMover do
|
|||
let!(:new_topic) { topic.move_posts(user, [p1.id, p2.id], title: "new testing topic name") }
|
||||
|
||||
it "copies the OP, doesn't delete it" do
|
||||
new_topic.should be_present
|
||||
expect(new_topic).to be_present
|
||||
new_topic.posts.reload
|
||||
new_topic.posts.by_post_number.first.raw.should == p1.raw
|
||||
expect(new_topic.posts.by_post_number.first.raw).to eq(p1.raw)
|
||||
|
||||
new_topic.reload
|
||||
new_topic.posts_count.should == 2
|
||||
new_topic.highest_post_number.should == 2
|
||||
expect(new_topic.posts_count).to eq(2)
|
||||
expect(new_topic.highest_post_number).to eq(2)
|
||||
|
||||
# First post didn't move
|
||||
p1.reload
|
||||
p1.sort_order.should == 1
|
||||
p1.post_number.should == 1
|
||||
expect(p1.sort_order).to eq(1)
|
||||
expect(p1.post_number).to eq(1)
|
||||
p1.topic_id == topic.id
|
||||
p1.reply_count.should == 0
|
||||
expect(p1.reply_count).to eq(0)
|
||||
|
||||
# New first post
|
||||
new_first = new_topic.posts.where(post_number: 1).first
|
||||
new_first.reply_count.should == 1
|
||||
expect(new_first.reply_count).to eq(1)
|
||||
|
||||
# Second post is in a new topic
|
||||
p2.reload
|
||||
p2.post_number.should == 2
|
||||
p2.sort_order.should == 2
|
||||
expect(p2.post_number).to eq(2)
|
||||
expect(p2.sort_order).to eq(2)
|
||||
p2.topic_id == new_topic.id
|
||||
p2.reply_to_post_number.should == 1
|
||||
p2.reply_count.should == 0
|
||||
expect(p2.reply_to_post_number).to eq(1)
|
||||
expect(p2.reply_count).to eq(0)
|
||||
|
||||
topic.reload
|
||||
topic.posts.by_post_number.should =~ [p1, p3, p4]
|
||||
topic.highest_post_number.should == p4.post_number
|
||||
expect(topic.posts.by_post_number).to match_array([p1, p3, p4])
|
||||
expect(topic.highest_post_number).to eq(p4.post_number)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -195,26 +195,26 @@ describe PostMover do
|
|||
it "works correctly" do
|
||||
destination_deleted_reply.trash!
|
||||
|
||||
moved_to.should == destination_topic
|
||||
expect(moved_to).to eq(destination_topic)
|
||||
|
||||
# Check out new topic
|
||||
moved_to.reload
|
||||
moved_to.posts_count.should == 3
|
||||
moved_to.highest_post_number.should == 4
|
||||
expect(moved_to.posts_count).to eq(3)
|
||||
expect(moved_to.highest_post_number).to eq(4)
|
||||
|
||||
# Posts should be re-ordered
|
||||
p2.reload
|
||||
p2.sort_order.should == 3
|
||||
p2.post_number.should == 3
|
||||
p2.topic_id.should == moved_to.id
|
||||
p2.reply_count.should == 1
|
||||
p2.reply_to_post_number.should == nil
|
||||
expect(p2.sort_order).to eq(3)
|
||||
expect(p2.post_number).to eq(3)
|
||||
expect(p2.topic_id).to eq(moved_to.id)
|
||||
expect(p2.reply_count).to eq(1)
|
||||
expect(p2.reply_to_post_number).to eq(nil)
|
||||
|
||||
p4.reload
|
||||
p4.post_number.should == 4
|
||||
p4.sort_order.should == 4
|
||||
p4.topic_id.should == moved_to.id
|
||||
p4.reply_to_post_number.should == p2.post_number
|
||||
expect(p4.post_number).to eq(4)
|
||||
expect(p4.sort_order).to eq(4)
|
||||
expect(p4.topic_id).to eq(moved_to.id)
|
||||
expect(p4.reply_to_post_number).to eq(p2.post_number)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe PostReply do
|
||||
|
||||
it { should belong_to :post }
|
||||
it { should belong_to :reply }
|
||||
it { is_expected.to belong_to :post }
|
||||
it { is_expected.to belong_to :reply }
|
||||
|
||||
end
|
||||
|
|
|
@ -2,8 +2,8 @@ require 'spec_helper'
|
|||
|
||||
describe PostTiming do
|
||||
|
||||
it { should validate_presence_of :post_number }
|
||||
it { should validate_presence_of :msecs }
|
||||
it { is_expected.to validate_presence_of :post_number }
|
||||
it { is_expected.to validate_presence_of :msecs }
|
||||
|
||||
describe 'pretend_read' do
|
||||
let!(:p1) { Fabricate(:post) }
|
||||
|
@ -41,21 +41,21 @@ describe PostTiming do
|
|||
|
||||
PostTiming.pretend_read(topic_id, 2, 3)
|
||||
|
||||
PostTiming.where(topic_id: topic_id, user_id: 1, post_number: 3).count.should == 0
|
||||
PostTiming.where(topic_id: topic_id, user_id: 2, post_number: 3).count.should == 1
|
||||
PostTiming.where(topic_id: topic_id, user_id: 3, post_number: 3).count.should == 1
|
||||
expect(PostTiming.where(topic_id: topic_id, user_id: 1, post_number: 3).count).to eq(0)
|
||||
expect(PostTiming.where(topic_id: topic_id, user_id: 2, post_number: 3).count).to eq(1)
|
||||
expect(PostTiming.where(topic_id: topic_id, user_id: 3, post_number: 3).count).to eq(1)
|
||||
|
||||
tu = TopicUser.find_by(topic_id: topic_id, user_id: 1)
|
||||
tu.last_read_post_number.should == 1
|
||||
tu.highest_seen_post_number.should == 1
|
||||
expect(tu.last_read_post_number).to eq(1)
|
||||
expect(tu.highest_seen_post_number).to eq(1)
|
||||
|
||||
tu = TopicUser.find_by(topic_id: topic_id, user_id: 2)
|
||||
tu.last_read_post_number.should == 3
|
||||
tu.highest_seen_post_number.should == 3
|
||||
expect(tu.last_read_post_number).to eq(3)
|
||||
expect(tu.highest_seen_post_number).to eq(3)
|
||||
|
||||
tu = TopicUser.find_by(topic_id: topic_id, user_id: 3)
|
||||
tu.last_read_post_number.should == 3
|
||||
tu.highest_seen_post_number.should == 3
|
||||
expect(tu.last_read_post_number).to eq(3)
|
||||
expect(tu.highest_seen_post_number).to eq(3)
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -73,14 +73,14 @@ describe PostTiming do
|
|||
|
||||
PostAction.act(user2, post, PostActionType.types[:like])
|
||||
|
||||
post.user.unread_notifications.should == 1
|
||||
post.user.unread_notifications_by_type.should == {Notification.types[:liked] => 1 }
|
||||
expect(post.user.unread_notifications).to eq(1)
|
||||
expect(post.user.unread_notifications_by_type).to eq({Notification.types[:liked] => 1 })
|
||||
|
||||
PostTiming.process_timings(post.user, post.topic_id, 1, [[post.post_number, 100]])
|
||||
|
||||
post.user.reload
|
||||
post.user.unread_notifications_by_type.should == {}
|
||||
post.user.unread_notifications.should == 0
|
||||
expect(post.user.unread_notifications_by_type).to eq({})
|
||||
expect(post.user.unread_notifications).to eq(0)
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -94,10 +94,10 @@ describe PostTiming do
|
|||
end
|
||||
|
||||
it 'adds a view to the post' do
|
||||
lambda {
|
||||
expect {
|
||||
PostTiming.record_timing(@timing_attrs)
|
||||
@post.reload
|
||||
}.should change(@post, :reads).by(1)
|
||||
}.to change(@post, :reads).by(1)
|
||||
end
|
||||
|
||||
describe 'multiple calls' do
|
||||
|
@ -106,10 +106,10 @@ describe PostTiming do
|
|||
PostTiming.record_timing(@timing_attrs)
|
||||
timing = PostTiming.find_by(topic_id: @post.topic_id, user_id: @coding_horror.id, post_number: @post.post_number)
|
||||
|
||||
timing.should be_present
|
||||
timing.msecs.should == 2468
|
||||
expect(timing).to be_present
|
||||
expect(timing.msecs).to eq(2468)
|
||||
|
||||
@coding_horror.user_stat.posts_read_count.should == 1
|
||||
expect(@coding_horror.user_stat.posts_read_count).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -118,25 +118,25 @@ describe PostTiming do
|
|||
|
||||
describe 'posts' do
|
||||
it 'has no avg_time by default' do
|
||||
@post.avg_time.should be_blank
|
||||
expect(@post.avg_time).to be_blank
|
||||
end
|
||||
|
||||
it "doesn't change when we calculate the avg time for the post because there's no timings" do
|
||||
Post.calculate_avg_time
|
||||
@post.reload
|
||||
@post.avg_time.should be_blank
|
||||
expect(@post.avg_time).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
describe 'topics' do
|
||||
it 'has no avg_time by default' do
|
||||
@topic.avg_time.should be_blank
|
||||
expect(@topic.avg_time).to be_blank
|
||||
end
|
||||
|
||||
it "doesn't change when we calculate the avg time for the post because there's no timings" do
|
||||
Topic.calculate_avg_time
|
||||
@topic.reload
|
||||
@topic.avg_time.should be_blank
|
||||
expect(@topic.avg_time).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -145,7 +145,7 @@ describe PostTiming do
|
|||
PostTiming.record_timing(@timing_attrs.merge(user_id: @post.user_id))
|
||||
Post.calculate_avg_time
|
||||
@post.reload
|
||||
@post.avg_time.should be_blank
|
||||
expect(@post.avg_time).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -158,7 +158,7 @@ describe PostTiming do
|
|||
end
|
||||
|
||||
it 'has a post avg_time from the timing' do
|
||||
@post.avg_time.should be_present
|
||||
expect(@post.avg_time).to be_present
|
||||
end
|
||||
|
||||
describe 'forum topics' do
|
||||
|
@ -168,7 +168,7 @@ describe PostTiming do
|
|||
end
|
||||
|
||||
it 'has an avg_time from the timing' do
|
||||
@topic.avg_time.should be_present
|
||||
expect(@topic.avg_time).to be_present
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe PostUpload do
|
||||
|
||||
it { should belong_to :post }
|
||||
it { should belong_to :upload }
|
||||
it { is_expected.to belong_to :post }
|
||||
it { is_expected.to belong_to :upload }
|
||||
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ describe Report do
|
|||
|
||||
context "no visits" do
|
||||
it "returns an empty report" do
|
||||
report.data.should be_blank
|
||||
expect(report.data).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,7 +38,7 @@ describe Report do
|
|||
|
||||
context "no #{pluralized}" do
|
||||
it 'returns an empty report' do
|
||||
report.data.should be_blank
|
||||
expect(report.data).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -65,14 +65,14 @@ describe Report do
|
|||
|
||||
context 'returns a report with data'
|
||||
it 'with 30 days data' do
|
||||
report.data.count.should == 4
|
||||
expect(report.data.count).to eq(4)
|
||||
end
|
||||
|
||||
it 'has correct data sorted as asc' do
|
||||
report.data[0][:y].should == 1 # 30.days.ago
|
||||
report.data[1][:y].should == 1 # 2.days.ago
|
||||
report.data[2][:y].should == 1 # 1.day.ago
|
||||
report.data[3][:y].should == 3 # today
|
||||
expect(report.data[0][:y]).to eq(1) # 30.days.ago
|
||||
expect(report.data[1][:y]).to eq(1) # 2.days.ago
|
||||
expect(report.data[2][:y]).to eq(1) # 1.day.ago
|
||||
expect(report.data[3][:y]).to eq(3) # today
|
||||
end
|
||||
|
||||
it "returns today's data" do
|
||||
|
@ -97,8 +97,8 @@ describe Report do
|
|||
Fabricate(:private_message_topic, created_at: 1.hour.ago)
|
||||
Fabricate(:topic, created_at: 1.hour.ago)
|
||||
report = Report.find('topics')
|
||||
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
|
||||
|
||||
it 'post report should not include private messages' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe TopicAllowedUser do
|
||||
it { should belong_to :user }
|
||||
it { should belong_to :topic }
|
||||
it { is_expected.to belong_to :user }
|
||||
it { is_expected.to belong_to :topic }
|
||||
end
|
||||
|
|
|
@ -2,9 +2,9 @@ require 'spec_helper'
|
|||
|
||||
describe TopicEmbed do
|
||||
|
||||
it { should belong_to :topic }
|
||||
it { should belong_to :post }
|
||||
it { should validate_presence_of :embed_url }
|
||||
it { is_expected.to belong_to :topic }
|
||||
it { is_expected.to belong_to :post }
|
||||
it { is_expected.to validate_presence_of :embed_url }
|
||||
|
||||
context '.import' do
|
||||
|
||||
|
@ -14,42 +14,42 @@ describe TopicEmbed do
|
|||
let(:contents) { "hello world new post <a href='/hello'>hello</a> <img src='/images/wat.jpg'>" }
|
||||
|
||||
it "returns nil when the URL is malformed" do
|
||||
TopicEmbed.import(user, "invalid url", title, contents).should == nil
|
||||
TopicEmbed.count.should == 0
|
||||
expect(TopicEmbed.import(user, "invalid url", title, contents)).to eq(nil)
|
||||
expect(TopicEmbed.count).to eq(0)
|
||||
end
|
||||
|
||||
context 'creation of a post' do
|
||||
let!(:post) { TopicEmbed.import(user, url, title, contents) }
|
||||
|
||||
it "works as expected with a new URL" do
|
||||
post.should be_present
|
||||
expect(post).to be_present
|
||||
|
||||
# It uses raw_html rendering
|
||||
post.cook_method.should == Post.cook_methods[:raw_html]
|
||||
post.cooked.should == post.raw
|
||||
expect(post.cook_method).to eq(Post.cook_methods[:raw_html])
|
||||
expect(post.cooked).to eq(post.raw)
|
||||
|
||||
# It converts relative URLs to absolute
|
||||
post.cooked.start_with?("hello world new post <a href=\"http://eviltrout.com/hello\">hello</a> <img src=\"http://eviltrout.com/images/wat.jpg\">").should == true
|
||||
expect(post.cooked.start_with?("hello world new post <a href=\"http://eviltrout.com/hello\">hello</a> <img src=\"http://eviltrout.com/images/wat.jpg\">")).to eq(true)
|
||||
|
||||
post.topic.has_topic_embed?.should == true
|
||||
TopicEmbed.where(topic_id: post.topic_id).should be_present
|
||||
expect(post.topic.has_topic_embed?).to eq(true)
|
||||
expect(TopicEmbed.where(topic_id: post.topic_id)).to be_present
|
||||
end
|
||||
|
||||
it "Supports updating the post" do
|
||||
post = TopicEmbed.import(user, url, title, "muhahaha new contents!")
|
||||
post.cooked.should =~ /new contents/
|
||||
expect(post.cooked).to match(/new contents/)
|
||||
end
|
||||
|
||||
it "Should leave uppercase Feed Entry URL untouched in content" do
|
||||
cased_url = 'http://eviltrout.com/ABCD'
|
||||
post = TopicEmbed.import(user, cased_url, title, "some random content")
|
||||
post.cooked.should =~ /#{cased_url}/
|
||||
expect(post.cooked).to match(/#{cased_url}/)
|
||||
end
|
||||
|
||||
it "Should leave lowercase Feed Entry URL untouched in content" do
|
||||
cased_url = 'http://eviltrout.com/abcd'
|
||||
post = TopicEmbed.import(user, cased_url, title, "some random content")
|
||||
post.cooked.should =~ /#{cased_url}/
|
||||
expect(post.cooked).to match(/#{cased_url}/)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ describe TopicFeaturedUsers do
|
|||
|
||||
t.reload
|
||||
|
||||
t.featured_user1_id.should == p2.user_id
|
||||
t.featured_user2_id.should == p4.user_id
|
||||
t.featured_user3_id.should == nil
|
||||
t.featured_user4_id.should == nil
|
||||
expect(t.featured_user1_id).to eq(p2.user_id)
|
||||
expect(t.featured_user2_id).to eq(p4.user_id)
|
||||
expect(t.featured_user3_id).to eq(nil)
|
||||
expect(t.featured_user4_id).to eq(nil)
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -2,9 +2,9 @@ require 'spec_helper'
|
|||
|
||||
describe TopicInvite do
|
||||
|
||||
it { should belong_to :topic }
|
||||
it { should belong_to :invite }
|
||||
it { should validate_presence_of :topic_id }
|
||||
it { should validate_presence_of :invite_id }
|
||||
it { is_expected.to belong_to :topic }
|
||||
it { is_expected.to belong_to :invite }
|
||||
it { is_expected.to validate_presence_of :topic_id }
|
||||
it { is_expected.to validate_presence_of :invite_id }
|
||||
|
||||
end
|
||||
|
|
|
@ -2,9 +2,9 @@ require 'spec_helper'
|
|||
|
||||
describe TopicLinkClick do
|
||||
|
||||
it { should belong_to :topic_link }
|
||||
it { should belong_to :user }
|
||||
it { should validate_presence_of :topic_link_id }
|
||||
it { is_expected.to belong_to :topic_link }
|
||||
it { is_expected.to belong_to :user }
|
||||
it { is_expected.to validate_presence_of :topic_link_id }
|
||||
|
||||
def test_uri
|
||||
URI.parse('http://test.host')
|
||||
|
@ -19,7 +19,7 @@ describe TopicLinkClick do
|
|||
end
|
||||
|
||||
it 'has 0 clicks at first' do
|
||||
@topic_link.clicks.should == 0
|
||||
expect(@topic_link.clicks).to eq(0)
|
||||
end
|
||||
|
||||
context 'create' do
|
||||
|
@ -28,16 +28,16 @@ describe TopicLinkClick do
|
|||
end
|
||||
|
||||
it 'creates the forum topic link click' do
|
||||
TopicLinkClick.count.should == 1
|
||||
expect(TopicLinkClick.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'has 0 clicks at first' do
|
||||
@topic_link.reload
|
||||
@topic_link.clicks.should == 1
|
||||
expect(@topic_link.clicks).to eq(1)
|
||||
end
|
||||
|
||||
it 'serializes and deserializes the IP' do
|
||||
TopicLinkClick.first.ip_address.to_s.should == '192.168.1.1'
|
||||
expect(TopicLinkClick.first.ip_address.to_s).to eq('192.168.1.1')
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -48,15 +48,15 @@ describe TopicLinkClick do
|
|||
let(:click) { TopicLinkClick.create_from(url: "url that doesn't exist", post_id: @post.id, ip: '127.0.0.1') }
|
||||
|
||||
it "returns nil" do
|
||||
click.should == nil
|
||||
expect(click).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'clicking on your own link' do
|
||||
it "should not record the click" do
|
||||
lambda {
|
||||
expect {
|
||||
TopicLinkClick.create_from(url: @topic_link.url, post_id: @post.id, ip: '127.0.0.0', user_id: @post.user_id)
|
||||
}.should_not change(TopicLinkClick, :count)
|
||||
}.not_to change(TopicLinkClick, :count)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -67,14 +67,14 @@ describe TopicLinkClick do
|
|||
end
|
||||
|
||||
it 'creates a click' do
|
||||
@click.should be_present
|
||||
@click.topic_link.should == @topic_link
|
||||
@url.should == @topic_link.url
|
||||
expect(@click).to be_present
|
||||
expect(@click.topic_link).to eq(@topic_link)
|
||||
expect(@url).to eq(@topic_link.url)
|
||||
end
|
||||
|
||||
context "clicking again" do
|
||||
it "should not record the click due to rate limiting" do
|
||||
-> { TopicLinkClick.create_from(url: @topic_link.url, post_id: @post.id, ip: '127.0.0.1') }.should_not change(TopicLinkClick, :count)
|
||||
expect { TopicLinkClick.create_from(url: @topic_link.url, post_id: @post.id, ip: '127.0.0.1') }.not_to change(TopicLinkClick, :count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -84,19 +84,19 @@ describe TopicLinkClick do
|
|||
|
||||
it 'returns the url' do
|
||||
url = TopicLinkClick.create_from(url: '/relative-url', post_id: @post.id, ip: '127.0.0.1')
|
||||
url.should == "/relative-url"
|
||||
expect(url).to eq("/relative-url")
|
||||
end
|
||||
|
||||
it 'finds a protocol relative urls with a host' do
|
||||
url = "//#{host}/relative-url"
|
||||
redirect = TopicLinkClick.create_from(url: url)
|
||||
redirect.should == url
|
||||
expect(redirect).to eq(url)
|
||||
end
|
||||
|
||||
it "returns the url if it's on our host" do
|
||||
url = "http://#{host}/relative-url"
|
||||
redirect = TopicLinkClick.create_from(url: url)
|
||||
redirect.should == url
|
||||
expect(redirect).to eq(url)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -107,9 +107,9 @@ describe TopicLinkClick do
|
|||
end
|
||||
|
||||
it 'creates a click' do
|
||||
@click.should be_present
|
||||
@click.topic_link.should == @topic_link
|
||||
@url.should == 'https://twitter.com'
|
||||
expect(@click).to be_present
|
||||
expect(@click.topic_link).to eq(@topic_link)
|
||||
expect(@url).to eq('https://twitter.com')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,9 +120,9 @@ describe TopicLinkClick do
|
|||
end
|
||||
|
||||
it 'creates a click' do
|
||||
@click.should be_present
|
||||
@click.topic_link.should == @topic_link
|
||||
@url.should == @topic_link.url
|
||||
expect(@click).to be_present
|
||||
expect(@click.topic_link).to eq(@topic_link)
|
||||
expect(@url).to eq(@topic_link.url)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe TopicLink do
|
||||
|
||||
it { should validate_presence_of :url }
|
||||
it { is_expected.to validate_presence_of :url }
|
||||
|
||||
def test_uri
|
||||
URI.parse(Discourse.base_url)
|
||||
|
@ -20,7 +20,7 @@ describe TopicLink do
|
|||
ftl = TopicLink.new(url: "/t/#{topic.id}",
|
||||
topic_id: topic.id,
|
||||
link_topic_id: topic.id)
|
||||
ftl.valid?.should == false
|
||||
expect(ftl.valid?).to eq(false)
|
||||
end
|
||||
|
||||
describe 'external links' do
|
||||
|
@ -37,13 +37,13 @@ http://b.com/#{'a'*500}
|
|||
|
||||
it 'works' do
|
||||
# has the forum topic links
|
||||
topic.topic_links.count.should == 2
|
||||
expect(topic.topic_links.count).to eq(2)
|
||||
|
||||
# works with markdown links
|
||||
topic.topic_links.exists?(url: "http://a.com/").should == true
|
||||
expect(topic.topic_links.exists?(url: "http://a.com/")).to eq(true)
|
||||
|
||||
#works with markdown links followed by a period
|
||||
topic.topic_links.exists?(url: "http://b.com/b").should == true
|
||||
expect(topic.topic_links.exists?(url: "http://b.com/b")).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -66,9 +66,9 @@ http://b.com/#{'a'*500}
|
|||
|
||||
link = topic.topic_links.first
|
||||
# should have a link
|
||||
link.should be_present
|
||||
expect(link).to be_present
|
||||
# should be the canonical URL
|
||||
link.url.should == url
|
||||
expect(link.url).to eq(url)
|
||||
end
|
||||
|
||||
|
||||
|
@ -95,24 +95,24 @@ http://b.com/#{'a'*500}
|
|||
TopicLink.extract_from(linked_post)
|
||||
|
||||
link = topic.topic_links.first
|
||||
link.should be_present
|
||||
link.should be_internal
|
||||
link.url.should == url
|
||||
link.domain.should == test_uri.host
|
||||
expect(link).to be_present
|
||||
expect(link).to be_internal
|
||||
expect(link.url).to eq(url)
|
||||
expect(link.domain).to eq(test_uri.host)
|
||||
link.link_topic_id == other_topic.id
|
||||
link.should_not be_reflection
|
||||
expect(link).not_to be_reflection
|
||||
|
||||
reflection = other_topic.topic_links.first
|
||||
|
||||
reflection.should be_present
|
||||
reflection.should be_reflection
|
||||
reflection.post_id.should be_present
|
||||
reflection.domain.should == test_uri.host
|
||||
reflection.url.should == "http://#{test_uri.host}/t/unique-topic-name/#{topic.id}/#{linked_post.post_number}"
|
||||
reflection.link_topic_id.should == topic.id
|
||||
reflection.link_post_id.should == linked_post.id
|
||||
expect(reflection).to be_present
|
||||
expect(reflection).to be_reflection
|
||||
expect(reflection.post_id).to be_present
|
||||
expect(reflection.domain).to eq(test_uri.host)
|
||||
expect(reflection.url).to eq("http://#{test_uri.host}/t/unique-topic-name/#{topic.id}/#{linked_post.post_number}")
|
||||
expect(reflection.link_topic_id).to eq(topic.id)
|
||||
expect(reflection.link_post_id).to eq(linked_post.id)
|
||||
|
||||
reflection.user_id.should == link.user_id
|
||||
expect(reflection.user_id).to eq(link.user_id)
|
||||
end
|
||||
|
||||
context 'removing a link' do
|
||||
|
@ -123,9 +123,9 @@ http://b.com/#{'a'*500}
|
|||
end
|
||||
|
||||
it 'should remove the link' do
|
||||
topic.topic_links.where(post_id: post.id).should be_blank
|
||||
expect(topic.topic_links.where(post_id: post.id)).to be_blank
|
||||
# should remove the reflected link
|
||||
other_topic.topic_links.should be_blank
|
||||
expect(other_topic.topic_links).to be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -137,7 +137,7 @@ http://b.com/#{'a'*500}
|
|||
end
|
||||
|
||||
it 'does not extract a link' do
|
||||
topic.topic_links.should be_blank
|
||||
expect(topic.topic_links).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -148,7 +148,7 @@ http://b.com/#{'a'*500}
|
|||
end
|
||||
|
||||
it 'does not extract a link' do
|
||||
topic.topic_links.should be_present
|
||||
expect(topic.topic_links).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -160,7 +160,7 @@ http://b.com/#{'a'*500}
|
|||
end
|
||||
|
||||
it 'does not extract a link' do
|
||||
topic.topic_links.should be_blank
|
||||
expect(topic.topic_links).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -172,8 +172,8 @@ http://b.com/#{'a'*500}
|
|||
TopicLink.extract_from(quoting_post)
|
||||
link = quoting_post.topic.topic_links.first
|
||||
|
||||
link.link_post_id.should == linked_post.id
|
||||
link.quote.should == true
|
||||
expect(link.link_post_id).to eq(linked_post.id)
|
||||
expect(link.quote).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -184,13 +184,13 @@ http://b.com/#{'a'*500}
|
|||
TopicLink.extract_from(post)
|
||||
link = topic.topic_links.first
|
||||
# extracted the link
|
||||
link.should be_present
|
||||
expect(link).to be_present
|
||||
# is set to internal
|
||||
link.should be_internal
|
||||
expect(link).to be_internal
|
||||
# has the correct url
|
||||
link.url.should == "/uploads/default/208/87bb3d8428eb4783.rb"
|
||||
expect(link.url).to eq("/uploads/default/208/87bb3d8428eb4783.rb")
|
||||
# should not be the reflection
|
||||
link.should_not be_reflection
|
||||
expect(link).not_to be_reflection
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -202,13 +202,13 @@ http://b.com/#{'a'*500}
|
|||
TopicLink.extract_from(post)
|
||||
link = topic.topic_links.first
|
||||
# extracted the link
|
||||
link.should be_present
|
||||
expect(link).to be_present
|
||||
# is not internal
|
||||
link.should_not be_internal
|
||||
expect(link).not_to be_internal
|
||||
# has the correct url
|
||||
link.url.should == "//s3.amazonaws.com/bucket/2104a0211c9ce41ed67989a1ed62e9a394c1fbd1446.rb"
|
||||
expect(link.url).to eq("//s3.amazonaws.com/bucket/2104a0211c9ce41ed67989a1ed62e9a394c1fbd1446.rb")
|
||||
# should not be the reflection
|
||||
link.should_not be_reflection
|
||||
expect(link).not_to be_reflection
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -227,8 +227,8 @@ http://b.com/#{'a'*500}
|
|||
|
||||
TopicLink.extract_from(linked_post)
|
||||
|
||||
topic.topic_links.first.should == nil
|
||||
pm.topic_links.first.should_not == nil
|
||||
expect(topic.topic_links.first).to eq(nil)
|
||||
expect(pm.topic_links.first).not_to eq(nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -245,13 +245,13 @@ http://b.com/#{'a'*500}
|
|||
TopicLink.extract_from(post)
|
||||
reflection = other_topic.topic_links.first
|
||||
|
||||
reflection.url.should == "http://#{alternate_uri.host}:5678/t/unique-topic-name/#{topic.id}"
|
||||
expect(reflection.url).to eq("http://#{alternate_uri.host}:5678/t/unique-topic-name/#{topic.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'counts_for and topic_map' do
|
||||
it 'returns blank without posts' do
|
||||
TopicLink.counts_for(Guardian.new, nil, nil).should be_blank
|
||||
expect(TopicLink.counts_for(Guardian.new, nil, nil)).to be_blank
|
||||
end
|
||||
|
||||
context 'with data' do
|
||||
|
@ -271,13 +271,13 @@ http://b.com/#{'a'*500}
|
|||
topic_link = post.topic.topic_links.first
|
||||
TopicLinkClick.create(topic_link: topic_link, ip_address: '192.168.1.1')
|
||||
|
||||
counts_for[post.id].should be_present
|
||||
counts_for[post.id].find {|l| l[:url] == 'http://google.com'}[:clicks].should == 0
|
||||
counts_for[post.id].first[:clicks].should == 1
|
||||
expect(counts_for[post.id]).to be_present
|
||||
expect(counts_for[post.id].find {|l| l[:url] == 'http://google.com'}[:clicks]).to eq(0)
|
||||
expect(counts_for[post.id].first[:clicks]).to eq(1)
|
||||
|
||||
array = TopicLink.topic_map(Guardian.new, post.topic_id)
|
||||
array.length.should == 4
|
||||
array[0]["clicks"].should == "1"
|
||||
expect(array.length).to eq(4)
|
||||
expect(array[0]["clicks"]).to eq("1")
|
||||
end
|
||||
|
||||
it 'secures internal links correctly' do
|
||||
|
@ -288,19 +288,19 @@ http://b.com/#{'a'*500}
|
|||
post = Fabricate(:post, raw: "hello test topic #{url}")
|
||||
TopicLink.extract_from(post)
|
||||
|
||||
TopicLink.topic_map(Guardian.new, post.topic_id).count.should == 1
|
||||
TopicLink.counts_for(Guardian.new, post.topic, [post]).length.should == 1
|
||||
expect(TopicLink.topic_map(Guardian.new, post.topic_id).count).to eq(1)
|
||||
expect(TopicLink.counts_for(Guardian.new, post.topic, [post]).length).to eq(1)
|
||||
|
||||
category.set_permissions(:staff => :full)
|
||||
category.save
|
||||
|
||||
admin = Fabricate(:admin)
|
||||
|
||||
TopicLink.topic_map(Guardian.new, post.topic_id).count.should == 0
|
||||
TopicLink.topic_map(Guardian.new(admin), post.topic_id).count.should == 1
|
||||
expect(TopicLink.topic_map(Guardian.new, post.topic_id).count).to eq(0)
|
||||
expect(TopicLink.topic_map(Guardian.new(admin), post.topic_id).count).to eq(1)
|
||||
|
||||
TopicLink.counts_for(Guardian.new, post.topic, [post]).length.should == 0
|
||||
TopicLink.counts_for(Guardian.new(admin), post.topic, [post]).length.should == 1
|
||||
expect(TopicLink.counts_for(Guardian.new, post.topic, [post]).length).to eq(0)
|
||||
expect(TopicLink.counts_for(Guardian.new(admin), post.topic, [post]).length).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -19,10 +19,10 @@ describe TopicStatusUpdate do
|
|||
|
||||
TopicStatusUpdate.new(post.topic, admin).update!("autoclosed", true)
|
||||
|
||||
post.topic.posts.count.should == 2
|
||||
expect(post.topic.posts.count).to eq(2)
|
||||
|
||||
tu = TopicUser.find_by(user_id: user.id)
|
||||
tu.last_read_post_number.should == 2
|
||||
expect(tu.last_read_post_number).to eq(2)
|
||||
end
|
||||
|
||||
it "adds an autoclosed message" do
|
||||
|
@ -30,7 +30,7 @@ describe TopicStatusUpdate do
|
|||
|
||||
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
||||
|
||||
topic.posts.last.raw.should == I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0)
|
||||
expect(topic.posts.last.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_minutes", count: 0))
|
||||
end
|
||||
|
||||
it "adds an autoclosed message based on last post" do
|
||||
|
@ -39,7 +39,7 @@ describe TopicStatusUpdate do
|
|||
|
||||
TopicStatusUpdate.new(topic, admin).update!("autoclosed", true)
|
||||
|
||||
topic.posts.last.raw.should == I18n.t("topic_statuses.autoclosed_enabled_lastpost_minutes", count: 0)
|
||||
expect(topic.posts.last.raw).to eq(I18n.t("topic_statuses.autoclosed_enabled_lastpost_minutes", count: 0))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -17,39 +17,39 @@ describe TopicTrackingState do
|
|||
|
||||
it "correctly gets the tracking state" do
|
||||
report = TopicTrackingState.report([user.id])
|
||||
report.length.should == 0
|
||||
expect(report.length).to eq(0)
|
||||
|
||||
new_post = post
|
||||
post.topic.notifier.watch_topic!(post.topic.user_id)
|
||||
|
||||
report = TopicTrackingState.report([user.id])
|
||||
|
||||
report.length.should == 1
|
||||
expect(report.length).to eq(1)
|
||||
row = report[0]
|
||||
|
||||
row.topic_id.should == post.topic_id
|
||||
row.highest_post_number.should == 1
|
||||
row.last_read_post_number.should == nil
|
||||
row.user_id.should == user.id
|
||||
expect(row.topic_id).to eq(post.topic_id)
|
||||
expect(row.highest_post_number).to eq(1)
|
||||
expect(row.last_read_post_number).to eq(nil)
|
||||
expect(row.user_id).to eq(user.id)
|
||||
|
||||
# lets not leak out random users
|
||||
TopicTrackingState.report([post.user_id]).should be_empty
|
||||
expect(TopicTrackingState.report([post.user_id])).to be_empty
|
||||
|
||||
# lets not return anything if we scope on non-existing topic
|
||||
TopicTrackingState.report([user.id], post.topic_id + 1).should be_empty
|
||||
expect(TopicTrackingState.report([user.id], post.topic_id + 1)).to be_empty
|
||||
|
||||
# when we reply the poster should have an unread row
|
||||
create_post(user: user, topic: post.topic)
|
||||
|
||||
report = TopicTrackingState.report([post.user_id, user.id])
|
||||
report.length.should == 1
|
||||
expect(report.length).to eq(1)
|
||||
|
||||
row = report[0]
|
||||
|
||||
row.topic_id.should == post.topic_id
|
||||
row.highest_post_number.should == 2
|
||||
row.last_read_post_number.should == 1
|
||||
row.user_id.should == post.user_id
|
||||
expect(row.topic_id).to eq(post.topic_id)
|
||||
expect(row.highest_post_number).to eq(2)
|
||||
expect(row.last_read_post_number).to eq(1)
|
||||
expect(row.user_id).to eq(post.user_id)
|
||||
|
||||
# when we have no permission to see a category, don't show its stats
|
||||
category = Fabricate(:category, read_restricted: true)
|
||||
|
@ -57,6 +57,6 @@ describe TopicTrackingState do
|
|||
post.topic.category_id = category.id
|
||||
post.topic.save
|
||||
|
||||
TopicTrackingState.report([post.user_id, user.id]).count.should == 0
|
||||
expect(TopicTrackingState.report([post.user_id, user.id]).count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,7 @@ describe TopicViewItem do
|
|||
TopicViewItem.create!(topic_id: 1, ip_address: "1.1.1.1", viewed_at: 1.day.ago)
|
||||
add(1, "1.1.1.1")
|
||||
|
||||
TopicViewItem.count.should == 3
|
||||
expect(TopicViewItem.count).to eq(3)
|
||||
end
|
||||
|
||||
it "increases a users view count" do
|
||||
|
@ -24,7 +24,7 @@ describe TopicViewItem do
|
|||
add(1, "1.1.1.1", user.id)
|
||||
|
||||
user.user_stat.reload
|
||||
user.user_stat.topics_entered.should == 1
|
||||
expect(user.user_stat.topics_entered).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -16,51 +16,51 @@ describe TrustLevel3Requirements do
|
|||
describe "requirements" do
|
||||
it "min_days_visited uses site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_days_visited).returns(66)
|
||||
tl3_requirements.min_days_visited.should == 66
|
||||
expect(tl3_requirements.min_days_visited).to eq(66)
|
||||
end
|
||||
|
||||
it "min_topics_replied_to uses site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_topics_replied_to).returns(12)
|
||||
tl3_requirements.min_topics_replied_to.should == 12
|
||||
expect(tl3_requirements.min_topics_replied_to).to eq(12)
|
||||
end
|
||||
|
||||
it "min_topics_viewed depends on site setting and number of topics created" do
|
||||
SiteSetting.stubs(:tl3_requires_topics_viewed).returns(75)
|
||||
described_class.stubs(:num_topics_in_time_period).returns(31)
|
||||
tl3_requirements.min_topics_viewed.should == 23
|
||||
expect(tl3_requirements.min_topics_viewed).to eq(23)
|
||||
end
|
||||
|
||||
it "min_posts_read depends on site setting and number of posts created" do
|
||||
SiteSetting.stubs(:tl3_requires_posts_read).returns(66)
|
||||
described_class.stubs(:num_posts_in_time_period).returns(1234)
|
||||
tl3_requirements.min_posts_read.should == 814
|
||||
expect(tl3_requirements.min_posts_read).to eq(814)
|
||||
end
|
||||
|
||||
it "min_topics_viewed_all_time depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_topics_viewed_all_time).returns(75)
|
||||
tl3_requirements.min_topics_viewed_all_time.should == 75
|
||||
expect(tl3_requirements.min_topics_viewed_all_time).to eq(75)
|
||||
end
|
||||
|
||||
it "min_posts_read_all_time depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_posts_read_all_time).returns(1001)
|
||||
tl3_requirements.min_posts_read_all_time.should == 1001
|
||||
expect(tl3_requirements.min_posts_read_all_time).to eq(1001)
|
||||
end
|
||||
|
||||
it "max_flagged_posts depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_max_flagged).returns(3)
|
||||
tl3_requirements.max_flagged_posts.should == 3
|
||||
expect(tl3_requirements.max_flagged_posts).to eq(3)
|
||||
end
|
||||
|
||||
it "min_likes_given depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_likes_given).returns(30)
|
||||
tl3_requirements.min_likes_given.should == 30
|
||||
expect(tl3_requirements.min_likes_given).to eq(30)
|
||||
end
|
||||
|
||||
it "min_likes_received depends on site setting" do
|
||||
SiteSetting.stubs(:tl3_requires_likes_received).returns(20)
|
||||
tl3_requirements.min_likes_received.should == 20
|
||||
tl3_requirements.min_likes_received_days.should == 7
|
||||
tl3_requirements.min_likes_received_users.should == 5
|
||||
expect(tl3_requirements.min_likes_received).to eq(20)
|
||||
expect(tl3_requirements.min_likes_received_days).to eq(7)
|
||||
expect(tl3_requirements.min_likes_received_users).to eq(5)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -71,7 +71,7 @@ describe TrustLevel3Requirements do
|
|||
user.update_posts_read!(1, 3.days.ago)
|
||||
user.update_posts_read!(0, 4.days.ago)
|
||||
user.update_posts_read!(3, 101.days.ago)
|
||||
tl3_requirements.days_visited.should == 2
|
||||
expect(tl3_requirements.days_visited).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -88,7 +88,7 @@ describe TrustLevel3Requirements do
|
|||
topic2 = create_post(created_at: 101.days.ago).topic
|
||||
_reply2 = create_post(topic: topic2, user: user, created_at: 101.days.ago) # topic is over 100 days old
|
||||
|
||||
tl3_requirements.num_topics_replied_to.should == 1
|
||||
expect(tl3_requirements.num_topics_replied_to).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -99,7 +99,7 @@ describe TrustLevel3Requirements do
|
|||
make_view(9, 3.days.ago, user.id) # same topic, different day
|
||||
make_view(3, 4.days.ago, user.id)
|
||||
make_view(2, 101.days.ago, user.id) # too long ago
|
||||
tl3_requirements.topics_viewed.should == 2
|
||||
expect(tl3_requirements.topics_viewed).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -110,7 +110,7 @@ describe TrustLevel3Requirements do
|
|||
user.update_posts_read!(1, 3.days.ago)
|
||||
user.update_posts_read!(0, 4.days.ago)
|
||||
user.update_posts_read!(5, 101.days.ago)
|
||||
tl3_requirements.posts_read.should == 4
|
||||
expect(tl3_requirements.posts_read).to eq(4)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,7 +120,7 @@ describe TrustLevel3Requirements do
|
|||
make_view(10, 1.day.ago, user.id)
|
||||
make_view(9, 100.days.ago, user.id)
|
||||
make_view(8, 101.days.ago, user.id)
|
||||
tl3_requirements.topics_viewed_all_time.should == 3
|
||||
expect(tl3_requirements.topics_viewed_all_time).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -129,7 +129,7 @@ describe TrustLevel3Requirements do
|
|||
user.save
|
||||
user.update_posts_read!(3, 2.days.ago)
|
||||
user.update_posts_read!(1, 101.days.ago)
|
||||
tl3_requirements.posts_read_all_time.should == 4
|
||||
expect(tl3_requirements.posts_read_all_time).to eq(4)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -159,8 +159,8 @@ describe TrustLevel3Requirements do
|
|||
end
|
||||
|
||||
it "num_flagged_posts and num_flagged_by_users count spam and inappropriate agreed flags in the last 100 days" do
|
||||
tl3_requirements.num_flagged_posts.should == 2
|
||||
tl3_requirements.num_flagged_by_users.should == 3
|
||||
expect(tl3_requirements.num_flagged_posts).to eq(2)
|
||||
expect(tl3_requirements.num_flagged_by_users).to eq(3)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -176,7 +176,7 @@ describe TrustLevel3Requirements do
|
|||
Fabricate(:like, user: user, post: recent_post2, created_at: 5.days.ago)
|
||||
Fabricate(:like, user: user, post: old_post, created_at: 101.days.ago)
|
||||
|
||||
tl3_requirements.num_likes_given.should == 2
|
||||
expect(tl3_requirements.num_likes_given).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -196,9 +196,9 @@ describe TrustLevel3Requirements do
|
|||
Fabricate(:like, user: liker, post: recent_post2, created_at: 5.days.ago)
|
||||
Fabricate(:like, user: liker, post: old_post, created_at: 101.days.ago)
|
||||
|
||||
tl3_requirements.num_likes_received.should == 3
|
||||
tl3_requirements.num_likes_received_days.should == 2
|
||||
tl3_requirements.num_likes_received_users.should == 2
|
||||
expect(tl3_requirements.num_likes_received).to eq(3)
|
||||
expect(tl3_requirements.num_likes_received_days).to eq(2)
|
||||
expect(tl3_requirements.num_likes_received_users).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -233,12 +233,12 @@ describe TrustLevel3Requirements do
|
|||
end
|
||||
|
||||
it "are met when all requirements are met" do
|
||||
tl3_requirements.requirements_met?.should == true
|
||||
expect(tl3_requirements.requirements_met?).to eq(true)
|
||||
end
|
||||
|
||||
it "are not met if too few days visited" do
|
||||
tl3_requirements.stubs(:days_visited).returns(49)
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
expect(tl3_requirements.requirements_met?).to eq(false)
|
||||
end
|
||||
|
||||
it "are not lost if requirements are close" do
|
||||
|
@ -248,77 +248,77 @@ describe TrustLevel3Requirements do
|
|||
tl3_requirements.stubs(:posts_read).returns(23)
|
||||
tl3_requirements.stubs(:num_likes_given).returns(29)
|
||||
tl3_requirements.stubs(:num_likes_received).returns(19)
|
||||
tl3_requirements.requirements_lost?.should == false
|
||||
expect(tl3_requirements.requirements_lost?).to eq(false)
|
||||
end
|
||||
|
||||
it "are lost if not enough visited" do
|
||||
tl3_requirements.stubs(:days_visited).returns(44)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||
end
|
||||
|
||||
it "are lost if not enough topics replied to" do
|
||||
tl3_requirements.stubs(:num_topics_replied_to).returns(8)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||
end
|
||||
|
||||
it "are lost if not enough topics viewed" do
|
||||
tl3_requirements.stubs(:topics_viewed).returns(22)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||
end
|
||||
|
||||
it "are lost if not enough posts read" do
|
||||
tl3_requirements.stubs(:posts_read).returns(22)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||
end
|
||||
|
||||
it "are not met if not enough likes given" do
|
||||
tl3_requirements.stubs(:num_likes_given).returns(29)
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
expect(tl3_requirements.requirements_met?).to eq(false)
|
||||
end
|
||||
|
||||
it "are not met if not enough likes received" do
|
||||
tl3_requirements.stubs(:num_likes_received).returns(19)
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
expect(tl3_requirements.requirements_met?).to eq(false)
|
||||
end
|
||||
|
||||
it "are not met if not enough likes received on different days" do
|
||||
tl3_requirements.stubs(:num_likes_received_days).returns(6)
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
expect(tl3_requirements.requirements_met?).to eq(false)
|
||||
end
|
||||
|
||||
it "are not met if not enough likes received by different users" do
|
||||
tl3_requirements.stubs(:num_likes_received_users).returns(4)
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
expect(tl3_requirements.requirements_met?).to eq(false)
|
||||
end
|
||||
|
||||
it "are lost if not enough likes given" do
|
||||
tl3_requirements.stubs(:num_likes_given).returns(26)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||
end
|
||||
|
||||
it "are lost if not enough likes received" do
|
||||
tl3_requirements.stubs(:num_likes_received).returns(17)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||
end
|
||||
|
||||
it "are not met if suspended" do
|
||||
user.stubs(:suspended?).returns(true)
|
||||
tl3_requirements.requirements_met?.should == false
|
||||
expect(tl3_requirements.requirements_met?).to eq(false)
|
||||
end
|
||||
|
||||
it "are lost if not enough likes received on different days" do
|
||||
tl3_requirements.stubs(:num_likes_received_days).returns(4)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||
end
|
||||
|
||||
it "are lost if not enough likes received by different users" do
|
||||
tl3_requirements.stubs(:num_likes_received_users).returns(3)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||
end
|
||||
|
||||
it "are lost if suspended" do
|
||||
user.stubs(:suspended?).returns(true)
|
||||
tl3_requirements.requirements_lost?.should == true
|
||||
expect(tl3_requirements.requirements_lost?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@ describe TwitterUserInfo do
|
|||
id = 22019458041
|
||||
info = TwitterUserInfo.create!(user_id: -1, screen_name: 'sam', twitter_user_id: id)
|
||||
info.reload
|
||||
info.twitter_user_id.should == id
|
||||
expect(info.twitter_user_id).to eq(id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,12 +2,12 @@ require 'spec_helper'
|
|||
require 'digest/sha1'
|
||||
|
||||
describe Upload do
|
||||
it { should belong_to :user }
|
||||
it { is_expected.to belong_to :user }
|
||||
|
||||
it { should have_many :post_uploads }
|
||||
it { should have_many :posts }
|
||||
it { is_expected.to have_many :post_uploads }
|
||||
it { is_expected.to have_many :posts }
|
||||
|
||||
it { should have_many :optimized_images }
|
||||
it { is_expected.to have_many :optimized_images }
|
||||
|
||||
let(:upload) { build(:upload) }
|
||||
let(:thumbnail) { build(:optimized_image, upload: upload) }
|
||||
|
@ -44,7 +44,7 @@ describe Upload do
|
|||
OptimizedImage.expects(:create_for).returns(thumbnail)
|
||||
upload.create_thumbnail!(100, 100)
|
||||
upload.reload
|
||||
upload.optimized_images.count.should == 1
|
||||
expect(upload.optimized_images.count).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -56,7 +56,7 @@ describe Upload do
|
|||
it "does not create another upload if it already exists" do
|
||||
Upload.expects(:find_by).with(sha1: image_sha1).returns(upload)
|
||||
Upload.expects(:save).never
|
||||
Upload.create_for(user_id, image, image_filename, image_filesize).should == upload
|
||||
expect(Upload.create_for(user_id, image, image_filename, image_filesize)).to eq(upload)
|
||||
end
|
||||
|
||||
it "fix image orientation" do
|
||||
|
@ -75,13 +75,13 @@ describe Upload do
|
|||
FileHelper.expects(:is_image?).returns(true)
|
||||
Upload.expects(:save).never
|
||||
upload = Upload.create_for(user_id, attachment, attachment_filename, attachment_filesize)
|
||||
upload.errors.size.should > 0
|
||||
expect(upload.errors.size).to be > 0
|
||||
end
|
||||
|
||||
it "does not compute width & height for non-image" do
|
||||
FastImage.any_instance.expects(:size).never
|
||||
upload = Upload.create_for(user_id, attachment, attachment_filename, attachment_filesize)
|
||||
upload.errors.size.should > 0
|
||||
expect(upload.errors.size).to be > 0
|
||||
end
|
||||
|
||||
it "saves proper information" do
|
||||
|
@ -91,13 +91,13 @@ describe Upload do
|
|||
|
||||
upload = Upload.create_for(user_id, image, image_filename, image_filesize)
|
||||
|
||||
upload.user_id.should == user_id
|
||||
upload.original_filename.should == image_filename
|
||||
upload.filesize.should == image_filesize
|
||||
upload.sha1.should == image_sha1
|
||||
upload.width.should == 244
|
||||
upload.height.should == 66
|
||||
upload.url.should == url
|
||||
expect(upload.user_id).to eq(user_id)
|
||||
expect(upload.original_filename).to eq(image_filename)
|
||||
expect(upload.filesize).to eq(image_filesize)
|
||||
expect(upload.sha1).to eq(image_sha1)
|
||||
expect(upload.width).to eq(244)
|
||||
expect(upload.height).to eq(66)
|
||||
expect(upload.url).to eq(url)
|
||||
end
|
||||
|
||||
context "when svg is authorized" do
|
||||
|
@ -111,12 +111,12 @@ describe Upload do
|
|||
|
||||
upload = Upload.create_for(user_id, image_svg, image_svg_filename, image_svg_filesize)
|
||||
|
||||
upload.user_id.should == user_id
|
||||
upload.original_filename.should == image_svg_filename
|
||||
upload.filesize.should == image_svg_filesize
|
||||
upload.width.should == 100
|
||||
upload.height.should == 50
|
||||
upload.url.should == url
|
||||
expect(upload.user_id).to eq(user_id)
|
||||
expect(upload.original_filename).to eq(image_svg_filename)
|
||||
expect(upload.filesize).to eq(image_svg_filesize)
|
||||
expect(upload.width).to eq(100)
|
||||
expect(upload.height).to eq(50)
|
||||
expect(upload.url).to eq(url)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,8 +6,8 @@ describe UserAction do
|
|||
ActiveRecord::Base.observers.enable :all
|
||||
end
|
||||
|
||||
it { should validate_presence_of :action_type }
|
||||
it { should validate_presence_of :user_id }
|
||||
it { is_expected.to validate_presence_of :action_type }
|
||||
it { is_expected.to validate_presence_of :user_id }
|
||||
|
||||
describe 'lists' do
|
||||
|
||||
|
@ -51,18 +51,18 @@ describe UserAction do
|
|||
it 'includes the events correctly' do
|
||||
mystats = stats_for_user(user)
|
||||
expecting = [UserAction::NEW_TOPIC, UserAction::NEW_PRIVATE_MESSAGE, UserAction::GOT_PRIVATE_MESSAGE, UserAction::BOOKMARK].sort
|
||||
mystats.should == expecting
|
||||
stream_count(user).should == 4
|
||||
expect(mystats).to eq(expecting)
|
||||
expect(stream_count(user)).to eq(4)
|
||||
|
||||
other_stats = stats_for_user
|
||||
expecting = [UserAction::NEW_TOPIC]
|
||||
stream_count.should == 1
|
||||
expect(stream_count).to eq(1)
|
||||
|
||||
other_stats.should == expecting
|
||||
expect(other_stats).to eq(expecting)
|
||||
|
||||
public_topic.trash!(user)
|
||||
stats_for_user.should == []
|
||||
stream_count.should == 0
|
||||
expect(stats_for_user).to eq([])
|
||||
expect(stream_count).to eq(0)
|
||||
|
||||
# groups
|
||||
category = Fabricate(:category, read_restricted: true)
|
||||
|
@ -71,8 +71,8 @@ describe UserAction do
|
|||
public_topic.category = category
|
||||
public_topic.save
|
||||
|
||||
stats_for_user.should == []
|
||||
stream_count.should == 0
|
||||
expect(stats_for_user).to eq([])
|
||||
expect(stream_count).to eq(0)
|
||||
|
||||
group = Fabricate(:group)
|
||||
u = Fabricate(:coding_horror)
|
||||
|
@ -82,8 +82,8 @@ describe UserAction do
|
|||
category.set_permissions(group => :full)
|
||||
category.save
|
||||
|
||||
stats_for_user(u).should == [UserAction::NEW_TOPIC]
|
||||
stream_count(u).should == 1
|
||||
expect(stats_for_user(u)).to eq([UserAction::NEW_TOPIC])
|
||||
expect(stream_count(u)).to eq(1)
|
||||
|
||||
# duplicate should not exception out
|
||||
log_test_action
|
||||
|
@ -94,8 +94,8 @@ describe UserAction do
|
|||
public_post.revise(admin, { category_id: category2.id})
|
||||
|
||||
action = UserAction.stream(user_id: public_topic.user_id, guardian: Guardian.new)[0]
|
||||
action.acting_user_id.should == admin.id
|
||||
action.action_type.should == UserAction::EDIT
|
||||
expect(action.acting_user_id).to eq(admin.id)
|
||||
expect(action.action_type).to eq(UserAction::EDIT)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -116,7 +116,7 @@ describe UserAction do
|
|||
|
||||
it "creates a new stream entry" do
|
||||
PostAction.act(liker, post, PostActionType.types[:like])
|
||||
likee_stream.count.should == @old_count + 1
|
||||
expect(likee_stream.count).to eq(@old_count + 1)
|
||||
end
|
||||
|
||||
context "successful like" do
|
||||
|
@ -127,14 +127,14 @@ describe UserAction do
|
|||
end
|
||||
|
||||
it 'should result in correct data assignment' do
|
||||
@liker_action.should_not == nil
|
||||
@likee_action.should_not == nil
|
||||
likee.user_stat.reload.likes_received.should == 1
|
||||
liker.user_stat.reload.likes_given.should == 1
|
||||
expect(@liker_action).not_to eq(nil)
|
||||
expect(@likee_action).not_to eq(nil)
|
||||
expect(likee.user_stat.reload.likes_received).to eq(1)
|
||||
expect(liker.user_stat.reload.likes_given).to eq(1)
|
||||
|
||||
PostAction.remove_act(liker, post, PostActionType.types[:like])
|
||||
likee.user_stat.reload.likes_received.should == 0
|
||||
liker.user_stat.reload.likes_given.should == 0
|
||||
expect(likee.user_stat.reload.likes_received).to eq(0)
|
||||
expect(liker.user_stat.reload.likes_given).to eq(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -147,7 +147,7 @@ describe UserAction do
|
|||
|
||||
it "doesn't add the entry to the stream" do
|
||||
PostAction.act(liker, post, PostActionType.types[:like])
|
||||
likee_stream.count.should_not == @old_count + 1
|
||||
expect(likee_stream.count).not_to eq(@old_count + 1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -169,13 +169,13 @@ describe UserAction do
|
|||
@action = @post.user.user_actions.find_by(action_type: UserAction::NEW_TOPIC)
|
||||
end
|
||||
it 'should exist' do
|
||||
@action.should_not == nil
|
||||
@action.created_at.should be_within(1).of(@post.topic.created_at)
|
||||
expect(@action).not_to eq(nil)
|
||||
expect(@action.created_at).to be_within(1).of(@post.topic.created_at)
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not log a post user action' do
|
||||
@post.user.user_actions.find_by(action_type: UserAction::REPLY).should == nil
|
||||
expect(@post.user.user_actions.find_by(action_type: UserAction::REPLY)).to eq(nil)
|
||||
end
|
||||
|
||||
|
||||
|
@ -189,16 +189,16 @@ describe UserAction do
|
|||
end
|
||||
|
||||
it 'should log user actions correctly' do
|
||||
@response.user.user_actions.find_by(action_type: UserAction::REPLY).should_not == nil
|
||||
@post.user.user_actions.find_by(action_type: UserAction::RESPONSE).should_not == nil
|
||||
@mentioned.user_actions.find_by(action_type: UserAction::MENTION).should_not == nil
|
||||
@post.user.user_actions.joins(:target_post).where('posts.post_number = 2').count.should == 1
|
||||
expect(@response.user.user_actions.find_by(action_type: UserAction::REPLY)).not_to eq(nil)
|
||||
expect(@post.user.user_actions.find_by(action_type: UserAction::RESPONSE)).not_to eq(nil)
|
||||
expect(@mentioned.user_actions.find_by(action_type: UserAction::MENTION)).not_to eq(nil)
|
||||
expect(@post.user.user_actions.joins(:target_post).where('posts.post_number = 2').count).to eq(1)
|
||||
end
|
||||
|
||||
it 'should not log a double notification for a post edit' do
|
||||
@response.raw = "here it goes again"
|
||||
@response.save!
|
||||
@response.user.user_actions.where(action_type: UserAction::REPLY).count.should == 1
|
||||
expect(@response.user.user_actions.where(action_type: UserAction::REPLY).count).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -213,13 +213,13 @@ describe UserAction do
|
|||
end
|
||||
|
||||
it 'should create a bookmark action correctly' do
|
||||
@action.action_type.should == UserAction::BOOKMARK
|
||||
@action.target_post_id.should == @post.id
|
||||
@action.acting_user_id.should == @user.id
|
||||
@action.user_id.should == @user.id
|
||||
expect(@action.action_type).to eq(UserAction::BOOKMARK)
|
||||
expect(@action.target_post_id).to eq(@post.id)
|
||||
expect(@action.acting_user_id).to eq(@user.id)
|
||||
expect(@action.user_id).to eq(@user.id)
|
||||
|
||||
PostAction.remove_act(@user, @post, PostActionType.types[:bookmark])
|
||||
@user.user_actions.find_by(action_type: UserAction::BOOKMARK).should == nil
|
||||
expect(@user.user_actions.find_by(action_type: UserAction::BOOKMARK)).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -283,9 +283,9 @@ describe UserAction do
|
|||
|
||||
actions = UserAction.all.to_a
|
||||
|
||||
actions.length.should == 1
|
||||
actions.first.action_type.should == UserAction::STAR
|
||||
actions.first.user_id.should == post.user.id
|
||||
expect(actions.length).to eq(1)
|
||||
expect(actions.first.action_type).to eq(UserAction::STAR)
|
||||
expect(actions.first.user_id).to eq(post.user.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -312,7 +312,7 @@ describe UserAction do
|
|||
UserAction.synchronize_target_topic_ids
|
||||
|
||||
action.reload
|
||||
action.target_topic_id.should == post.topic_id
|
||||
expect(action.target_topic_id).to eq(post.topic_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,6 +15,6 @@ describe UserAvatar do
|
|||
FileHelper.expects(:download).returns(temp)
|
||||
avatar.update_gravatar!
|
||||
temp.unlink
|
||||
avatar.gravatar_upload.should_not == nil
|
||||
expect(avatar.gravatar_upload).not_to eq(nil)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,12 +11,12 @@ describe UserHistory do
|
|||
|
||||
it "returns all records for admins" do
|
||||
records = described_class.staff_action_records(Fabricate(:admin)).to_a
|
||||
records.size.should == 2
|
||||
expect(records.size).to eq(2)
|
||||
end
|
||||
|
||||
it "doesn't return records to moderators that only admins should see" do
|
||||
records = described_class.staff_action_records(Fabricate(:moderator)).to_a
|
||||
records.should == [@change_trust_level]
|
||||
expect(records).to eq([@change_trust_level])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe UserOpenId do
|
||||
|
||||
it { should belong_to :user }
|
||||
it { should validate_presence_of :email }
|
||||
it { should validate_presence_of :url }
|
||||
it { is_expected.to belong_to :user }
|
||||
it { is_expected.to validate_presence_of :email }
|
||||
it { is_expected.to validate_presence_of :url }
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe UserProfile do
|
||||
it 'is created automatically when a user is created' do
|
||||
user = Fabricate(:evil_trout)
|
||||
user.user_profile.should be_present
|
||||
expect(user.user_profile).to be_present
|
||||
end
|
||||
|
||||
describe 'rebaking' do
|
||||
|
@ -12,11 +12,11 @@ describe UserProfile do
|
|||
user_profile.update_columns(bio_raw: "test", bio_cooked: "broken", bio_cooked_version: nil)
|
||||
|
||||
problems = UserProfile.rebake_old(10)
|
||||
problems.length.should == 0
|
||||
expect(problems.length).to eq(0)
|
||||
|
||||
user_profile.reload
|
||||
user_profile.bio_cooked.should == "<p>test</p>"
|
||||
user_profile.bio_cooked_version.should == UserProfile::BAKED_VERSION
|
||||
expect(user_profile.bio_cooked).to eq("<p>test</p>")
|
||||
expect(user_profile.bio_cooked_version).to eq(UserProfile::BAKED_VERSION)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,7 @@ describe UserProfile do
|
|||
|
||||
it "doesn't support really long bios" do
|
||||
user_profile = Fabricate.build(:user_profile_long)
|
||||
user_profile.should_not be_valid
|
||||
expect(user_profile).not_to be_valid
|
||||
end
|
||||
|
||||
describe 'after save' do
|
||||
|
@ -65,7 +65,7 @@ describe UserProfile do
|
|||
end
|
||||
|
||||
it 'should markdown the raw_bio and put it in cooked_bio' do
|
||||
user.user_profile.bio_cooked.should == "<p><strong>turtle power!</strong></p>"
|
||||
expect(user.user_profile.bio_cooked).to eq("<p><strong>turtle power!</strong></p>")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -37,80 +37,80 @@ describe UserSearch do
|
|||
|
||||
# normal search
|
||||
results = search_for(user1.name.split(" ").first)
|
||||
results.size.should == 1
|
||||
results.first.should == user1
|
||||
expect(results.size).to eq(1)
|
||||
expect(results.first).to eq(user1)
|
||||
|
||||
# lower case
|
||||
results = search_for(user1.name.split(" ").first.downcase)
|
||||
results.size.should == 1
|
||||
results.first.should == user1
|
||||
expect(results.size).to eq(1)
|
||||
expect(results.first).to eq(user1)
|
||||
|
||||
# username
|
||||
results = search_for(user4.username)
|
||||
results.size.should == 1
|
||||
results.first.should == user4
|
||||
expect(results.size).to eq(1)
|
||||
expect(results.first).to eq(user4)
|
||||
|
||||
# case insensitive
|
||||
results = search_for(user4.username.upcase)
|
||||
results.size.should == 1
|
||||
results.first.should == user4
|
||||
expect(results.size).to eq(1)
|
||||
expect(results.first).to eq(user4)
|
||||
|
||||
# substrings
|
||||
# only staff members see suspended users in results
|
||||
results = search_for("mr")
|
||||
results.size.should == 5
|
||||
results.should_not include(user6)
|
||||
search_for("mr", searching_user: user1).size.should == 5
|
||||
expect(results.size).to eq(5)
|
||||
expect(results).not_to include(user6)
|
||||
expect(search_for("mr", searching_user: user1).size).to eq(5)
|
||||
|
||||
results = search_for("mr", searching_user: admin)
|
||||
results.size.should == 6
|
||||
results.should include(user6)
|
||||
search_for("mr", searching_user: moderator).size.should == 6
|
||||
expect(results.size).to eq(6)
|
||||
expect(results).to include(user6)
|
||||
expect(search_for("mr", searching_user: moderator).size).to eq(6)
|
||||
|
||||
results = search_for("mrb", searching_user: admin)
|
||||
results.size.should == 3
|
||||
expect(results.size).to eq(3)
|
||||
|
||||
|
||||
results = search_for("MR", searching_user: admin)
|
||||
results.size.should == 6
|
||||
expect(results.size).to eq(6)
|
||||
|
||||
results = search_for("MRB", searching_user: admin, limit: 2)
|
||||
results.size.should == 2
|
||||
expect(results.size).to eq(2)
|
||||
|
||||
# topic priority
|
||||
results = search_for("mrb", topic_id: topic.id)
|
||||
results.first.should == user1
|
||||
expect(results.first).to eq(user1)
|
||||
|
||||
|
||||
results = search_for("mrb", topic_id: topic2.id)
|
||||
results[1].should == user2
|
||||
expect(results[1]).to eq(user2)
|
||||
|
||||
results = search_for("mrb", topic_id: topic3.id)
|
||||
results[1].should == user5
|
||||
expect(results[1]).to eq(user5)
|
||||
|
||||
# When searching by name is enabled, it returns the record
|
||||
SiteSetting.enable_names = true
|
||||
results = search_for("Tarantino")
|
||||
results.size.should == 1
|
||||
expect(results.size).to eq(1)
|
||||
|
||||
results = search_for("coding")
|
||||
results.size.should == 0
|
||||
expect(results.size).to eq(0)
|
||||
|
||||
results = search_for("z")
|
||||
results.size.should == 0
|
||||
expect(results.size).to eq(0)
|
||||
|
||||
# When searching by name is disabled, it will not return the record
|
||||
SiteSetting.enable_names = false
|
||||
results = search_for("Tarantino")
|
||||
results.size.should == 0
|
||||
expect(results.size).to eq(0)
|
||||
|
||||
# find an exact match first
|
||||
results = search_for("mrB")
|
||||
results.first.should == user1
|
||||
expect(results.first).to eq(user1)
|
||||
|
||||
# don't return inactive users
|
||||
results = search_for("Ghost")
|
||||
results.should be_blank
|
||||
expect(results).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ require_dependency 'user'
|
|||
|
||||
describe User do
|
||||
|
||||
it { should validate_presence_of :username }
|
||||
it { should validate_presence_of :email }
|
||||
it { is_expected.to validate_presence_of :username }
|
||||
it { is_expected.to validate_presence_of :email }
|
||||
|
||||
describe '#count_by_signup_date' do
|
||||
before(:each) do
|
||||
|
@ -20,8 +20,8 @@ describe User do
|
|||
let(:signups_by_day) { {1.day.ago.to_date => 2, 2.days.ago.to_date => 1, Time.now.utc.to_date => 1} }
|
||||
|
||||
it 'collect closed interval signups' do
|
||||
User.count_by_signup_date(2.days.ago, Time.now).should include(signups_by_day)
|
||||
User.count_by_signup_date(2.days.ago, Time.now).should_not include({4.days.ago.to_date => 1})
|
||||
expect(User.count_by_signup_date(2.days.ago, Time.now)).to include(signups_by_day)
|
||||
expect(User.count_by_signup_date(2.days.ago, Time.now)).not_to include({4.days.ago.to_date => 1})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -58,15 +58,15 @@ describe User do
|
|||
end
|
||||
|
||||
it 'marks the user as approved' do
|
||||
user.should be_approved
|
||||
expect(user).to be_approved
|
||||
end
|
||||
|
||||
it 'has the admin as the approved by' do
|
||||
user.approved_by.should == admin
|
||||
expect(user.approved_by).to eq(admin)
|
||||
end
|
||||
|
||||
it 'has a value for approved_at' do
|
||||
user.approved_at.should be_present
|
||||
expect(user.approved_at).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -78,9 +78,9 @@ describe User do
|
|||
end
|
||||
|
||||
it "creates a bookmark with the true parameter" do
|
||||
lambda {
|
||||
expect {
|
||||
PostAction.act(@post.user, @post, PostActionType.types[:bookmark])
|
||||
}.should change(PostAction, :count).by(1)
|
||||
}.to change(PostAction, :count).by(1)
|
||||
end
|
||||
|
||||
describe 'when removing a bookmark' do
|
||||
|
@ -90,9 +90,9 @@ describe User do
|
|||
|
||||
it 'reduces the bookmark count of the post' do
|
||||
active = PostAction.where(deleted_at: nil)
|
||||
lambda {
|
||||
expect {
|
||||
PostAction.remove_act(@post.user, @post, PostActionType.types[:bookmark])
|
||||
}.should change(active, :count).by(-1)
|
||||
}.to change(active, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -109,17 +109,17 @@ describe User do
|
|||
end
|
||||
|
||||
it 'returns true' do
|
||||
@result.should == true
|
||||
expect(@result).to eq(true)
|
||||
end
|
||||
|
||||
it 'should change the username' do
|
||||
user.reload
|
||||
user.username.should == new_username
|
||||
expect(user.username).to eq(new_username)
|
||||
end
|
||||
|
||||
it 'should change the username_lower' do
|
||||
user.reload
|
||||
user.username_lower.should == new_username.downcase
|
||||
expect(user.username_lower).to eq(new_username.downcase)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -133,17 +133,17 @@ describe User do
|
|||
end
|
||||
|
||||
it 'returns false' do
|
||||
@result.should == false
|
||||
expect(@result).to eq(false)
|
||||
end
|
||||
|
||||
it 'should not change the username' do
|
||||
user.reload
|
||||
user.username.should == username_before_change
|
||||
expect(user.username).to eq(username_before_change)
|
||||
end
|
||||
|
||||
it 'should not change the username_lower' do
|
||||
user.reload
|
||||
user.username_lower.should == username_lower_before_change
|
||||
expect(user.username_lower).to eq(username_lower_before_change)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -151,12 +151,12 @@ describe User do
|
|||
let!(:myself) { Fabricate(:user, username: 'hansolo') }
|
||||
|
||||
it 'should return true' do
|
||||
myself.change_username('HanSolo').should == true
|
||||
expect(myself.change_username('HanSolo')).to eq(true)
|
||||
end
|
||||
|
||||
it 'should change the username' do
|
||||
myself.change_username('HanSolo')
|
||||
myself.reload.username.should == 'HanSolo'
|
||||
expect(myself.reload.username).to eq('HanSolo')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -168,17 +168,17 @@ describe User do
|
|||
|
||||
it 'should allow a shorter username than default' do
|
||||
result = user.change_username('a' * @custom_min)
|
||||
result.should_not == false
|
||||
expect(result).not_to eq(false)
|
||||
end
|
||||
|
||||
it 'should not allow a shorter username than limit' do
|
||||
result = user.change_username('a' * (@custom_min - 1))
|
||||
result.should == false
|
||||
expect(result).to eq(false)
|
||||
end
|
||||
|
||||
it 'should not allow a longer username than limit' do
|
||||
result = user.change_username('a' * (User.username_length.end + 1))
|
||||
result.should == false
|
||||
expect(result).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -212,8 +212,8 @@ describe User do
|
|||
|
||||
@posts.each do |p|
|
||||
p.reload
|
||||
p.should be_present
|
||||
p.topic.should be_present
|
||||
expect(p).to be_present
|
||||
expect(p.topic).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -222,32 +222,32 @@ describe User do
|
|||
|
||||
subject { Fabricate.build(:user) }
|
||||
|
||||
it { should be_valid }
|
||||
it { should_not be_admin }
|
||||
it { should_not be_approved }
|
||||
it { is_expected.to be_valid }
|
||||
it { is_expected.not_to be_admin }
|
||||
it { is_expected.not_to be_approved }
|
||||
|
||||
it "is properly initialized" do
|
||||
subject.approved_at.should be_blank
|
||||
subject.approved_by_id.should be_blank
|
||||
subject.email_private_messages.should == true
|
||||
subject.email_direct.should == true
|
||||
expect(subject.approved_at).to be_blank
|
||||
expect(subject.approved_by_id).to be_blank
|
||||
expect(subject.email_private_messages).to eq(true)
|
||||
expect(subject.email_direct).to eq(true)
|
||||
end
|
||||
|
||||
context 'digest emails' do
|
||||
it 'defaults to digests every week' do
|
||||
subject.email_digests.should == true
|
||||
subject.digest_after_days.should == 7
|
||||
expect(subject.email_digests).to eq(true)
|
||||
expect(subject.digest_after_days).to eq(7)
|
||||
end
|
||||
|
||||
it 'uses default_digest_email_frequency' do
|
||||
SiteSetting.stubs(:default_digest_email_frequency).returns(1)
|
||||
subject.email_digests.should == true
|
||||
subject.digest_after_days.should == 1
|
||||
expect(subject.email_digests).to eq(true)
|
||||
expect(subject.digest_after_days).to eq(1)
|
||||
end
|
||||
|
||||
it 'disables digests by default if site setting says so' do
|
||||
SiteSetting.stubs(:default_digest_email_frequency).returns('')
|
||||
subject.email_digests.should == false
|
||||
expect(subject.email_digests).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -255,14 +255,14 @@ describe User do
|
|||
before { subject.save }
|
||||
|
||||
it "has an email token" do
|
||||
subject.email_tokens.should be_present
|
||||
expect(subject.email_tokens).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
it "downcases email addresses" do
|
||||
user = Fabricate.build(:user, email: 'Fancy.Caps.4.U@gmail.com')
|
||||
user.save
|
||||
user.reload.email.should == 'fancy.caps.4.u@gmail.com'
|
||||
expect(user.reload.email).to eq('fancy.caps.4.u@gmail.com')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -288,49 +288,49 @@ describe User do
|
|||
|
||||
it "sets to the default trust level setting" do
|
||||
SiteSetting.default_trust_level = TrustLevel[4]
|
||||
User.new.trust_level.should == TrustLevel[4]
|
||||
expect(User.new.trust_level).to eq(TrustLevel[4])
|
||||
end
|
||||
|
||||
describe 'has_trust_level?' do
|
||||
|
||||
it "raises an error with an invalid level" do
|
||||
lambda { user.has_trust_level?(:wat) }.should raise_error
|
||||
expect { user.has_trust_level?(:wat) }.to raise_error
|
||||
end
|
||||
|
||||
it "is true for your basic level" do
|
||||
user.has_trust_level?(TrustLevel[0]).should == true
|
||||
expect(user.has_trust_level?(TrustLevel[0])).to eq(true)
|
||||
end
|
||||
|
||||
it "is false for a higher level" do
|
||||
user.has_trust_level?(TrustLevel[2]).should == false
|
||||
expect(user.has_trust_level?(TrustLevel[2])).to eq(false)
|
||||
end
|
||||
|
||||
it "is true if you exceed the level" do
|
||||
user.trust_level = TrustLevel[4]
|
||||
user.has_trust_level?(TrustLevel[1]).should == true
|
||||
expect(user.has_trust_level?(TrustLevel[1])).to eq(true)
|
||||
end
|
||||
|
||||
it "is true for an admin even with a low trust level" do
|
||||
user.trust_level = TrustLevel[0]
|
||||
user.admin = true
|
||||
user.has_trust_level?(TrustLevel[1]).should == true
|
||||
expect(user.has_trust_level?(TrustLevel[1])).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'moderator' do
|
||||
it "isn't a moderator by default" do
|
||||
user.moderator?.should == false
|
||||
expect(user.moderator?).to eq(false)
|
||||
end
|
||||
|
||||
it "is a moderator if the user level is moderator" do
|
||||
user.moderator = true
|
||||
user.has_trust_level?(TrustLevel[4]).should == true
|
||||
expect(user.has_trust_level?(TrustLevel[4])).to eq(true)
|
||||
end
|
||||
|
||||
it "is staff if the user is an admin" do
|
||||
user.admin = true
|
||||
user.staff?.should == true
|
||||
expect(user.staff?).to eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -344,36 +344,36 @@ describe User do
|
|||
describe '#staff?' do
|
||||
subject { user.staff? }
|
||||
|
||||
it { should == false }
|
||||
it { is_expected.to eq(false) }
|
||||
|
||||
context 'for a moderator user' do
|
||||
before { user.moderator = true }
|
||||
|
||||
it { should == true }
|
||||
it { is_expected.to eq(true) }
|
||||
end
|
||||
|
||||
context 'for an admin user' do
|
||||
before { user.admin = true }
|
||||
|
||||
it { should == true }
|
||||
it { is_expected.to eq(true) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#regular?' do
|
||||
subject { user.regular? }
|
||||
|
||||
it { should == true }
|
||||
it { is_expected.to eq(true) }
|
||||
|
||||
context 'for a moderator user' do
|
||||
before { user.moderator = true }
|
||||
|
||||
it { should == false }
|
||||
it { is_expected.to eq(false) }
|
||||
end
|
||||
|
||||
context 'for an admin user' do
|
||||
before { user.admin = true }
|
||||
|
||||
it { should == false }
|
||||
it { is_expected.to eq(false) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -384,17 +384,17 @@ describe User do
|
|||
let!(:temporary_key) { user.temporary_key}
|
||||
|
||||
it 'has a temporary key' do
|
||||
temporary_key.should be_present
|
||||
expect(temporary_key).to be_present
|
||||
end
|
||||
|
||||
describe 'User#find_by_temporary_key' do
|
||||
|
||||
it 'can be used to find the user' do
|
||||
User.find_by_temporary_key(temporary_key).should == user
|
||||
expect(User.find_by_temporary_key(temporary_key)).to eq(user)
|
||||
end
|
||||
|
||||
it 'returns nil with an invalid key' do
|
||||
User.find_by_temporary_key('asdfasdf').should be_blank
|
||||
expect(User.find_by_temporary_key('asdfasdf')).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -407,7 +407,7 @@ describe User do
|
|||
end
|
||||
|
||||
it 'should have a sane email hash' do
|
||||
@user.email_hash.should =~ /^[0-9a-f]{32}$/
|
||||
expect(@user.email_hash).to match(/^[0-9a-f]{32}$/)
|
||||
end
|
||||
|
||||
it 'should use downcase email' do
|
||||
|
@ -415,7 +415,7 @@ describe User do
|
|||
@user2 = Fabricate(:user)
|
||||
@user2.email = "ExAmPlE@eXaMpLe.com"
|
||||
|
||||
@user.email_hash.should == @user2.email_hash
|
||||
expect(@user.email_hash).to eq(@user2.email_hash)
|
||||
end
|
||||
|
||||
it 'should trim whitespace before hashing' do
|
||||
|
@ -423,14 +423,14 @@ describe User do
|
|||
@user2 = Fabricate(:user)
|
||||
@user2.email = " example@example.com "
|
||||
|
||||
@user.email_hash.should == @user2.email_hash
|
||||
expect(@user.email_hash).to eq(@user2.email_hash)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'associated_accounts' do
|
||||
it 'should correctly find social associations' do
|
||||
user = Fabricate(:user)
|
||||
user.associated_accounts.should == I18n.t("user.no_accounts_associated")
|
||||
expect(user.associated_accounts).to eq(I18n.t("user.no_accounts_associated"))
|
||||
|
||||
TwitterUserInfo.create(user_id: user.id, screen_name: "sam", twitter_user_id: 1)
|
||||
FacebookUserInfo.create(user_id: user.id, username: "sam", facebook_user_id: 1)
|
||||
|
@ -438,14 +438,14 @@ describe User do
|
|||
GithubUserInfo.create(user_id: user.id, screen_name: "sam", github_user_id: 1)
|
||||
|
||||
user.reload
|
||||
user.associated_accounts.should == "Twitter(sam), Facebook(sam), Google(sam@sam.com), Github(sam)"
|
||||
expect(user.associated_accounts).to eq("Twitter(sam), Facebook(sam), Google(sam@sam.com), Github(sam)")
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
describe 'name heuristics' do
|
||||
it 'is able to guess a decent name from an email' do
|
||||
User.suggest_name('sam.saffron@gmail.com').should == 'Sam Saffron'
|
||||
expect(User.suggest_name('sam.saffron@gmail.com')).to eq('Sam Saffron')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -453,26 +453,26 @@ describe User do
|
|||
it "should be #{SiteSetting.min_username_length} chars or longer" do
|
||||
@user = Fabricate.build(:user)
|
||||
@user.username = 'ss'
|
||||
@user.save.should == false
|
||||
expect(@user.save).to eq(false)
|
||||
end
|
||||
|
||||
it "should never end with a ." do
|
||||
@user = Fabricate.build(:user)
|
||||
@user.username = 'sam.'
|
||||
@user.save.should == false
|
||||
expect(@user.save).to eq(false)
|
||||
end
|
||||
|
||||
it "should never contain spaces" do
|
||||
@user = Fabricate.build(:user)
|
||||
@user.username = 'sam s'
|
||||
@user.save.should == false
|
||||
expect(@user.save).to eq(false)
|
||||
end
|
||||
|
||||
['Bad One', 'Giraf%fe', 'Hello!', '@twitter', 'me@example.com', 'no.dots', 'purple.', '.bilbo', '_nope', 'sa$sy'].each do |bad_nickname|
|
||||
it "should not allow username '#{bad_nickname}'" do
|
||||
@user = Fabricate.build(:user)
|
||||
@user.username = bad_nickname
|
||||
@user.save.should == false
|
||||
expect(@user.save).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -486,102 +486,102 @@ describe User do
|
|||
|
||||
it "should not allow saving if username is reused" do
|
||||
@codinghorror.username = @user.username
|
||||
@codinghorror.save.should == false
|
||||
expect(@codinghorror.save).to eq(false)
|
||||
end
|
||||
|
||||
it "should not allow saving if username is reused in different casing" do
|
||||
@codinghorror.username = @user.username.upcase
|
||||
@codinghorror.save.should == false
|
||||
expect(@codinghorror.save).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context '.username_available?' do
|
||||
it "returns true for a username that is available" do
|
||||
User.username_available?('BruceWayne').should == true
|
||||
expect(User.username_available?('BruceWayne')).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns false when a username is taken' do
|
||||
User.username_available?(Fabricate(:user).username).should == false
|
||||
expect(User.username_available?(Fabricate(:user).username)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'email_validator' do
|
||||
it 'should allow good emails' do
|
||||
user = Fabricate.build(:user, email: 'good@gmail.com')
|
||||
user.should be_valid
|
||||
expect(user).to be_valid
|
||||
end
|
||||
|
||||
it 'should reject some emails based on the email_domains_blacklist site setting' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('mailinator.com')
|
||||
Fabricate.build(:user, email: 'notgood@mailinator.com').should_not be_valid
|
||||
Fabricate.build(:user, email: 'mailinator@gmail.com').should be_valid
|
||||
expect(Fabricate.build(:user, email: 'notgood@mailinator.com')).not_to be_valid
|
||||
expect(Fabricate.build(:user, email: 'mailinator@gmail.com')).to be_valid
|
||||
end
|
||||
|
||||
it 'should reject some emails based on the email_domains_blacklist site setting' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('mailinator.com|trashmail.net')
|
||||
Fabricate.build(:user, email: 'notgood@mailinator.com').should_not be_valid
|
||||
Fabricate.build(:user, email: 'notgood@trashmail.net').should_not be_valid
|
||||
Fabricate.build(:user, email: 'mailinator.com@gmail.com').should be_valid
|
||||
expect(Fabricate.build(:user, email: 'notgood@mailinator.com')).not_to be_valid
|
||||
expect(Fabricate.build(:user, email: 'notgood@trashmail.net')).not_to be_valid
|
||||
expect(Fabricate.build(:user, email: 'mailinator.com@gmail.com')).to be_valid
|
||||
end
|
||||
|
||||
it 'should not reject partial matches' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('mail.com')
|
||||
Fabricate.build(:user, email: 'mailinator@gmail.com').should be_valid
|
||||
expect(Fabricate.build(:user, email: 'mailinator@gmail.com')).to be_valid
|
||||
end
|
||||
|
||||
it 'should reject some emails based on the email_domains_blacklist site setting ignoring case' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('trashmail.net')
|
||||
Fabricate.build(:user, email: 'notgood@TRASHMAIL.NET').should_not be_valid
|
||||
expect(Fabricate.build(:user, email: 'notgood@TRASHMAIL.NET')).not_to be_valid
|
||||
end
|
||||
|
||||
it 'should not interpret a period as a wildcard' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('trashmail.net')
|
||||
Fabricate.build(:user, email: 'good@trashmailinet.com').should be_valid
|
||||
expect(Fabricate.build(:user, email: 'good@trashmailinet.com')).to be_valid
|
||||
end
|
||||
|
||||
it 'should not be used to validate existing records' do
|
||||
u = Fabricate(:user, email: 'in_before_blacklisted@fakemail.com')
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('fakemail.com')
|
||||
u.should be_valid
|
||||
expect(u).to be_valid
|
||||
end
|
||||
|
||||
it 'should be used when email is being changed' do
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('mailinator.com')
|
||||
u = Fabricate(:user, email: 'good@gmail.com')
|
||||
u.email = 'nope@mailinator.com'
|
||||
u.should_not be_valid
|
||||
expect(u).not_to be_valid
|
||||
end
|
||||
|
||||
it 'whitelist should reject some emails based on the email_domains_whitelist site setting' do
|
||||
SiteSetting.stubs(:email_domains_whitelist).returns('vaynermedia.com')
|
||||
Fabricate.build(:user, email: 'notgood@mailinator.com').should_not be_valid
|
||||
Fabricate.build(:user, email: 'sbauch@vaynermedia.com').should be_valid
|
||||
expect(Fabricate.build(:user, email: 'notgood@mailinator.com')).not_to be_valid
|
||||
expect(Fabricate.build(:user, email: 'sbauch@vaynermedia.com')).to be_valid
|
||||
end
|
||||
|
||||
it 'should reject some emails based on the email_domains_whitelist site setting when whitelisting multiple domains' do
|
||||
SiteSetting.stubs(:email_domains_whitelist).returns('vaynermedia.com|gmail.com')
|
||||
Fabricate.build(:user, email: 'notgood@mailinator.com').should_not be_valid
|
||||
Fabricate.build(:user, email: 'notgood@trashmail.net').should_not be_valid
|
||||
Fabricate.build(:user, email: 'mailinator.com@gmail.com').should be_valid
|
||||
Fabricate.build(:user, email: 'mailinator.com@vaynermedia.com').should be_valid
|
||||
expect(Fabricate.build(:user, email: 'notgood@mailinator.com')).not_to be_valid
|
||||
expect(Fabricate.build(:user, email: 'notgood@trashmail.net')).not_to be_valid
|
||||
expect(Fabricate.build(:user, email: 'mailinator.com@gmail.com')).to be_valid
|
||||
expect(Fabricate.build(:user, email: 'mailinator.com@vaynermedia.com')).to be_valid
|
||||
end
|
||||
|
||||
it 'should accept some emails based on the email_domains_whitelist site setting ignoring case' do
|
||||
SiteSetting.stubs(:email_domains_whitelist).returns('vaynermedia.com')
|
||||
Fabricate.build(:user, email: 'good@VAYNERMEDIA.COM').should be_valid
|
||||
expect(Fabricate.build(:user, email: 'good@VAYNERMEDIA.COM')).to be_valid
|
||||
end
|
||||
|
||||
it 'email whitelist should not be used to validate existing records' do
|
||||
u = Fabricate(:user, email: 'in_before_whitelisted@fakemail.com')
|
||||
SiteSetting.stubs(:email_domains_blacklist).returns('vaynermedia.com')
|
||||
u.should be_valid
|
||||
expect(u).to be_valid
|
||||
end
|
||||
|
||||
it 'email whitelist should be used when email is being changed' do
|
||||
SiteSetting.stubs(:email_domains_whitelist).returns('vaynermedia.com')
|
||||
u = Fabricate(:user, email: 'good@vaynermedia.com')
|
||||
u.email = 'nope@mailinator.com'
|
||||
u.should_not be_valid
|
||||
expect(u).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -593,11 +593,11 @@ describe User do
|
|||
end
|
||||
|
||||
it "should have a valid password after the initial save" do
|
||||
@user.confirm_password?("ilovepasta").should == true
|
||||
expect(@user.confirm_password?("ilovepasta")).to eq(true)
|
||||
end
|
||||
|
||||
it "should not have an active account after initial save" do
|
||||
@user.active.should == false
|
||||
expect(@user.active).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -614,26 +614,26 @@ describe User do
|
|||
end
|
||||
|
||||
it "should act correctly" do
|
||||
user.previous_visit_at.should == nil
|
||||
expect(user.previous_visit_at).to eq(nil)
|
||||
|
||||
# first visit
|
||||
user.update_last_seen!(first_visit_date)
|
||||
user.previous_visit_at.should == nil
|
||||
expect(user.previous_visit_at).to eq(nil)
|
||||
|
||||
# updated same time
|
||||
user.update_last_seen!(first_visit_date)
|
||||
user.reload
|
||||
user.previous_visit_at.should == nil
|
||||
expect(user.previous_visit_at).to eq(nil)
|
||||
|
||||
# second visit
|
||||
user.update_last_seen!(second_visit_date)
|
||||
user.reload
|
||||
user.previous_visit_at.should be_within_one_second_of(first_visit_date)
|
||||
expect(user.previous_visit_at).to be_within_one_second_of(first_visit_date)
|
||||
|
||||
# third visit
|
||||
user.update_last_seen!(third_visit_date)
|
||||
user.reload
|
||||
user.previous_visit_at.should be_within_one_second_of(second_visit_date)
|
||||
expect(user.previous_visit_at).to be_within_one_second_of(second_visit_date)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -642,11 +642,11 @@ describe User do
|
|||
let(:user) { Fabricate(:user) }
|
||||
|
||||
it "should have a blank last seen on creation" do
|
||||
user.last_seen_at.should == nil
|
||||
expect(user.last_seen_at).to eq(nil)
|
||||
end
|
||||
|
||||
it "should have 0 for days_visited" do
|
||||
user.user_stat.days_visited.should == 0
|
||||
expect(user.user_stat.days_visited).to eq(0)
|
||||
end
|
||||
|
||||
describe 'with no previous values' do
|
||||
|
@ -662,16 +662,16 @@ describe User do
|
|||
end
|
||||
|
||||
it "updates last_seen_at" do
|
||||
user.last_seen_at.should be_within_one_second_of(date)
|
||||
expect(user.last_seen_at).to be_within_one_second_of(date)
|
||||
end
|
||||
|
||||
it "should have 0 for days_visited" do
|
||||
user.reload
|
||||
user.user_stat.days_visited.should == 1
|
||||
expect(user.user_stat.days_visited).to eq(1)
|
||||
end
|
||||
|
||||
it "should log a user_visit with the date" do
|
||||
user.user_visits.first.visited_at.should == date.to_date
|
||||
expect(user.user_visits.first.visited_at).to eq(date.to_date)
|
||||
end
|
||||
|
||||
context "called twice" do
|
||||
|
@ -688,7 +688,7 @@ describe User do
|
|||
end
|
||||
|
||||
it "doesn't increase days_visited twice" do
|
||||
user.user_stat.days_visited.should == 1
|
||||
expect(user.user_stat.days_visited).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -706,7 +706,7 @@ describe User do
|
|||
end
|
||||
|
||||
it "should log a second visited_at record when we log an update later" do
|
||||
user.user_visits.count.should == 2
|
||||
expect(user.user_visits.count).to eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -718,7 +718,7 @@ describe User do
|
|||
|
||||
context 'when email has not been confirmed yet' do
|
||||
it 'should return false' do
|
||||
user.email_confirmed?.should == false
|
||||
expect(user.email_confirmed?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -726,7 +726,7 @@ describe User do
|
|||
it 'should return true' do
|
||||
token = user.email_tokens.find_by(email: user.email)
|
||||
EmailToken.confirm(token.token)
|
||||
user.email_confirmed?.should == true
|
||||
expect(user.email_confirmed?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -734,7 +734,7 @@ describe User do
|
|||
it 'should return false' do
|
||||
user.email_tokens.each {|t| t.destroy}
|
||||
user.reload
|
||||
user.email_confirmed?.should == true
|
||||
expect(user.email_confirmed?).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -750,13 +750,13 @@ describe User do
|
|||
user.flag_linked_posts_as_spam
|
||||
|
||||
post.reload
|
||||
post.spam_count.should == 1
|
||||
expect(post.spam_count).to eq(1)
|
||||
|
||||
another_post.reload
|
||||
another_post.spam_count.should == 1
|
||||
expect(another_post.spam_count).to eq(1)
|
||||
|
||||
post_without_link.reload
|
||||
post_without_link.spam_count.should == 0
|
||||
expect(post_without_link.spam_count).to eq(0)
|
||||
|
||||
# It doesn't raise an exception if called again
|
||||
user.flag_linked_posts_as_spam
|
||||
|
@ -768,17 +768,17 @@ describe User do
|
|||
describe '#readable_name' do
|
||||
context 'when name is missing' do
|
||||
it 'returns just the username' do
|
||||
Fabricate(:user, username: 'foo', name: nil).readable_name.should == 'foo'
|
||||
expect(Fabricate(:user, username: 'foo', name: nil).readable_name).to eq('foo')
|
||||
end
|
||||
end
|
||||
context 'when name and username are identical' do
|
||||
it 'returns just the username' do
|
||||
Fabricate(:user, username: 'foo', name: 'foo').readable_name.should == 'foo'
|
||||
expect(Fabricate(:user, username: 'foo', name: 'foo').readable_name).to eq('foo')
|
||||
end
|
||||
end
|
||||
context 'when name and username are not identical' do
|
||||
it 'returns the name and username' do
|
||||
Fabricate(:user, username: 'foo', name: 'Bar Baz').readable_name.should == 'Bar Baz (foo)'
|
||||
expect(Fabricate(:user, username: 'foo', name: 'Bar Baz').readable_name).to eq('Bar Baz (foo)')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -895,11 +895,11 @@ describe User do
|
|||
|
||||
it "does not return true for staff" do
|
||||
user.stubs(:staff?).returns(true)
|
||||
user.posted_too_much_in_topic?(topic.id).should == false
|
||||
expect(user.posted_too_much_in_topic?(topic.id)).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true when the user has posted too much" do
|
||||
user.posted_too_much_in_topic?(topic.id).should == true
|
||||
expect(user.posted_too_much_in_topic?(topic.id)).to eq(true)
|
||||
end
|
||||
|
||||
context "with a reply" do
|
||||
|
@ -908,7 +908,7 @@ describe User do
|
|||
end
|
||||
|
||||
it "resets the `posted_too_much` threshold" do
|
||||
user.posted_too_much_in_topic?(topic.id).should == false
|
||||
expect(user.posted_too_much_in_topic?(topic.id)).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -916,7 +916,7 @@ describe User do
|
|||
it "returns false for a user who created the topic" do
|
||||
topic_user = topic.user
|
||||
topic_user.trust_level = TrustLevel[0]
|
||||
topic.user.posted_too_much_in_topic?(topic.id).should == false
|
||||
expect(topic.user.posted_too_much_in_topic?(topic.id)).to eq(false)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -945,7 +945,7 @@ describe User do
|
|||
describe "#gravatar_template" do
|
||||
|
||||
it "returns a gravatar based template" do
|
||||
User.gravatar_template("em@il.com").should == "//www.gravatar.com/avatar/6dc2fde946483a1d8a84b89345a1b638.png?s={size}&r=pg&d=identicon"
|
||||
expect(User.gravatar_template("em@il.com")).to eq("//www.gravatar.com/avatar/6dc2fde946483a1d8a84b89345a1b638.png?s={size}&r=pg&d=identicon")
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -955,7 +955,7 @@ describe User do
|
|||
let(:user) { build(:user, username: 'Sam') }
|
||||
|
||||
it "returns a 45-pixel-wide avatar" do
|
||||
user.small_avatar_url.should == "//test.localhost/letter_avatar/sam/45/#{LetterAvatar::VERSION}.png"
|
||||
expect(user.small_avatar_url).to eq("//test.localhost/letter_avatar/sam/45/#{LetterAvatar::VERSION}.png")
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -965,12 +965,12 @@ describe User do
|
|||
let(:user) { build(:user, uploaded_avatar_id: 99, username: 'Sam') }
|
||||
|
||||
it "returns a schemaless avatar template with correct id" do
|
||||
user.avatar_template_url.should == "//test.localhost/user_avatar/test.localhost/sam/{size}/99.png"
|
||||
expect(user.avatar_template_url).to eq("//test.localhost/user_avatar/test.localhost/sam/{size}/99.png")
|
||||
end
|
||||
|
||||
it "returns a schemaless cdn-based avatar template" do
|
||||
Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com")
|
||||
user.avatar_template_url.should == "//my.cdn.com/user_avatar/test.localhost/sam/{size}/99.png"
|
||||
expect(user.avatar_template_url).to eq("//my.cdn.com/user_avatar/test.localhost/sam/{size}/99.png")
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -984,14 +984,14 @@ describe User do
|
|||
it "with existing UserVisit record, increments the posts_read value" do
|
||||
expect {
|
||||
user_visit = user.update_posts_read!(2)
|
||||
user_visit.posts_read.should == 2
|
||||
expect(user_visit.posts_read).to eq(2)
|
||||
}.to_not change { UserVisit.count }
|
||||
end
|
||||
|
||||
it "with no existing UserVisit record, creates a new UserVisit record and increments the posts_read count" do
|
||||
expect {
|
||||
user_visit = user.update_posts_read!(3, 5.days.ago)
|
||||
user_visit.posts_read.should == 3
|
||||
expect(user_visit.posts_read).to eq(3)
|
||||
}.to change { UserVisit.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
@ -1001,7 +1001,7 @@ describe User do
|
|||
let!(:user) { Fabricate(:user) }
|
||||
|
||||
it "has no primary_group_id by default" do
|
||||
user.primary_group_id.should == nil
|
||||
expect(user.primary_group_id).to eq(nil)
|
||||
end
|
||||
|
||||
context "when the user has a group" do
|
||||
|
@ -1016,7 +1016,7 @@ describe User do
|
|||
end
|
||||
|
||||
it "should allow us to use it as a primary group" do
|
||||
user.primary_group_id.should == group.id
|
||||
expect(user.primary_group_id).to eq(group.id)
|
||||
|
||||
# If we remove the user from the group
|
||||
group.usernames = ""
|
||||
|
@ -1024,7 +1024,7 @@ describe User do
|
|||
|
||||
# It should unset it from the primary_group_id
|
||||
user.reload
|
||||
user.primary_group_id.should == nil
|
||||
expect(user.primary_group_id).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1034,12 +1034,12 @@ describe User do
|
|||
|
||||
it "should be redirected to top when there is a reason to" do
|
||||
user.expects(:redirected_to_top_reason).returns("42")
|
||||
user.should_be_redirected_to_top.should == true
|
||||
expect(user.should_be_redirected_to_top).to eq(true)
|
||||
end
|
||||
|
||||
it "should not be redirected to top when there is no reason to" do
|
||||
user.expects(:redirected_to_top_reason).returns(nil)
|
||||
user.should_be_redirected_to_top.should == false
|
||||
expect(user.should_be_redirected_to_top).to eq(false)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1049,7 +1049,7 @@ describe User do
|
|||
|
||||
it "should have no reason when `SiteSetting.redirect_users_to_top_page` is disabled" do
|
||||
SiteSetting.expects(:redirect_users_to_top_page).returns(false)
|
||||
user.redirected_to_top_reason.should == nil
|
||||
expect(user.redirected_to_top_reason).to eq(nil)
|
||||
end
|
||||
|
||||
context "when `SiteSetting.redirect_users_to_top_page` is enabled" do
|
||||
|
@ -1057,7 +1057,7 @@ describe User do
|
|||
|
||||
it "should have no reason when top is not in the `SiteSetting.top_menu`" do
|
||||
SiteSetting.expects(:top_menu).returns("latest")
|
||||
user.redirected_to_top_reason.should == nil
|
||||
expect(user.redirected_to_top_reason).to eq(nil)
|
||||
end
|
||||
|
||||
context "and when top is in the `SiteSetting.top_menu`" do
|
||||
|
@ -1065,7 +1065,7 @@ describe User do
|
|||
|
||||
it "should have no reason when there aren't enough topics" do
|
||||
SiteSetting.expects(:has_enough_topics_to_redirect_to_top).returns(false)
|
||||
user.redirected_to_top_reason.should == nil
|
||||
expect(user.redirected_to_top_reason).to eq(nil)
|
||||
end
|
||||
|
||||
context "and when there are enough topics" do
|
||||
|
@ -1081,14 +1081,14 @@ describe User do
|
|||
user.expects(:last_redirected_to_top_at).returns(nil)
|
||||
user.expects(:update_last_redirected_to_top!).once
|
||||
|
||||
user.redirected_to_top_reason.should == I18n.t('redirected_to_top_reasons.new_user')
|
||||
expect(user.redirected_to_top_reason).to eq(I18n.t('redirected_to_top_reasons.new_user'))
|
||||
end
|
||||
|
||||
it "should not have a reason for next visits" do
|
||||
user.expects(:last_redirected_to_top_at).returns(10.minutes.ago)
|
||||
user.expects(:update_last_redirected_to_top!).never
|
||||
|
||||
user.redirected_to_top_reason.should == nil
|
||||
expect(user.redirected_to_top_reason).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1099,7 +1099,7 @@ describe User do
|
|||
user.last_seen_at = 2.months.ago
|
||||
user.expects(:update_last_redirected_to_top!).once
|
||||
|
||||
user.redirected_to_top_reason.should == I18n.t('redirected_to_top_reasons.not_seen_in_a_month')
|
||||
expect(user.redirected_to_top_reason).to eq(I18n.t('redirected_to_top_reasons.not_seen_in_a_month'))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1115,8 +1115,8 @@ describe User do
|
|||
it "sets a system avatar for new users" do
|
||||
u = User.create!(username: "bob", email: "bob@bob.com")
|
||||
u.reload
|
||||
u.uploaded_avatar_id.should == nil
|
||||
u.avatar_template.should == "/letter_avatar/bob/{size}/#{LetterAvatar::VERSION}.png"
|
||||
expect(u.uploaded_avatar_id).to eq(nil)
|
||||
expect(u.avatar_template).to eq("/letter_avatar/bob/{size}/#{LetterAvatar::VERSION}.png")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1124,7 +1124,7 @@ describe User do
|
|||
it "allows modification of custom fields" do
|
||||
user = Fabricate(:user)
|
||||
|
||||
user.custom_fields["a"].should == nil
|
||||
expect(user.custom_fields["a"]).to eq(nil)
|
||||
|
||||
user.custom_fields["bob"] = "marley"
|
||||
user.custom_fields["jack"] = "black"
|
||||
|
@ -1132,8 +1132,8 @@ describe User do
|
|||
|
||||
user = User.find(user.id)
|
||||
|
||||
user.custom_fields["bob"].should == "marley"
|
||||
user.custom_fields["jack"].should == "black"
|
||||
expect(user.custom_fields["bob"]).to eq("marley")
|
||||
expect(user.custom_fields["jack"]).to eq("black")
|
||||
|
||||
user.custom_fields.delete("bob")
|
||||
user.custom_fields["jack"] = "jill"
|
||||
|
@ -1141,7 +1141,7 @@ describe User do
|
|||
user.save
|
||||
user = User.find(user.id)
|
||||
|
||||
user.custom_fields.should == {"jack" => "jill"}
|
||||
expect(user.custom_fields).to eq({"jack" => "jill"})
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1165,9 +1165,9 @@ describe User do
|
|||
it 'should only remove old, unactivated users' do
|
||||
User.purge_unactivated
|
||||
all_users = User.all
|
||||
all_users.include?(user).should == true
|
||||
all_users.include?(inactive).should == true
|
||||
all_users.include?(inactive_old).should == false
|
||||
expect(all_users.include?(user)).to eq(true)
|
||||
expect(all_users.include?(inactive)).to eq(true)
|
||||
expect(all_users.include?(inactive_old)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1180,19 +1180,19 @@ describe User do
|
|||
end
|
||||
|
||||
it "returns the same hash for the same password and salt" do
|
||||
hash('poutine', 'gravy').should == hash('poutine', 'gravy')
|
||||
expect(hash('poutine', 'gravy')).to eq(hash('poutine', 'gravy'))
|
||||
end
|
||||
|
||||
it "returns a different hash for the same salt and different password" do
|
||||
hash('poutine', 'gravy').should_not == hash('fries', 'gravy')
|
||||
expect(hash('poutine', 'gravy')).not_to eq(hash('fries', 'gravy'))
|
||||
end
|
||||
|
||||
it "returns a different hash for the same password and different salt" do
|
||||
hash('poutine', 'gravy').should_not == hash('poutine', 'cheese')
|
||||
expect(hash('poutine', 'gravy')).not_to eq(hash('poutine', 'cheese'))
|
||||
end
|
||||
|
||||
it "raises an error when passwords are too long" do
|
||||
-> { hash(too_long, 'gravy') }.should raise_error
|
||||
expect { hash(too_long, 'gravy') }.to raise_error
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,14 +2,14 @@ require 'spec_helper'
|
|||
|
||||
describe UserStat do
|
||||
|
||||
it { should belong_to :user }
|
||||
it { is_expected.to belong_to :user }
|
||||
|
||||
it "is created automatically when a user is created" do
|
||||
user = Fabricate(:evil_trout)
|
||||
user.user_stat.should be_present
|
||||
expect(user.user_stat).to be_present
|
||||
|
||||
# It populates the `new_since` field by default
|
||||
user.user_stat.new_since.should be_present
|
||||
expect(user.user_stat.new_since).to be_present
|
||||
end
|
||||
|
||||
context '#update_view_counts' do
|
||||
|
@ -20,7 +20,7 @@ describe UserStat do
|
|||
context 'topics_entered' do
|
||||
context 'without any views' do
|
||||
it "doesn't increase the user's topics_entered" do
|
||||
lambda { UserStat.update_view_counts; stat.reload }.should_not change(stat, :topics_entered)
|
||||
expect { UserStat.update_view_counts; stat.reload }.not_to change(stat, :topics_entered)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -35,14 +35,14 @@ describe UserStat do
|
|||
it "adds one to the topics entered" do
|
||||
UserStat.update_view_counts
|
||||
stat.reload
|
||||
stat.topics_entered.should == 1
|
||||
expect(stat.topics_entered).to eq(1)
|
||||
end
|
||||
|
||||
it "won't record a second view as a different topic" do
|
||||
TopicViewItem.add(topic.id, '127.0.0.1', user.id)
|
||||
UserStat.update_view_counts
|
||||
stat.reload
|
||||
stat.topics_entered.should == 1
|
||||
expect(stat.topics_entered).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -51,7 +51,7 @@ describe UserStat do
|
|||
context 'posts_read_count' do
|
||||
context 'without any post timings' do
|
||||
it "doesn't increase the user's posts_read_count" do
|
||||
lambda { UserStat.update_view_counts; stat.reload }.should_not change(stat, :posts_read_count)
|
||||
expect { UserStat.update_view_counts; stat.reload }.not_to change(stat, :posts_read_count)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,7 @@ describe UserStat do
|
|||
it "increases posts_read_count" do
|
||||
UserStat.update_view_counts
|
||||
stat.reload
|
||||
stat.posts_read_count.should == 1
|
||||
expect(stat.posts_read_count).to eq(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -83,14 +83,14 @@ describe UserStat do
|
|||
stat.expects(:last_seen_cached).returns(nil)
|
||||
stat.update_time_read!
|
||||
stat.reload
|
||||
stat.time_read.should == 0
|
||||
expect(stat.time_read).to eq(0)
|
||||
end
|
||||
|
||||
it 'makes a change if time read is below threshold' do
|
||||
stat.expects(:last_seen_cached).returns(Time.now - 10)
|
||||
stat.update_time_read!
|
||||
stat.reload
|
||||
stat.time_read.should == 10
|
||||
expect(stat.time_read).to eq(10)
|
||||
end
|
||||
|
||||
it 'makes no change if time read is above threshold' do
|
||||
|
@ -98,7 +98,7 @@ describe UserStat do
|
|||
stat.expects(:last_seen_cached).returns(t)
|
||||
stat.update_time_read!
|
||||
stat.reload
|
||||
stat.time_read.should == 0
|
||||
expect(stat.time_read).to eq(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -11,14 +11,14 @@ describe UserVisit do
|
|||
user.update_visit_record!(1.day.ago.to_date)
|
||||
|
||||
user.reload
|
||||
user.user_stat.days_visited.should == 2
|
||||
expect(user.user_stat.days_visited).to eq(2)
|
||||
|
||||
user.user_stat.days_visited = 1
|
||||
user.save
|
||||
UserVisit.ensure_consistency!
|
||||
|
||||
user.reload
|
||||
user.user_stat.days_visited.should == 2
|
||||
expect(user.user_stat.days_visited).to eq(2)
|
||||
end
|
||||
|
||||
describe '#by_day' do
|
||||
|
@ -34,8 +34,8 @@ describe UserVisit do
|
|||
let(:visits_by_day) { {1.day.ago.to_date => 2, 2.days.ago.to_date => 1, Time.now.to_date => 1 } }
|
||||
|
||||
it 'collect closed interval visits' do
|
||||
UserVisit.by_day(2.days.ago, Time.now).should include(visits_by_day)
|
||||
UserVisit.by_day(2.days.ago, Time.now).should_not include({4.days.ago.to_date => 1})
|
||||
expect(UserVisit.by_day(2.days.ago, Time.now)).to include(visits_by_day)
|
||||
expect(UserVisit.by_day(2.days.ago, Time.now)).not_to include({4.days.ago.to_date => 1})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,12 +12,12 @@ describe BasicPostSerializer do
|
|||
|
||||
it "returns the name it when `enable_names` is true" do
|
||||
SiteSetting.stubs(:enable_names?).returns(true)
|
||||
json[:name].should be_present
|
||||
expect(json[:name]).to be_present
|
||||
end
|
||||
|
||||
it "doesn't return the name it when `enable_names` is false" do
|
||||
SiteSetting.stubs(:enable_names?).returns(false)
|
||||
json[:name].should be_blank
|
||||
expect(json[:name]).to be_blank
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -30,16 +30,16 @@ describe PostSerializer do
|
|||
end
|
||||
|
||||
it "displays the correct info" do
|
||||
visible_actions_for(actor).sort.should == [:like,:notify_user,:spam,:vote]
|
||||
visible_actions_for(post.user).sort.should == [:like,:vote]
|
||||
visible_actions_for(nil).sort.should == [:like,:vote]
|
||||
visible_actions_for(admin).sort.should == [:like,:notify_user,:spam,:vote]
|
||||
expect(visible_actions_for(actor).sort).to eq([:like,:notify_user,:spam,:vote])
|
||||
expect(visible_actions_for(post.user).sort).to eq([:like,:vote])
|
||||
expect(visible_actions_for(nil).sort).to eq([:like,:vote])
|
||||
expect(visible_actions_for(admin).sort).to eq([:like,:notify_user,:spam,:vote])
|
||||
end
|
||||
|
||||
it "can't flag your own post to notify yourself" do
|
||||
serializer = PostSerializer.new(post, scope: Guardian.new(post.user), root: false)
|
||||
notify_user_action = serializer.actions_summary.find { |a| a[:id] == PostActionType.types[:notify_user] }
|
||||
notify_user_action[:can_act].should == false
|
||||
expect(notify_user_action[:can_act]).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -55,10 +55,10 @@ describe PostSerializer do
|
|||
|
||||
it "serializes correctly" do
|
||||
[:name, :username, :display_username, :avatar_template, :user_title, :trust_level].each do |attr|
|
||||
subject[attr].should be_nil
|
||||
expect(subject[attr]).to be_nil
|
||||
end
|
||||
[:moderator, :staff, :yours].each do |attr|
|
||||
subject[attr].should == false
|
||||
expect(subject[attr]).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -71,12 +71,12 @@ describe PostSerializer do
|
|||
|
||||
it "returns the display_username it when `enable_names` is on" do
|
||||
SiteSetting.stubs(:enable_names).returns(true)
|
||||
json[:display_username].should be_present
|
||||
expect(json[:display_username]).to be_present
|
||||
end
|
||||
|
||||
it "doesn't return the display_username it when `enable_names` is off" do
|
||||
SiteSetting.stubs(:enable_names).returns(false)
|
||||
json[:display_username].should be_blank
|
||||
expect(json[:display_username]).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -95,7 +95,7 @@ describe PostSerializer do
|
|||
|
||||
it "includes the raw post for everyone" do
|
||||
[nil, user, Fabricate(:user), Fabricate(:moderator), Fabricate(:admin)].each do |user|
|
||||
serialized_post_for_user(user)[:raw].should == raw
|
||||
expect(serialized_post_for_user(user)[:raw]).to eq(raw)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -104,21 +104,21 @@ describe PostSerializer do
|
|||
let(:post) { Fabricate.build(:post, raw: raw, user: user, hidden: true, hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached]) }
|
||||
|
||||
it "shows the raw post only if authorized to see it" do
|
||||
serialized_post_for_user(nil)[:raw].should == nil
|
||||
serialized_post_for_user(Fabricate(:user))[:raw].should == nil
|
||||
expect(serialized_post_for_user(nil)[:raw]).to eq(nil)
|
||||
expect(serialized_post_for_user(Fabricate(:user))[:raw]).to eq(nil)
|
||||
|
||||
serialized_post_for_user(user)[:raw].should == raw
|
||||
serialized_post_for_user(Fabricate(:moderator))[:raw].should == raw
|
||||
serialized_post_for_user(Fabricate(:admin))[:raw].should == raw
|
||||
expect(serialized_post_for_user(user)[:raw]).to eq(raw)
|
||||
expect(serialized_post_for_user(Fabricate(:moderator))[:raw]).to eq(raw)
|
||||
expect(serialized_post_for_user(Fabricate(:admin))[:raw]).to eq(raw)
|
||||
end
|
||||
|
||||
it "can view edit history only if authorized" do
|
||||
serialized_post_for_user(nil)[:can_view_edit_history].should == false
|
||||
serialized_post_for_user(Fabricate(:user))[:can_view_edit_history].should == false
|
||||
expect(serialized_post_for_user(nil)[:can_view_edit_history]).to eq(false)
|
||||
expect(serialized_post_for_user(Fabricate(:user))[:can_view_edit_history]).to eq(false)
|
||||
|
||||
serialized_post_for_user(user)[:can_view_edit_history].should == true
|
||||
serialized_post_for_user(Fabricate(:moderator))[:can_view_edit_history].should == true
|
||||
serialized_post_for_user(Fabricate(:admin))[:can_view_edit_history].should == true
|
||||
expect(serialized_post_for_user(user)[:can_view_edit_history]).to eq(true)
|
||||
expect(serialized_post_for_user(Fabricate(:moderator))[:can_view_edit_history]).to eq(true)
|
||||
expect(serialized_post_for_user(Fabricate(:admin))[:can_view_edit_history]).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -127,7 +127,7 @@ describe PostSerializer do
|
|||
|
||||
it "can view edit history" do
|
||||
[nil, user, Fabricate(:user), Fabricate(:moderator), Fabricate(:admin)].each do |user|
|
||||
serialized_post_for_user(user)[:can_view_edit_history].should == true
|
||||
expect(serialized_post_for_user(user)[:can_view_edit_history]).to eq(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -136,12 +136,12 @@ describe PostSerializer do
|
|||
let(:post) { Fabricate.build(:post, raw: raw, user: user, wiki: true, hidden: true, hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached]) }
|
||||
|
||||
it "can view edit history only if authorized" do
|
||||
serialized_post_for_user(nil)[:can_view_edit_history].should == false
|
||||
serialized_post_for_user(Fabricate(:user))[:can_view_edit_history].should == false
|
||||
expect(serialized_post_for_user(nil)[:can_view_edit_history]).to eq(false)
|
||||
expect(serialized_post_for_user(Fabricate(:user))[:can_view_edit_history]).to eq(false)
|
||||
|
||||
serialized_post_for_user(user)[:can_view_edit_history].should == true
|
||||
serialized_post_for_user(Fabricate(:moderator))[:can_view_edit_history].should == true
|
||||
serialized_post_for_user(Fabricate(:admin))[:can_view_edit_history].should == true
|
||||
expect(serialized_post_for_user(user)[:can_view_edit_history]).to eq(true)
|
||||
expect(serialized_post_for_user(Fabricate(:moderator))[:can_view_edit_history]).to eq(true)
|
||||
expect(serialized_post_for_user(Fabricate(:admin))[:can_view_edit_history]).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ describe TopicListItemSerializer do
|
|||
topic.posters = []
|
||||
serialized = TopicListItemSerializer.new(topic, scope: Guardian.new, root: false).as_json
|
||||
|
||||
serialized[:title].should == "test"
|
||||
serialized[:bumped].should == true
|
||||
expect(serialized[:title]).to eq("test")
|
||||
expect(serialized[:bumped]).to eq(true)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ describe UserSerializer do
|
|||
let(:untrusted_attributes) { %i{bio_raw bio_cooked bio_excerpt location website profile_background card_background} }
|
||||
|
||||
it "doesn't serialize untrusted attributes" do
|
||||
untrusted_attributes.each { |attr| json.should_not have_key(attr) }
|
||||
untrusted_attributes.each { |attr| expect(json).not_to have_key(attr) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,7 @@ describe UserSerializer do
|
|||
let(:json) { serializer.as_json }
|
||||
|
||||
it "produces json" do
|
||||
json.should be_present
|
||||
expect(json).to be_present
|
||||
end
|
||||
|
||||
context "with `enable_names` true" do
|
||||
|
@ -30,7 +30,7 @@ describe UserSerializer do
|
|||
end
|
||||
|
||||
it "has a name" do
|
||||
json[:name].should be_present
|
||||
expect(json[:name]).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,7 +40,7 @@ describe UserSerializer do
|
|||
end
|
||||
|
||||
it "has a name" do
|
||||
json[:name].should be_blank
|
||||
expect(json[:name]).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -102,13 +102,13 @@ describe UserSerializer do
|
|||
|
||||
it "doesn't serialize the fields by default" do
|
||||
json[:custom_fields]
|
||||
json[:custom_fields].should be_empty
|
||||
expect(json[:custom_fields]).to be_empty
|
||||
end
|
||||
|
||||
it "serializes the fields listed in public_user_custom_fields site setting" do
|
||||
SiteSetting.stubs(:public_user_custom_fields).returns('public_field')
|
||||
json[:custom_fields]['public_field'].should == user.custom_fields['public_field']
|
||||
json[:custom_fields]['secret_field'].should == nil
|
||||
expect(json[:custom_fields]['public_field']).to eq(user.custom_fields['public_field'])
|
||||
expect(json[:custom_fields]['secret_field']).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,9 +17,9 @@ describe "users/omniauth_callbacks/complete.html.erb" do
|
|||
|
||||
render
|
||||
|
||||
rendered_data["authenticated"].should eq(false)
|
||||
rendered_data["awaiting_activation"].should eq(false)
|
||||
rendered_data["awaiting_approval"].should eq(false)
|
||||
expect(rendered_data["authenticated"]).to eq(false)
|
||||
expect(rendered_data["awaiting_activation"]).to eq(false)
|
||||
expect(rendered_data["awaiting_approval"]).to eq(false)
|
||||
end
|
||||
|
||||
it "renders cas data " do
|
||||
|
@ -32,10 +32,10 @@ describe "users/omniauth_callbacks/complete.html.erb" do
|
|||
|
||||
render
|
||||
|
||||
rendered_data["email"].should eq(result.email)
|
||||
expect(rendered_data["email"]).to eq(result.email)
|
||||
# TODO this is a bit weird, the upcasing is confusing,
|
||||
# clean it up throughout
|
||||
rendered_data["auth_provider"].should eq("Cas")
|
||||
expect(rendered_data["auth_provider"]).to eq("Cas")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ describe "users/omniauth_callbacks/failure.html.erb" do
|
|||
flash[:error] = I18n.t("login.omniauth_error", strategy: 'test')
|
||||
render
|
||||
|
||||
rendered.match(I18n.t("login.omniauth_error", strategy: 'test')).should_not == nil
|
||||
expect(rendered.match(I18n.t("login.omniauth_error", strategy: 'test'))).not_to eq(nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue