forked from rubysherpas/forem
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rubysherpas#143 - more detailed forum and topic view tracking
- Loading branch information
Showing
8 changed files
with
135 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class AddForemViewFields < ActiveRecord::Migration | ||
def up | ||
add_column :forem_views, :current_viewed_at, :datetime | ||
add_column :forem_views, :past_viewed_at, :datetime | ||
add_column :forem_topics, :views_count, :integer, :default=>0 | ||
add_column :forem_forums, :views_count, :integer, :default=>0 | ||
|
||
Forem::Topic.find_each do |topic| | ||
topic.update_column(:views_count, topics.views.sum(:count)) | ||
end | ||
|
||
Forem::Forum.find_each do |forum| | ||
forum.update_column(:views_count, forum.topics.sum(:views_count)) | ||
end | ||
end | ||
|
||
def down | ||
remove_column :forem_views, :current_viewed_at, :datetime | ||
remove_column :forem_views, :past_viewed_at, :datetime | ||
remove_column :forem_topics, :views_count, :integer, :default=>0 | ||
remove_column :forem_forums, :views_count, :integer, :default=>0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require 'spec_helper' | ||
|
||
describe "forums" do | ||
let!(:forum) { FactoryGirl.create(:forum) } | ||
|
||
it "listing all" do | ||
visit forums_path | ||
within(".forum") do | ||
page.should have_content("Welcome to Forem!") | ||
within(".description") do | ||
page.should have_content("A placeholder forum.") | ||
end | ||
end | ||
end | ||
|
||
context "visiting a forum" do | ||
before do | ||
@topic_1 = FactoryGirl.create(:topic, :subject => "Unpinned", :forum => forum) | ||
@topic_2 = FactoryGirl.create(:topic, :subject => "Most Recent", :forum => forum) | ||
FactoryGirl.create(:post, :topic => @topic_2, :created_at => Time.now + 30.seconds) | ||
@topic_3 = FactoryGirl.create(:topic, :subject => "PINNED!", :forum => forum, :pinned => true) | ||
@topic_4 = FactoryGirl.create(:topic, :subject => "HIDDEN!", :forum => forum, :hidden => true) | ||
visit forum_path(forum) | ||
end | ||
|
||
it "lists pinned topics first" do | ||
# TODO: cleaner way to get at topic subjects on the page? | ||
topic_subjects = Nokogiri::HTML(page.body).css(".topics tbody tr .subject").map(&:text) | ||
topic_subjects.should == ["PINNED!", "Most Recent", "Unpinned"] | ||
end | ||
|
||
it "does not show hidden topics" do | ||
# TODO: cleaner way to get at topic subjects on the page? | ||
topic_subjects = Nokogiri::HTML(page.body).css(".topics tbody tr .subject").map(&:text) | ||
topic_subjects.include?("HIDDEN!").should be_false | ||
end | ||
|
||
context "when logged in" do | ||
before do | ||
@user = Factory(:user) | ||
sign_in(@user) | ||
end | ||
it "calls out topics that have been posted to since your last visit, if you've visited" do | ||
visit forum_topic_path(forum.id, @topic_2) | ||
::Forem::View.last.update_attribute(:updated_at, 1.minute.ago) | ||
visit forum_path(forum) | ||
topic_subjects = Nokogiri::HTML(page.body).css(".topics tbody tr .new_posts") | ||
topic_subjects.should_not be_empty | ||
end | ||
|
||
it "calls out new topics since last visit" do | ||
forum.topics.clear | ||
forum.register_view_by(@user) | ||
forum.view_for(@user).update_attribute(:updated_at, 3.days.ago) | ||
|
||
new_topic = FactoryGirl.create(:topic, :subject => "New Since Visit", :forum => forum, :created_at=>1.day.ago) | ||
old_topic = FactoryGirl.create(:topic, :subject => "Already Viewed", :forum => forum, :created_at=>4.day.ago) | ||
|
||
visit forum_path(forum) | ||
new_topics = Nokogiri::HTML(page.body).css(".topics tbody tr super") | ||
new_topics.size.should eq(1) # should include the one just created | ||
|
||
visit forum_topic_path(forum, topic) | ||
|
||
visit forum_path(forum) | ||
new_topics = Nokogiri::HTML(page.body).css(".topics tbody tr super") | ||
new_topics.size.should eq(3) # should include the one just created | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters