File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,4 +12,10 @@ class Stringer < Sinatra::Base
1212 story . is_read = true
1313 StoryRepository . save ( story )
1414 end
15+
16+ post "/mark_all_as_read" do
17+ StoryRepository . mark_all_as_read
18+
19+ redirect to ( "/news" )
20+ end
1521end
Original file line number Diff line number Diff line change @@ -38,4 +38,10 @@ $(document).ready(function() {
3838 $ . post ( "/mark_as_read" , { story_id : $this . data ( "id" ) } )
3939 . fail ( function ( ) { alert ( "something broke!" ) ; } ) ;
4040 } ) ;
41+
42+ $ ( "#mark-all" ) . click ( function ( e ) {
43+ e . preventDefault ( ) ;
44+
45+ $ ( "form#mark-all-as-read" ) . submit ( ) ;
46+ } ) ;
4147} ) ;
Original file line number Diff line number Diff line change @@ -21,4 +21,8 @@ def self.save(story)
2121 def self . unread
2222 Story . where ( is_read : false ) . order ( :published )
2323 end
24+
25+ def self . mark_all_as_read
26+ Story . update_all ( is_read : false , is_read : true )
27+ end
2428end
Original file line number Diff line number Diff line change 1818 </ a >
1919 </ div >
2020 </ div >
21+
22+ < div class ="hidden ">
23+ < form id ="mark-all-as-read " method ="POST " action ="/mark_all_as_read "> </ form >
24+ </ div >
2125</ div >
2226
2327<% unless @unread_stories . empty? %>
Original file line number Diff line number Diff line change 5454 story_one . is_read . should be_true
5555 end
5656 end
57+
58+ describe "/mark_all_as_read" do
59+ it "marks all unread stories as read and reload the page" do
60+ StoryRepository . should_receive ( :mark_all_as_read ) . once
61+
62+ post "/mark_all_as_read"
63+
64+ last_response . status . should be 302
65+ URI ::parse ( last_response . location ) . path . should eq "/news"
66+ end
67+ end
5768end
You can’t perform that action at this time.
0 commit comments