mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 11:11:13 +08:00
introduce Enum
This commit is contained in:
@ -161,8 +161,8 @@ describe Invite do
|
||||
context 'invite trust levels' do
|
||||
|
||||
it "returns the trust level in default_invitee_trust_level" do
|
||||
SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel.Levels[:experienced])
|
||||
invite.redeem.trust_level.should == TrustLevel.Levels[:experienced]
|
||||
SiteSetting.stubs(:default_invitee_trust_level).returns(TrustLevel.levels[:experienced])
|
||||
invite.redeem.trust_level.should == TrustLevel.levels[:experienced]
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -77,7 +77,7 @@ describe Notification do
|
||||
end
|
||||
|
||||
it 'should create a private message notification' do
|
||||
@target.notifications.first.notification_type.should == Notification.Types[:private_message]
|
||||
@target.notifications.first.notification_type.should == Notification.types[:private_message]
|
||||
end
|
||||
|
||||
it 'should not add a pm notification for the creator' do
|
||||
|
@ -9,7 +9,7 @@ describe PostAction do
|
||||
|
||||
let(:codinghorror) { Fabricate(:coding_horror) }
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:bookmark) { PostAction.new(user_id: post.user_id, post_action_type_id: PostActionType.Types[:bookmark] , post_id: post.id) }
|
||||
let(:bookmark) { PostAction.new(user_id: post.user_id, post_action_type_id: PostActionType.types[:bookmark] , post_id: post.id) }
|
||||
|
||||
describe "flag counts" do
|
||||
before do
|
||||
@ -20,7 +20,7 @@ describe PostAction do
|
||||
end
|
||||
|
||||
it "increments the numbers correctly" do
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:off_topic])
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:off_topic])
|
||||
PostAction.flagged_posts_count.should == 1
|
||||
|
||||
PostAction.clear_flags!(post, -1)
|
||||
@ -28,14 +28,14 @@ describe PostAction do
|
||||
end
|
||||
|
||||
it "should reset counts when a topic is deleted" do
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:off_topic])
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:off_topic])
|
||||
post.topic.destroy
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
end
|
||||
|
||||
it "should reset counts when a post is deleted" do
|
||||
post2 = Fabricate(:post, topic_id: post.topic_id)
|
||||
PostAction.act(codinghorror, post2, PostActionType.Types[:off_topic])
|
||||
PostAction.act(codinghorror, post2, PostActionType.types[:off_topic])
|
||||
post2.destroy
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
end
|
||||
@ -54,14 +54,14 @@ describe PostAction do
|
||||
describe 'when a user likes something' do
|
||||
it 'should increase the post counts when a user likes' do
|
||||
lambda {
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:like])
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||
post.reload
|
||||
}.should change(post, :like_count).by(1)
|
||||
end
|
||||
|
||||
it 'should increase the forum topic like count when a user likes' do
|
||||
lambda {
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:like])
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:like])
|
||||
post.topic.reload
|
||||
}.should change(post.topic, :like_count).by(1)
|
||||
end
|
||||
@ -72,14 +72,14 @@ describe PostAction do
|
||||
describe 'when a user votes for something' do
|
||||
it 'should increase the vote counts when a user likes' do
|
||||
lambda {
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:vote])
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:vote])
|
||||
post.reload
|
||||
}.should change(post, :vote_count).by(1)
|
||||
end
|
||||
|
||||
it 'should increase the forum topic vote count when a user votes' do
|
||||
lambda {
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:vote])
|
||||
PostAction.act(codinghorror, post, PostActionType.types[:vote])
|
||||
post.topic.reload
|
||||
}.should change(post.topic, :vote_count).by(1)
|
||||
end
|
||||
@ -114,14 +114,14 @@ describe PostAction do
|
||||
it 'does not allow you to flag stuff with 2 reasons' do
|
||||
post = Fabricate(:post)
|
||||
u1 = Fabricate(:evil_trout)
|
||||
PostAction.act(u1, post, PostActionType.Types[:spam])
|
||||
lambda { PostAction.act(u1, post, PostActionType.Types[:off_topic]) }.should raise_error(PostAction::AlreadyFlagged)
|
||||
PostAction.act(u1, post, PostActionType.types[:spam])
|
||||
lambda { PostAction.act(u1, post, PostActionType.types[:off_topic]) }.should raise_error(PostAction::AlreadyFlagged)
|
||||
end
|
||||
|
||||
it 'should update counts when you clear flags' do
|
||||
post = Fabricate(:post)
|
||||
u1 = Fabricate(:evil_trout)
|
||||
PostAction.act(u1, post, PostActionType.Types[:spam])
|
||||
PostAction.act(u1, post, PostActionType.types[:spam])
|
||||
|
||||
post.reload
|
||||
post.spam_count.should == 1
|
||||
@ -143,8 +143,8 @@ describe PostAction do
|
||||
|
||||
SiteSetting.flags_required_to_hide_post = 2
|
||||
|
||||
PostAction.act(u1, post, PostActionType.Types[:spam])
|
||||
PostAction.act(u2, post, PostActionType.Types[:spam])
|
||||
PostAction.act(u1, post, PostActionType.types[:spam])
|
||||
PostAction.act(u2, post, PostActionType.types[:spam])
|
||||
|
||||
post.reload
|
||||
|
||||
@ -159,8 +159,8 @@ describe PostAction do
|
||||
post.hidden_reason_id.should be_nil
|
||||
post.topic.visible.should be_true
|
||||
|
||||
PostAction.act(u1, post, PostActionType.Types[:spam])
|
||||
PostAction.act(u2, post, PostActionType.Types[:off_topic])
|
||||
PostAction.act(u1, post, PostActionType.types[:spam])
|
||||
PostAction.act(u2, post, PostActionType.types[:off_topic])
|
||||
|
||||
post.reload
|
||||
|
||||
|
@ -9,19 +9,19 @@ describe PostAlertObserver do
|
||||
context 'when liking a post' do
|
||||
it 'creates a notification' do
|
||||
lambda {
|
||||
PostAction.act(evil_trout, post, PostActionType.Types[:like])
|
||||
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
||||
}.should change(Notification, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when removing a liked post' do
|
||||
before do
|
||||
PostAction.act(evil_trout, post, PostActionType.Types[:like])
|
||||
PostAction.act(evil_trout, post, PostActionType.types[:like])
|
||||
end
|
||||
|
||||
it 'removes a notification' do
|
||||
lambda {
|
||||
PostAction.remove_act(evil_trout, post, PostActionType.Types[:like])
|
||||
PostAction.remove_act(evil_trout, post, PostActionType.types[:like])
|
||||
}.should change(Notification, :count).by(-1)
|
||||
end
|
||||
end
|
||||
|
@ -70,7 +70,7 @@ describe Post do
|
||||
end
|
||||
|
||||
it "returns true for moderators" do
|
||||
topic.user.trust_level = TrustLevel.Levels[:moderator]
|
||||
topic.user.trust_level = TrustLevel.levels[:moderator]
|
||||
Fabricate.build(:post, post_args).should be_valid
|
||||
end
|
||||
end
|
||||
@ -81,12 +81,12 @@ describe Post do
|
||||
it 'isFlagged is accurate' do
|
||||
post = Fabricate(:post)
|
||||
user = Fabricate(:coding_horror)
|
||||
PostAction.act(user, post, PostActionType.Types[:off_topic])
|
||||
PostAction.act(user, post, PostActionType.types[:off_topic])
|
||||
|
||||
post.reload
|
||||
post.is_flagged?.should == true
|
||||
|
||||
PostAction.remove_act(user, post, PostActionType.Types[:off_topic])
|
||||
PostAction.remove_act(user, post, PostActionType.types[:off_topic])
|
||||
post.reload
|
||||
post.is_flagged?.should == false
|
||||
end
|
||||
@ -130,22 +130,22 @@ describe Post do
|
||||
|
||||
context "validation" do
|
||||
it "allows a new user to make a post with one image" do
|
||||
post_no_images.user.trust_level = TrustLevel.Levels[:new]
|
||||
post_no_images.user.trust_level = TrustLevel.levels[:new]
|
||||
post_no_images.should be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow multiple images for new accounts" do
|
||||
post_one_image.user.trust_level = TrustLevel.Levels[:new]
|
||||
post_one_image.user.trust_level = TrustLevel.levels[:new]
|
||||
post_one_image.should_not be_valid
|
||||
end
|
||||
|
||||
it "allows multiple images for basic accounts" do
|
||||
post_one_image.user.trust_level = TrustLevel.Levels[:basic]
|
||||
post_one_image.user.trust_level = TrustLevel.levels[:basic]
|
||||
post_one_image.should be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a new user to edit their post to insert an image" do
|
||||
post_no_images.user.trust_level = TrustLevel.Levels[:new]
|
||||
post_no_images.user.trust_level = TrustLevel.levels[:new]
|
||||
post_no_images.save
|
||||
-> {
|
||||
post_no_images.revise(post_no_images.user, post_two_images.raw)
|
||||
@ -176,17 +176,17 @@ describe Post do
|
||||
|
||||
context "validation" do
|
||||
it "allows a new user to make a post with one image" do
|
||||
post_one_link.user.trust_level = TrustLevel.Levels[:new]
|
||||
post_one_link.user.trust_level = TrustLevel.levels[:new]
|
||||
post_one_link.should be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow multiple images for new accounts" do
|
||||
post_two_links.user.trust_level = TrustLevel.Levels[:new]
|
||||
post_two_links.user.trust_level = TrustLevel.levels[:new]
|
||||
post_two_links.should_not be_valid
|
||||
end
|
||||
|
||||
it "allows multiple images for basic accounts" do
|
||||
post_two_links.user.trust_level = TrustLevel.Levels[:basic]
|
||||
post_two_links.user.trust_level = TrustLevel.levels[:basic]
|
||||
post_two_links.should be_valid
|
||||
end
|
||||
end
|
||||
|
@ -16,10 +16,10 @@ describe PostTiming do
|
||||
post = Fabricate(:post)
|
||||
user2 = Fabricate(:coding_horror)
|
||||
|
||||
PostAction.act(user2, post, PostActionType.Types[:like])
|
||||
PostAction.act(user2, post, PostActionType.types[:like])
|
||||
post.user.unread_notifications.should == 1
|
||||
|
||||
post.user.unread_notifications_by_type.should == {Notification.Types[:liked] => 1}
|
||||
post.user.unread_notifications_by_type.should == { Notification.types[:liked] => 1 }
|
||||
|
||||
PostTiming.process_timings(post.user, post.topic_id, 1, 100, [[post.post_number, 100]])
|
||||
|
||||
|
@ -97,13 +97,13 @@ describe UserAction do
|
||||
end
|
||||
|
||||
it "creates a new stream entry" do
|
||||
PostAction.act(liker, post, PostActionType.Types[:like])
|
||||
PostAction.act(liker, post, PostActionType.types[:like])
|
||||
likee_stream.count.should == @old_count + 1
|
||||
end
|
||||
|
||||
context "successful like" do
|
||||
before do
|
||||
PostAction.act(liker, post, PostActionType.Types[:like])
|
||||
PostAction.act(liker, post, PostActionType.types[:like])
|
||||
@liker_action = liker.user_actions.where(action_type: UserAction::LIKE).first
|
||||
@likee_action = likee.user_actions.where(action_type: UserAction::WAS_LIKED).first
|
||||
end
|
||||
@ -124,7 +124,7 @@ describe UserAction do
|
||||
end
|
||||
|
||||
it "doesn't add the entry to the stream" do
|
||||
PostAction.act(liker, post, PostActionType.Types[:like])
|
||||
PostAction.act(liker, post, PostActionType.types[:like])
|
||||
likee_stream.count.should_not == @old_count + 1
|
||||
end
|
||||
|
||||
@ -191,7 +191,7 @@ describe UserAction do
|
||||
before do
|
||||
@post = Fabricate(:post)
|
||||
@user = @post.user
|
||||
PostAction.act(@user, @post, PostActionType.Types[:bookmark])
|
||||
PostAction.act(@user, @post, PostActionType.types[:bookmark])
|
||||
@action = @user.user_actions.where(action_type: UserAction::BOOKMARK).first
|
||||
end
|
||||
|
||||
@ -208,7 +208,7 @@ describe UserAction do
|
||||
@action.user_id.should == @user.id
|
||||
end
|
||||
it 'should nuke the action when unbookmarked' do
|
||||
PostAction.remove_act(@user, @post, PostActionType.Types[:bookmark])
|
||||
PostAction.remove_act(@user, @post, PostActionType.types[:bookmark])
|
||||
@user.user_actions.where(action_type: UserAction::BOOKMARK).first.should be_nil
|
||||
end
|
||||
end
|
||||
|
@ -123,19 +123,19 @@ describe User do
|
||||
|
||||
it "creates a bookmark with the true parameter" do
|
||||
lambda {
|
||||
PostAction.act(@post.user, @post, PostActionType.Types[:bookmark])
|
||||
PostAction.act(@post.user, @post, PostActionType.types[:bookmark])
|
||||
}.should change(PostAction, :count).by(1)
|
||||
end
|
||||
|
||||
describe 'when removing a bookmark' do
|
||||
before do
|
||||
PostAction.act(@post.user, @post, PostActionType.Types[:bookmark])
|
||||
PostAction.act(@post.user, @post, PostActionType.types[:bookmark])
|
||||
end
|
||||
|
||||
it 'reduces the bookmark count of the post' do
|
||||
active = PostAction.where(deleted_at: nil)
|
||||
lambda {
|
||||
PostAction.remove_act(@post.user, @post, PostActionType.Types[:bookmark])
|
||||
PostAction.remove_act(@post.user, @post, PostActionType.types[:bookmark])
|
||||
}.should change(active, :count).by(-1)
|
||||
end
|
||||
end
|
||||
@ -224,11 +224,11 @@ describe User do
|
||||
end
|
||||
|
||||
describe "trust levels" do
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel.Levels[:new]) }
|
||||
let(:user) { Fabricate(:user, trust_level: TrustLevel.levels[:new]) }
|
||||
|
||||
it "sets to the default trust level setting" do
|
||||
SiteSetting.expects(:default_trust_level).returns(TrustLevel.Levels[:advanced])
|
||||
User.new.trust_level.should == TrustLevel.Levels[:advanced]
|
||||
SiteSetting.expects(:default_trust_level).returns(TrustLevel.levels[:advanced])
|
||||
User.new.trust_level.should == TrustLevel.levels[:advanced]
|
||||
end
|
||||
|
||||
describe 'has_trust_level?' do
|
||||
@ -246,12 +246,12 @@ describe User do
|
||||
end
|
||||
|
||||
it "is true if you exceed the level" do
|
||||
user.trust_level = TrustLevel.Levels[:advanced]
|
||||
user.trust_level = TrustLevel.levels[:advanced]
|
||||
user.has_trust_level?(:basic).should be_true
|
||||
end
|
||||
|
||||
it "is true for an admin even with a low trust level" do
|
||||
user.trust_level = TrustLevel.Levels[:new]
|
||||
user.trust_level = TrustLevel.levels[:new]
|
||||
user.admin = true
|
||||
user.has_trust_level?(:advanced).should be_true
|
||||
end
|
||||
@ -264,7 +264,7 @@ describe User do
|
||||
end
|
||||
|
||||
it "is a moderator if the user level is moderator" do
|
||||
user.trust_level = TrustLevel.Levels[:moderator]
|
||||
user.trust_level = TrustLevel.levels[:moderator]
|
||||
user.has_trust_level?(:moderator).should be_true
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user