FEATURE: remove star concept from Discourse

This commit is contained in:
Sam
2015-01-07 12:19:23 +11:00
parent fa8493118b
commit efc717c14a
35 changed files with 50 additions and 448 deletions

View File

@ -562,70 +562,6 @@ describe Topic do
end
end
describe 'toggle_star' do
shared_examples_for "adding a star to a topic" do
it 'triggers a forum topic user change with true' do
# otherwise no chance the mock will work
freeze_time
TopicUser.expects(:change).with(@user, @topic.id, starred: true, starred_at: DateTime.now, unstarred_at: nil)
@topic.toggle_star(@user, true)
end
it 'increases the star_count of the forum topic' do
expect {
@topic.toggle_star(@user, true)
@topic.reload
}.to change(@topic, :star_count).by(1)
end
it 'triggers the rate limiter' do
Topic::StarLimiter.any_instance.expects(:performed!)
@topic.toggle_star(@user, true)
end
end
before do
@topic = Fabricate(:topic)
@user = @topic.user
end
it_should_behave_like "adding a star to a topic"
describe 'removing a star' do
before do
@topic.toggle_star(@user, true)
@topic.reload
end
it 'rolls back the rate limiter' do
Topic::StarLimiter.any_instance.expects(:rollback!)
@topic.toggle_star(@user, false)
end
it 'triggers a forum topic user change with false' do
freeze_time
TopicUser.expects(:change).with(@user, @topic.id, starred: false, unstarred_at: DateTime.now)
@topic.toggle_star(@user, false)
end
it 'reduces the star_count' do
expect {
@topic.toggle_star(@user, false)
@topic.reload
}.to change(@topic, :star_count).by(-1)
end
describe 'and adding a star again' do
before do
@topic.toggle_star(@user, false)
@topic.reload
end
it_should_behave_like "adding a star to a topic"
end
end
end
describe "banner" do
let(:topic) { Fabricate(:topic) }

View File

@ -20,14 +20,14 @@ describe TopicUser do
let(:topic_new_user) { TopicUser.get(topic, new_user)}
let(:yesterday) { DateTime.now.yesterday }
def ensure_topic_user
TopicUser.change(user, topic, last_emailed_post_number: 1)
end
describe "unpinned" do
before do
TopicUser.change(user, topic, {starred_at: yesterday})
end
it "defaults to blank" do
ensure_topic_user
topic_user.cleared_pinned_at.should be_blank
end
@ -37,19 +37,19 @@ describe TopicUser do
it 'should be set to tracking if auto_track_topics is enabled' do
user.update_column(:auto_track_topics_after_msecs, 0)
TopicUser.change(user, topic, {starred_at: yesterday})
ensure_topic_user
TopicUser.get(topic, user).notification_level.should == TopicUser.notification_levels[:tracking]
end
it 'should reset regular topics to tracking topics if auto track is changed' do
TopicUser.change(user, topic, {starred_at: yesterday})
ensure_topic_user
user.auto_track_topics_after_msecs = 0
user.save
topic_user.notification_level.should == TopicUser.notification_levels[:tracking]
end
it 'should be set to "regular" notifications, by default on non creators' do
TopicUser.change(user, topic, {starred_at: yesterday})
ensure_topic_user
TopicUser.get(topic,user).notification_level.should == TopicUser.notification_levels[:regular]
end
@ -195,37 +195,20 @@ describe TopicUser do
describe 'change a flag' do
it 'creates a forum topic user record' do
user; topic
lambda {
TopicUser.change(user, topic.id, starred: true)
}.should change(TopicUser, :count).by(1)
end
it "only inserts a row once, even on repeated calls" do
topic; user
lambda {
TopicUser.change(user, topic.id, starred: true)
TopicUser.change(user, topic.id, starred: false)
TopicUser.change(user, topic.id, starred: true)
TopicUser.change(user, topic.id, total_msecs_viewed: 1)
TopicUser.change(user, topic.id, total_msecs_viewed: 2)
TopicUser.change(user, topic.id, total_msecs_viewed: 3)
}.should change(TopicUser, :count).by(1)
end
it 'triggers the observer callbacks when updating' do
UserActionObserver.instance.expects(:after_save).twice
3.times { TopicUser.change(user, topic.id, starred: true) }
end
describe 'after creating a row' do
before do
TopicUser.change(user, topic.id, starred: true)
end
it 'has the correct starred value' do
TopicUser.get(topic, user).should be_starred
ensure_topic_user
end
it 'has a lookup' do

View File

@ -257,38 +257,6 @@ describe UserAction do
end
describe 'synchronize_starred' do
it 'corrects out of sync starred' do
post = Fabricate(:post)
post.topic.toggle_star(post.user, true)
UserAction.delete_all
UserAction.log_action!(
action_type: UserAction::STAR,
user_id: post.user.id,
acting_user_id: post.user.id,
target_topic_id: 99,
target_post_id: -1,
)
UserAction.log_action!(
action_type: UserAction::STAR,
user_id: Fabricate(:user).id,
acting_user_id: post.user.id,
target_topic_id: post.topic_id,
target_post_id: -1,
)
UserAction.synchronize_starred
actions = UserAction.all.to_a
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
describe 'synchronize_target_topic_ids' do
it 'correct target_topic_id' do
post = Fabricate(:post)