From 30acefc852a4bdfc879c1a678ad017ba5cb948b5 Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Wed, 7 Mar 2012 13:10:54 +0700 Subject: [PATCH 1/4] Users can mark articles as read on articles/activities index page --- app/controllers/activities_controller.rb | 10 +++++++--- app/controllers/articles_controller.rb | 11 ++++++++--- app/decorators/activity_decorator.rb | 7 +++++++ app/decorators/article_decorator.rb | 7 +++++++ app/views/activities/_activity.html.haml | 1 + app/views/articles/_article.html.haml | 1 + app/views/shared/_unread_count.html.haml | 2 +- app/views/shared/mark_as_read.js.erb | 7 +++++++ config/routes.rb | 6 +++++- 9 files changed, 44 insertions(+), 8 deletions(-) create mode 100644 app/views/shared/mark_as_read.js.erb diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index fe55c14..229d5d2 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -2,8 +2,8 @@ class ActivitiesController < ApplicationController before_filter :user_required before_filter :find_activity, :only => [ :show, :edit, :update, :destroy, :register, :archive, :restore, - :create_discussion_list ] - before_filter :mark_as_read, :only => [ :show ] + :create_discussion_list, :read ] + before_filter :mark_as_read, :only => [ :show, :read ] before_filter :authorized_users_only, :only => [ :edit, :update, :destroy, :archive, :restore, :create_discussion_list ] @@ -27,7 +27,6 @@ def show @user = UserDecorator.decorate(current_user) end - def new @activity = Activity.new(:registration_open => true) end @@ -96,6 +95,11 @@ def create_discussion_list end end + def read + @resource = @activity + render "shared/mark_as_read" + end + private def find_activity diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 9aaaa4a..69c1783 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -1,9 +1,9 @@ class ArticlesController < ApplicationController respond_to :html - before_filter :user_required, :only => [:new, :create, :edit, :update, :destroy] - before_filter :find_article, :only => [:show, :edit, :update, :destroy] - before_filter :mark_as_read, :only => [:show] + before_filter :user_required, :only => [:new, :create, :edit, :update, :destroy, :read] + before_filter :find_article, :only => [:show, :edit, :update, :destroy, :read] + before_filter :mark_as_read, :only => [:show, :read] before_filter :authorized_users_only, :only => [:edit, :update, :destroy] before_filter :profile_required, :only => [:new, :create] @@ -57,6 +57,11 @@ def destroy redirect_to(articles_path, :notice => 'Article was successfully destroyed.') end + def read + @resource = @article + render "shared/mark_as_read" + end + private def authorized_users_only diff --git a/app/decorators/activity_decorator.rb b/app/decorators/activity_decorator.rb index f9a3a11..0c853d7 100644 --- a/app/decorators/activity_decorator.rb +++ b/app/decorators/activity_decorator.rb @@ -69,6 +69,13 @@ def participants_link h.content_tag(:div, link || "", :class => "participants").html_safe end + def mark_as_read_link + h.link_to "Mark as read", h.read_activity_path(activity), + :class => 'mark-as-read', + :method => :post, + :remote => true unless activity.read_by?(h.current_user) + end + def css_class css_class = [] css_class << 'unread' unless activity.read_by?(h.current_user) diff --git a/app/decorators/article_decorator.rb b/app/decorators/article_decorator.rb index e0b7522..764d843 100644 --- a/app/decorators/article_decorator.rb +++ b/app/decorators/article_decorator.rb @@ -29,6 +29,13 @@ def short_url RestClient.post("http://is.gd/create.php", :format => "simple", :url => url) end + def mark_as_read_link + h.link_to "Mark as read", h.read_article_path(article), + :class => 'mark-as-read', + :method => :post, + :remote => true unless article.read_by?(h.current_user) + end + def css css_classes = [] diff --git a/app/views/activities/_activity.html.haml b/app/views/activities/_activity.html.haml index 004402f..b37426b 100644 --- a/app/views/activities/_activity.html.haml +++ b/app/views/activities/_activity.html.haml @@ -1,6 +1,7 @@ = content_tag_for(:div, activity, :class => activity.css_class) do .activity_title - if @activities + %span.mark-as-read= activity.mark_as_read_link = link_to activity.title, activity_path(activity) - else = activity.title diff --git a/app/views/articles/_article.html.haml b/app/views/articles/_article.html.haml index 8d89209..edee4be 100644 --- a/app/views/articles/_article.html.haml +++ b/app/views/articles/_article.html.haml @@ -1,6 +1,7 @@ = content_tag_for :article, article, class: article.css do .article_title - if @articles + %span.mark-as-read= article.mark_as_read_link = link_to article.title, article_path(article) - else = article.title diff --git a/app/views/shared/_unread_count.html.haml b/app/views/shared/_unread_count.html.haml index 78d073a..18d8a72 100644 --- a/app/views/shared/_unread_count.html.haml +++ b/app/views/shared/_unread_count.html.haml @@ -1,3 +1,3 @@ - if count > 0 %span.unread_count{rel: 'twipsy', title: "Unread #{type}", - data: { placement: 'below' }}= count \ No newline at end of file + data: { type: type, placement: 'below' }}= count diff --git a/app/views/shared/mark_as_read.js.erb b/app/views/shared/mark_as_read.js.erb new file mode 100644 index 0000000..6155ad9 --- /dev/null +++ b/app/views/shared/mark_as_read.js.erb @@ -0,0 +1,7 @@ +var unreadCount = $('.unread_count[data-type=<%= params[:controller] %>]'); +unreadCount.text(parseInt(unreadCount.text()) - 1); +if( unreadCount.text() === '0' ) { + unreadCount.remove(); +} + +$('#<%= dom_id(@resource) %> .mark-as-read').remove(); diff --git a/config/routes.rb b/config/routes.rb index fbaf31f..dcdf98a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,13 +8,17 @@ match '/read_all/:type' => 'people#read_all', as: 'read_all' resources :people - resources :articles + resources :articles do + post :read, :on => :member + end + resources :activities do member do post :register post :archive post :restore post :create_discussion_list + post :read end collection do get :archived From 66b13ee9a5c1a299a202c5f929505102005bf261 Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Wed, 7 Mar 2012 16:43:18 +0700 Subject: [PATCH 2/4] Add styling to mark as read indicantor on articles/activities index page --- app/assets/images/icons/unread.png | Bin 0 -> 1991 bytes app/assets/stylesheets/partials/_activities.sass | 3 +-- app/assets/stylesheets/partials/_articles.sass | 5 ++--- app/assets/stylesheets/partials/_mixins.sass | 14 +++++++++++++- app/views/activities/_activity.html.haml | 2 +- app/views/articles/_article.html.haml | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 app/assets/images/icons/unread.png diff --git a/app/assets/images/icons/unread.png b/app/assets/images/icons/unread.png new file mode 100644 index 0000000000000000000000000000000000000000..ff4618e99095b35e64824bcd6f5d336639c07d6a GIT binary patch literal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Eue~s>FRQaBp*=?*ZY5kq&n9W`aO6 ziW?>ZV&7H0Cr{nSY!Zq*464WVvUArTQ|Dw#&615AW5+!(P%F3d%dh)8CrUm%$XZ0g>k z+iUmOfqOGMRov{6h5SjQmNJ$^G$ecEKEkJcjlUyAr-&5pJZBSuUY^yj3 zOCh243e{fsrJKCtCy%uM`RmFL4pFcA^Y)?DiM;vTnbnDvANtvM<9}Qn%@7r}ZgqA0 zT)?8Uiz5DL`6MDb=|6hGSR+XKBf8H~@)6SeRa4ic`_)fI8o6VQEZ~$%n8fP7ile*MaUK6ks73q1LF`wdtQcvPJ0wPsXaiRz@339$k z6!?+Y1P4{SxU4mP$*oEDNj_~fDGr=7In*Ckc2_NTC{2pu%~DeUPwADpRzD}^jhKxa zo%HzgW$&2)j=zSty*%~Jx*Q%6!}PArG~a{Od!xW=k7;OA8~CMpIjuDmEGR<{Q$fK8-_9yM)Dh|%Li#5Ag~z4HqnExET*#QE7i^ zx_x%G+{pCozHZ>Qk4=)7X{Xsz^_se&Lnb#5FM8Q$=vF2tIf4D3v(Z5Vs)FWgY7vJO z6u&A-w>L`L1k$1F%9@pPV%1&t`wKhkLf>n?6fAcYaZeI%86@nS24AKMf-a1Hw3}X= zSO2sIYbj+fS4p{IU*LM?I&Zcfk<$Bp?)oQDO-#1tW$C>#*cOe!?HX-I1rov;0|Gfa L9J4RS{1WpwVh4F! literal 0 HcmV?d00001 diff --git a/app/assets/stylesheets/partials/_activities.sass b/app/assets/stylesheets/partials/_activities.sass index b0bc693..ae07f88 100644 --- a/app/assets/stylesheets/partials/_activities.sass +++ b/app/assets/stylesheets/partials/_activities.sass @@ -1,9 +1,8 @@ div.activity +container - &.unread div.activity_title - font-weight: bold div.activity_title +column(20, true) + +mark-as-read font-size: 1.5em font-family: $display-font margin-bottom: 1em diff --git a/app/assets/stylesheets/partials/_articles.sass b/app/assets/stylesheets/partials/_articles.sass index e90768b..543b7f1 100644 --- a/app/assets/stylesheets/partials/_articles.sass +++ b/app/assets/stylesheets/partials/_articles.sass @@ -2,6 +2,7 @@ article +container div.article_title +column(20) + +mark-as-read font-size: 1.5em font-family: $display-font margin-bottom: 1em @@ -44,12 +45,10 @@ article &.private .article_title padding-left: 30px background: asset-url('icons/butterfly.png', image) 0 0 no-repeat - &.unread .article_title - font-weight: bold #articles article.highlight border: 1px dashed #AE9331 padding: 10px margin: 0 -5px +border-radius(4px) - background-color: #FAFAE2 \ No newline at end of file + background-color: #FAFAE2 diff --git a/app/assets/stylesheets/partials/_mixins.sass b/app/assets/stylesheets/partials/_mixins.sass index a0ecb03..5db1d9e 100644 --- a/app/assets/stylesheets/partials/_mixins.sass +++ b/app/assets/stylesheets/partials/_mixins.sass @@ -15,4 +15,16 @@ +single-box-shadow(#000, 0, 0, 0) display: inline margin: 0 - background-color: inherit \ No newline at end of file + background-color: inherit + +=mark-as-read + div.mark-as-read + float: left + margin-right: 17px + a + width: 17px + height: 17px + background: image_url('icons/unread.png') 0 0 no-repeat + text-indent: -9999px + display: block + diff --git a/app/views/activities/_activity.html.haml b/app/views/activities/_activity.html.haml index b37426b..39a9e67 100644 --- a/app/views/activities/_activity.html.haml +++ b/app/views/activities/_activity.html.haml @@ -1,7 +1,7 @@ = content_tag_for(:div, activity, :class => activity.css_class) do .activity_title - if @activities - %span.mark-as-read= activity.mark_as_read_link + .mark-as-read= activity.mark_as_read_link = link_to activity.title, activity_path(activity) - else = activity.title diff --git a/app/views/articles/_article.html.haml b/app/views/articles/_article.html.haml index edee4be..c44cf6b 100644 --- a/app/views/articles/_article.html.haml +++ b/app/views/articles/_article.html.haml @@ -1,7 +1,7 @@ = content_tag_for :article, article, class: article.css do .article_title - if @articles - %span.mark-as-read= article.mark_as_read_link + .mark-as-read= article.mark_as_read_link = link_to article.title, article_path(article) - else = article.title From 1037d1c2a699ebc17699793c7919ada2c09b3142 Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Wed, 7 Mar 2012 23:47:39 +0700 Subject: [PATCH 3/4] Update styling for unread indicator --- app/assets/images/icons/unread.png | Bin 1991 -> 3570 bytes app/assets/stylesheets/partials/_mixins.sass | 16 +++++++--------- app/decorators/activity_decorator.rb | 6 ++++-- app/decorators/article_decorator.rb | 4 +++- app/views/activities/_activity.html.haml | 2 +- app/views/articles/_article.html.haml | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/assets/images/icons/unread.png b/app/assets/images/icons/unread.png index ff4618e99095b35e64824bcd6f5d336639c07d6a..dd50efd144ae29154a418f4eab011a3cc2c54f16 100644 GIT binary patch delta 3569 zcmVEX>4Tx0C?J+Q+HUC_ZB|i_hk=OLfG)J zmu!ImA|tE_$Pihg5Rw34gb)%y#f69pRumNxoJdu~g4GI0orvO~D7a@qiilc^Ra`jk zAKa(4eR}Wh?fcjJyyu+f{LXpL4}cL8CXwc%Y5+M>g*-agAAgTeNW{s#fC3dr-~=EL z=F7ro1;qdW@B?{xesr)u`~k0T00IDT)h;9w$Kn5jx= z$P@s`7yz(Svt$YYlmGy1d3-`50ICfD?DR=K1pwHoliU{o*rFV%2mp-%0GTL9BmzLY z0AN*tQY-?%!hZmutUw|z1i-EVfLXROM*@Jo1ps!ASdb4uU;u!bLM+SxAUFa5Lmm^& z10YNTpfJ+E;Hh75g}6uo0Km(Y&6i8kGZeU$&>DC0@ZjPh;=*jPLSYvv5M~MFBAl0- zBNIsH15C~g000{K(ZT*WKal6<l4`aK{0#b-!z=TL9Wt0BGO&T{GJWpjryhdijfaIQ&2!o}p04JRKYg3k&TfVxhe- zO!X{f;To z;xw^bEPoY>@mPttP$EsodAU-NL?OwQ;u7h9GVvdl{RxwI4FIf$Pry#L2er#=z<%xl z0*ek<(slqqe)BDi8VivC5N9+pdG`PSlfU_oKq~;2Moa!tiTSO!5zH77Xo1hL_iEAz&sE_27ly$915WrmO&X*z&h9jwXg#kpb?tk z5VXNDI1T6E5?q1na2Ez(7@ooyyoLz`LC6RbVIew*5n_(mBF+dGnT`Y^VMsKRfTSSl zh!jyG#mI7`0;xi3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gqA0 zT)?8Uiz5DL`6MDb=|6hGSR+XKBf8H~@)6SeRa4ic`_)fI8o6VQEZ~$%n8fP7ile*MaUK6ks73q1LF`wdtQcvPJ0wPsXaiRz@339$k z6!?+Y1P4{SxU4mP$*oEDNj_~fDGr=7In*Ckc2_NTC{2pu%~DeUPwADpRzD}^jhKxa zo%HzgW$&2)j=zSty*%~Jx*Q%6!}PArG~a{Od!xW=k7;OA8~CMpIjuDmEGR<{Q$fK8-_9yM)Dh|%Li#5Ag~z4HqnExET*#QE7i^ zx_x%G+{pCozHZ>Qk4=)7X{Xsz^_se&Lnb#5FM8Q$=vF2tIf4D3v(Z5Vs)FWgY7vJO z6u&A-w>L`L1k$1F%9@pPV%1&t`wKhkLf>n?6fAcYaZeI%86@nS24AKMf-a1Hw3}X= zSO2sIYbj+fS4p{IU*LM?I&Zcfk<$Bp?)oQDO-#1tW$C>#*cOe!?HX-I1rov;0|Gfa L9J4RS{1WpwVh4F! diff --git a/app/assets/stylesheets/partials/_mixins.sass b/app/assets/stylesheets/partials/_mixins.sass index 5db1d9e..34b0529 100644 --- a/app/assets/stylesheets/partials/_mixins.sass +++ b/app/assets/stylesheets/partials/_mixins.sass @@ -18,13 +18,11 @@ background-color: inherit =mark-as-read - div.mark-as-read - float: left - margin-right: 17px - a - width: 17px - height: 17px - background: image_url('icons/unread.png') 0 0 no-repeat - text-indent: -9999px - display: block + a.mark-as-read + margin-right: 15px + width: 17px + height: 17px + background: image_url('icons/unread.png') 0 0 no-repeat + text-indent: -9999px + display: inline-block diff --git a/app/decorators/activity_decorator.rb b/app/decorators/activity_decorator.rb index 0c853d7..ab9b0d2 100644 --- a/app/decorators/activity_decorator.rb +++ b/app/decorators/activity_decorator.rb @@ -70,9 +70,11 @@ def participants_link end def mark_as_read_link - h.link_to "Mark as read", h.read_activity_path(activity), - :class => 'mark-as-read', + h.link_to "Mark as read", h.read_activity_path(activity), :method => :post, + :class => 'mark-as-read', + :rel => 'twipsy', + :title => "Mark as read", :remote => true unless activity.read_by?(h.current_user) end diff --git a/app/decorators/article_decorator.rb b/app/decorators/article_decorator.rb index 764d843..f843f1f 100644 --- a/app/decorators/article_decorator.rb +++ b/app/decorators/article_decorator.rb @@ -31,8 +31,10 @@ def short_url def mark_as_read_link h.link_to "Mark as read", h.read_article_path(article), - :class => 'mark-as-read', :method => :post, + :class => 'mark-as-read', + :rel => 'twipsy', + :title => "Mark as read", :remote => true unless article.read_by?(h.current_user) end diff --git a/app/views/activities/_activity.html.haml b/app/views/activities/_activity.html.haml index 39a9e67..a258812 100644 --- a/app/views/activities/_activity.html.haml +++ b/app/views/activities/_activity.html.haml @@ -1,7 +1,7 @@ = content_tag_for(:div, activity, :class => activity.css_class) do .activity_title - if @activities - .mark-as-read= activity.mark_as_read_link + = activity.mark_as_read_link = link_to activity.title, activity_path(activity) - else = activity.title diff --git a/app/views/articles/_article.html.haml b/app/views/articles/_article.html.haml index c44cf6b..7125a5d 100644 --- a/app/views/articles/_article.html.haml +++ b/app/views/articles/_article.html.haml @@ -1,7 +1,7 @@ = content_tag_for :article, article, class: article.css do .article_title - if @articles - .mark-as-read= article.mark_as_read_link + = article.mark_as_read_link = link_to article.title, article_path(article) - else = article.title From 64b82f51b1ff1ffa9c15b3fa16a753c087e65d43 Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Wed, 7 Mar 2012 23:58:23 +0700 Subject: [PATCH 4/4] Add integration tests for unread articles feature --- Gemfile | 1 + Gemfile.lock | 2 ++ test/integration/articles_test.rb | 11 ------ test/integration/unread_items_test.rb | 48 +++++++++++++++++++++++++++ test/test_helper.rb | 17 ++++++++-- 5 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 test/integration/unread_items_test.rb diff --git a/Gemfile b/Gemfile index 895a45b..6885200 100644 --- a/Gemfile +++ b/Gemfile @@ -41,6 +41,7 @@ group 'test' do gem 'colorific', '~> 1.0.0' gem 'test_notifier', '~> 1.0.0' gem 'mocha' + gem 'database_cleaner' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index da23754..015f7fb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,6 +71,7 @@ GEM chunky_png (~> 1.2) fssm (>= 0.2.7) sass (~> 3.1) + database_cleaner (0.7.1) erubis (2.7.0) exception_notification (2.5.2) actionmailer (>= 3.0.4) @@ -225,6 +226,7 @@ DEPENDENCIES coffee-rails (~> 3.1.1) colorific (~> 1.0.0) compass (~> 0.12.alpha) + database_cleaner draper! exception_notification factory_girl_rails diff --git a/test/integration/articles_test.rb b/test/integration/articles_test.rb index c7dfca2..39b6cab 100644 --- a/test/integration/articles_test.rb +++ b/test/integration/articles_test.rb @@ -46,15 +46,4 @@ def setup visit article_path(@article) assert_content("Restricted Unicorns!") end - - test "unicorns see an unread article" do - visit articles_path - assert_no_content("1 Updates") - - sign_user_in(@user) - assert_content("1 Updates") - - visit article_path(@article) - assert_no_content("1 Updates") - end end diff --git a/test/integration/unread_items_test.rb b/test/integration/unread_items_test.rb new file mode 100644 index 0000000..e909d15 --- /dev/null +++ b/test/integration/unread_items_test.rb @@ -0,0 +1,48 @@ +require 'test_helper' + +class UnreadItemsTest < ActionDispatch::IntegrationTest + def setup + @user = FactoryGirl.create(:user) + @article = FactoryGirl.create(:article, title: "Unicorns!", author: @user) + end + + test "unicorns see an unread article" do + visit articles_path + assert_no_content("1 Updates") + + sign_user_in(@user) + assert_content("1 Updates") + + visit article_path(@article) + assert_no_content("1 Updates") + end + + test "unicorns can mark all articles as read" do + 2.times { FactoryGirl.create(:article, title: "Title of Unicorns!", author: @user) } + + visit articles_path + assert_no_content("3 Updates") + + sign_user_in(@user) + assert_content("3 Updates") + + click_on "Mark all as read" + assert_no_content("3 Updates") + end + + test "unicorns can mark as read on an article via clicking on unread indicator" do + Capybara.current_driver = Capybara.javascript_driver + + sign_user_in(@user) + + assert_content("1 Updates") + + within("#article_#{@article.id}") do + click_link "Mark as read" + + assert_no_link("Mark as read") + end + + assert_no_content("1 Updates") + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 342091c..421ae1e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,12 +10,25 @@ TestNotifier.silence_no_notifier_warning = true OmniAuth.config.test_mode = true +DatabaseCleaner.clean_with :truncation +DatabaseCleaner.strategy = :truncation + class ActionDispatch::IntegrationTest include Capybara::DSL include Support::Integration include Support::Auth - setup { mock_uniweb_user({}) } - teardown { Capybara.reset_sessions! } + self.use_transactional_fixtures = false + + setup do + DatabaseCleaner.start + mock_uniweb_user({}) + end + + teardown do + DatabaseCleaner.clean + Capybara.reset_sessions! + Capybara.use_default_driver + end end