diff --git a/TODO/spec/controllers/stories_controller_spec.rb b/TODO/spec/controllers/stories_controller_spec.rb index d0ebe15d9..13ad355fb 100644 --- a/TODO/spec/controllers/stories_controller_spec.rb +++ b/TODO/spec/controllers/stories_controller_spec.rb @@ -57,8 +57,8 @@ end describe "GET /archive" do - let(:read_one) { StoryFactory.build(is_read: true) } - let(:read_two) { StoryFactory.build(is_read: true) } + let(:read_one) { StoryFactory.build(readed: true) } + let(:read_two) { StoryFactory.build(readed: true) } let(:stories) { [read_one, read_two].paginate } before { allow(StoryRepository).to receive(:read).and_return(stories) } @@ -72,8 +72,8 @@ end describe "GET /starred" do - let(:starred_one) { StoryFactory.build(is_starred: true) } - let(:starred_two) { StoryFactory.build(is_starred: true) } + let(:starred_one) { StoryFactory.build(starred: true) } + let(:starred_two) { StoryFactory.build(starred: true) } let(:stories) { [starred_one, starred_two].paginate } before { allow(StoryRepository).to receive(:starred).and_return(stories) } @@ -88,14 +88,14 @@ describe "PUT /stories/:id" do before { allow(StoryRepository).to receive(:fetch).and_return(story_one) } - context "is_read parameter" do + context "readed parameter" do context "when it is not malformed" do it "marks a story as read" do expect(StoryRepository).to receive(:save).once - put "/stories/#{story_one.id}", { is_read: true }.to_json + put "/stories/#{story_one.id}", { readed: true }.to_json - expect(story_one.is_read).to eq true + expect(story_one.readed).to eq true end end @@ -103,9 +103,9 @@ it "marks a story as read" do expect(StoryRepository).to receive(:save).once - put "/stories/#{story_one.id}", { is_read: "malformed" }.to_json + put "/stories/#{story_one.id}", { readed: "malformed" }.to_json - expect(story_one.is_read).to eq true + expect(story_one.readed).to eq true end end end @@ -128,20 +128,20 @@ end end - context "is_starred parameter" do + context "starred parameter" do context "when it is not malformed" do it "marks a story as permanently starred" do - put "/stories/#{story_one.id}", { is_starred: true }.to_json + put "/stories/#{story_one.id}", { starred: true }.to_json - expect(story_one.is_starred).to eq true + expect(story_one.starred).to eq true end end context "when it is malformed" do it "marks a story as permanently starred" do - put "/stories/#{story_one.id}", { is_starred: "malformed" }.to_json + put "/stories/#{story_one.id}", { starred: "malformed" }.to_json - expect(story_one.is_starred).to eq true + expect(story_one.starred).to eq true end end end @@ -179,8 +179,8 @@ allow(FeedRepository).to receive(:fetch).and_return(story_one.feed) allow(StoryRepository).to receive(:feed).and_return(stories) - story_one.is_read = false - story_two.is_read = true + story_one.readed = false + story_two.readed = true get "/feed/#{story_one.feed.id}" diff --git a/TODO/spec/fever_api_spec.rb b/TODO/spec/fever_api_spec.rb index 011d0eb43..4310d61e9 100644 --- a/TODO/spec/fever_api_spec.rb +++ b/TODO/spec/fever_api_spec.rb @@ -169,7 +169,7 @@ def make_request(extra_headers = {}) end it "returns starred items when 'saved_item_ids' header is provided" do - expect(Story).to receive(:where).with(is_starred: true).and_return([story_one, story_two]) + expect(Story).to receive(:where).with(starred: true).and_return([story_one, story_two]) make_request(saved_item_ids: nil) diff --git a/TODO/spec/javascript/spec/models/story_spec.js b/TODO/spec/javascript/spec/models/story_spec.js index e666993ff..fd194eff6 100644 --- a/TODO/spec/javascript/spec/models/story_spec.js +++ b/TODO/spec/javascript/spec/models/story_spec.js @@ -19,18 +19,18 @@ describe("Story", function(){ story.get("selected").should.be.true; }); - it("sets is_read to true if keep_unread isn't true", function(){ + it("sets readed to true if keep_unread isn't true", function(){ var story = new Story(); (!! story.get("keep_unread")).should.be.false; story.open(); - story.get("is_read").should.be.true; + story.get("readed").should.be.true; }); - it("doesn't sets is_read to true if keep_unread is true", function(){ + it("doesn't sets readed to true if keep_unread is true", function(){ var story = new Story(); story.set("keep_unread", true); story.open(); - (!! story.get("is_read")).should.be.false; + (!! story.get("readed")).should.be.false; }); it("calls closeOthers, unselectAll, setSelection on collection", function(){ @@ -117,7 +117,7 @@ describe("Story", function(){ it("returns false if it has changedAttributes but no id", function(){ var story = new Story(); sinon.stub(story, "changedAttributes", function(){ - return {is_read: true}; + return {readed: true}; }); story.shouldSave().should.be.false; story.changedAttributes.should.have.been.calledOnce; @@ -126,7 +126,7 @@ describe("Story", function(){ it("returns true if it has changedAttributes and an id", function(){ var story = new Story({id: 1}); sinon.stub(story, "changedAttributes", function(){ - return {is_read: true}; + return {readed: true}; }); story.shouldSave().should.be.true; story.changedAttributes.should.have.been.calledOnce; diff --git a/TODO/spec/javascript/spec/views/story_view_spec.js b/TODO/spec/javascript/spec/views/story_view_spec.js index c7a556c97..6e0565cbc 100644 --- a/TODO/spec/javascript/spec/views/story_view_spec.js +++ b/TODO/spec/javascript/spec/views/story_view_spec.js @@ -16,8 +16,8 @@ describe("Storyiew", function(){ pretty_date: "Mon July 1, 2013", permalink: "http://example.com/krunch", keep_unread: false, - is_read: false, - is_starred: false + readed: false, + starred: false }); this.view = new StoryView({model: this.story}) @@ -98,7 +98,7 @@ describe("Storyiew", function(){ it("should autofill star button based on item", function(){ assertTagExists(this.view.$el, ".story-starred .icon-star-empty", 2); - this.story.set("is_starred", true); + this.story.set("starred", true); this.view.render(); assertTagExists(this.view.$el, ".story-starred .icon-star", 2); diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index aca4f5422..44c252e52 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -54,7 +54,7 @@ var Story = Backbone.Model.extend({ }, open: function() { - if (!this.get("keep_unread")) this.set("is_read", true); + if (!this.get("keep_unread")) this.set("readed", true); if (this.shouldSave()) this.save(); if(this.collection){ @@ -70,20 +70,20 @@ var Story = Backbone.Model.extend({ toggleKeepUnread: function() { if (this.get("keep_unread")) { this.set("keep_unread", false); - this.set("is_read", true); + this.set("readed", true); } else { this.set("keep_unread", true); - this.set("is_read", false); + this.set("readed", false); } if (this.shouldSave()) this.save(); }, toggleStarred: function() { - if (this.get("is_starred")) { - this.set("is_starred", false); + if (this.get("starred")) { + this.set("starred", false); } else { - this.set("is_starred", true); + this.set("starred", true); } if (this.shouldSave()) this.save(); @@ -124,15 +124,15 @@ var StoryView = Backbone.View.extend({ this.listenTo(this.model, 'add', this.render); this.listenTo(this.model, 'change:selected', this.itemSelected); this.listenTo(this.model, 'change:open', this.itemOpened); - this.listenTo(this.model, 'change:is_read', this.itemRead); + this.listenTo(this.model, 'change:readed', this.itemRead); this.listenTo(this.model, 'change:keep_unread', this.itemKeepUnread); - this.listenTo(this.model, 'change:is_starred', this.itemStarred); + this.listenTo(this.model, 'change:starred', this.itemStarred); }, render: function() { var jsonModel = this.model.toJSON(); this.$el.html(this.template(jsonModel)); - if (jsonModel.is_read) { + if (jsonModel.readed) { this.$el.addClass('read'); } if (jsonModel.keep_unread) { @@ -142,7 +142,7 @@ var StoryView = Backbone.View.extend({ }, itemRead: function() { - this.$el.toggleClass("read", this.model.get("is_read")); + this.$el.toggleClass("read", this.model.get("readed")); }, itemOpened: function() { @@ -168,7 +168,7 @@ var StoryView = Backbone.View.extend({ }, itemStarred: function() { - var icon = this.model.get("is_starred") ? "icon-star" : "icon-star-empty"; + var icon = this.model.get("starred") ? "icon-star" : "icon-star-empty"; this.$(".story-starred > i").attr("class", icon); }, @@ -177,7 +177,7 @@ var StoryView = Backbone.View.extend({ var backgroundTab = window.open(this.model.get("permalink")); if (backgroundTab) backgroundTab.blur(); window.focus(); - if (!this.model.get("keep_unread")) this.model.set("is_read", true); + if (!this.model.get("keep_unread")) this.model.set("readed", true); if (this.model.shouldSave()) this.model.save(); } else { this.model.toggle(); @@ -208,7 +208,7 @@ var StoryList = Backbone.Collection.extend({ }, unreadCount: function() { - return this.where({is_read: false}).length; + return this.where({readed: false}).length; }, closeOthers: function(modelToSkip) { diff --git a/app/commands/stories/mark_all_as_read.rb b/app/commands/stories/mark_all_as_read.rb index 21111cdd8..ccefda03e 100644 --- a/app/commands/stories/mark_all_as_read.rb +++ b/app/commands/stories/mark_all_as_read.rb @@ -7,6 +7,6 @@ def initialize(story_ids, repository = StoryRepository) end def mark_as_read - @repo.fetch_by_ids(@story_ids).update_all(is_read: true) + @repo.fetch_by_ids(@story_ids).update_all(readed: true) end end diff --git a/app/commands/stories/mark_as_read.rb b/app/commands/stories/mark_as_read.rb index 270c3a203..9c5c741b8 100644 --- a/app/commands/stories/mark_as_read.rb +++ b/app/commands/stories/mark_as_read.rb @@ -7,6 +7,6 @@ def initialize(story_id, repository = StoryRepository) end def mark_as_read - @repo.fetch(@story_id).update_attributes(is_read: true) + @repo.fetch(@story_id).update_attributes(readed: true) end end diff --git a/app/commands/stories/mark_as_starred.rb b/app/commands/stories/mark_as_starred.rb index 89e219c25..c9204f86a 100644 --- a/app/commands/stories/mark_as_starred.rb +++ b/app/commands/stories/mark_as_starred.rb @@ -7,6 +7,6 @@ def initialize(story_id, repository = StoryRepository) end def mark_as_starred - @repo.fetch(@story_id).update_attributes(is_starred: true) + @repo.fetch(@story_id).update_attributes(starred: true) end end diff --git a/app/commands/stories/mark_as_unread.rb b/app/commands/stories/mark_as_unread.rb index 3e978229a..3b074ad66 100644 --- a/app/commands/stories/mark_as_unread.rb +++ b/app/commands/stories/mark_as_unread.rb @@ -7,6 +7,6 @@ def initialize(story_id, repository = StoryRepository) end def mark_as_unread - @repo.fetch(@story_id).update_attributes(is_read: false) + @repo.fetch(@story_id).update_attributes(readed: false) end end diff --git a/app/commands/stories/mark_as_unstarred.rb b/app/commands/stories/mark_as_unstarred.rb index fdce3909a..88711fd62 100644 --- a/app/commands/stories/mark_as_unstarred.rb +++ b/app/commands/stories/mark_as_unstarred.rb @@ -7,6 +7,6 @@ def initialize(story_id, repository = StoryRepository) end def mark_as_unstarred - @repo.fetch(@story_id).update_attributes(is_starred: false) + @repo.fetch(@story_id).update_attributes(starred: false) end end diff --git a/app/commands/stories/mark_feed_as_read.rb b/app/commands/stories/mark_feed_as_read.rb index 7a7cabbcd..1d2595cb3 100644 --- a/app/commands/stories/mark_feed_as_read.rb +++ b/app/commands/stories/mark_feed_as_read.rb @@ -8,6 +8,6 @@ def initialize(feed_id, timestamp, repository = StoryRepository) end def mark_feed_as_read - @repo.fetch_unread_for_feed_by_timestamp(@feed_id, @timestamp).update_all(is_read: true) + @repo.fetch_unread_for_feed_by_timestamp(@feed_id, @timestamp).update_all(readed: true) end end diff --git a/app/commands/stories/mark_group_as_read.rb b/app/commands/stories/mark_group_as_read.rb index 0c5bd6cf5..c92abf46f 100644 --- a/app/commands/stories/mark_group_as_read.rb +++ b/app/commands/stories/mark_group_as_read.rb @@ -14,9 +14,9 @@ def mark_group_as_read return unless @group_id if [KINDLING_GROUP_ID, SPARKS_GROUP_ID].include?(@group_id.to_i) - @repo.fetch_unread_by_timestamp(@timestamp).update_all(is_read: true) + @repo.fetch_unread_by_timestamp(@timestamp).update_all(readed: true) elsif @group_id.to_i > 0 - @repo.fetch_unread_by_timestamp_and_group(@timestamp, @group_id).update_all(is_read: true) + @repo.fetch_unread_by_timestamp_and_group(@timestamp, @group_id).update_all(readed: true) end end end diff --git a/app/controllers/archived_news_controller.rb b/app/controllers/archived_news_controller.rb index 0128d6110..84fe0aee9 100644 --- a/app/controllers/archived_news_controller.rb +++ b/app/controllers/archived_news_controller.rb @@ -3,7 +3,7 @@ class ArchivedNewsController < ApplicationController def index @read_stories = current_user.stories - .where(is_read: true) + .where(readed: true) .includes(:feed) .order(published: :desc) .page(params[:page]).per(20) diff --git a/app/controllers/feed_controller.rb b/app/controllers/feed_controller.rb index d0e436105..f5e2e191e 100644 --- a/app/controllers/feed_controller.rb +++ b/app/controllers/feed_controller.rb @@ -6,6 +6,6 @@ def show @stories = @feed.stories.order(published: :desc).includes(:feed) - @unread_stories = @stories.where(is_read: false) + @unread_stories = @stories.where(readed: false) end end diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 2a758d28f..f473eb89a 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -2,8 +2,7 @@ class NewsController < ApplicationController def index - @unread_stories = current_user.stories - .where(is_read: false) + @unread_stories = current_user.unreaded_stories .order(published: :desc) .includes(:feed) .page(params[:page]).per(20) diff --git a/app/controllers/starred_news_controller.rb b/app/controllers/starred_news_controller.rb index 6f9a6738c..640b911ec 100644 --- a/app/controllers/starred_news_controller.rb +++ b/app/controllers/starred_news_controller.rb @@ -2,8 +2,7 @@ class StarredNewsController < ApplicationController def index - @starred_stories = current_user.stories - .where(is_starred: true) + @starred_stories = current_user.starred_stories .includes(:feed) .order(published: :desc) .page(params[:page]).per(20) diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 310939a38..86dc5196d 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -5,9 +5,9 @@ def update json_params = JSON.parse(request.body.read, symbolize_names: true) story = StoryRepository.fetch(params[:id]) - story.is_read = !!json_params[:is_read] + story.readed = !!json_params[:readed] story.keep_unread = !!json_params[:keep_unread] - story.is_starred = !!json_params[:is_starred] + story.starred = !!json_params[:starred] StoryRepository.save(story) diff --git a/app/models/feed.rb b/app/models/feed.rb index 4e89188af..2d1444ce6 100644 --- a/app/models/feed.rb +++ b/app/models/feed.rb @@ -9,7 +9,7 @@ class Feed < ApplicationRecord has_many :stories, -> { order('published desc') }, dependent: :destroy - has_many :unread_stories, -> { where(is_read: false).order('published desc') }, class_name: 'Story' + has_many :unread_stories, -> { where(readed: false).order('published desc') }, class_name: 'Story' validates :url, presence: true diff --git a/app/models/story.rb b/app/models/story.rb index d66968bee..20ae7f52d 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -36,8 +36,8 @@ def as_fever_json author: source, html: body, url: permalink, - is_saved: is_starred ? 1 : 0, - is_read: is_read ? 1 : 0, + is_saved: starred ? 1 : 0, + is_read: readed ? 1 : 0, created_on_time: published.to_i } end diff --git a/app/models/user.rb b/app/models/user.rb index b357d428f..9646c9825 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,5 +5,13 @@ class User < ApplicationRecord has_many :stories, through: :feeds + has_many :unreaded_stories, -> { where(readed: false) }, + through: :feeds, + source: :stories + + has_many :starred_stories, -> { where(starred: true) }, + through: :feeds, + source: :stories + has_secure_password end diff --git a/app/repositories/story_repository.rb b/app/repositories/story_repository.rb index f1fcec8c7..c72b70b70 100644 --- a/app/repositories/story_repository.rb +++ b/app/repositories/story_repository.rb @@ -8,8 +8,8 @@ def self.add(entry, feed) title: extract_title(entry), permalink: extract_url(entry, feed), body: extract_content(entry), - is_read: false, - is_starred: false, + readed: false, # TODO: check and remove + starred: false, # TODO: check and remove published: entry.published || Time.now, entry_id: entry.id) end @@ -24,7 +24,7 @@ def self.fetch_by_ids(ids) def self.fetch_unread_by_timestamp(timestamp) timestamp = Time.at(timestamp.to_i) - Story.where("stories.created_at < ?", timestamp).where(is_read: false) + Story.where("stories.created_at < ?", timestamp).where(readed: false) end def self.fetch_unread_by_timestamp_and_group(timestamp, group_id) @@ -33,7 +33,7 @@ def self.fetch_unread_by_timestamp_and_group(timestamp, group_id) def self.fetch_unread_for_feed_by_timestamp(feed_id, timestamp) timestamp = Time.at(timestamp.to_i) - Story.where(feed_id: feed_id).where("created_at < ? AND is_read = ?", timestamp, false) + Story.where(feed_id: feed_id).where("created_at < ? AND readed = ?", timestamp, false) end def self.save(story) @@ -53,16 +53,16 @@ def self.feed(feed_id) end def self.all_starred - Story.where(is_starred: true) + Story.where(starred: true) end def self.unstarred_read_stories_older_than(num_days) - Story.where(is_read: true, is_starred: false) + Story.where(readed: true, starred: false) .where("published <= ?", num_days.days.ago) end def self.read_count - Story.where(is_read: true).count + Story.where(readed: true).count end def self.extract_url(entry, feed) diff --git a/app/utils/sample_story.rb b/app/utils/sample_story.rb index 876312e45..54806d507 100644 --- a/app/utils/sample_story.rb +++ b/app/utils/sample_story.rb @@ -1,4 +1,4 @@ -SampleStory = Struct.new(:source, :title, :lead, :is_read, :published) do +SampleStory = Struct.new(:source, :title, :lead, :readed, :published) do BODY = <<-EOS.freeze
Tofu shoreditch intelligentsia umami, fashion axe photo booth try-hard terry richardson quinoa actually fingerstache meggings fixie. Aesthetic @@ -40,7 +40,7 @@ def body BODY end - def is_read # rubocop:disable Style/PredicateName + def readed # rubocop:disable Style/PredicateName false end @@ -48,7 +48,7 @@ def keep_unread false end - def is_starred # rubocop:disable Style/PredicateName + def starred # rubocop:disable Style/PredicateName false end @@ -66,8 +66,8 @@ def as_json(*) pretty_date: published.strftime("%A, %B %d"), body: body, permalink: permalink, - is_read: is_read, - is_starred: is_starred, + is_read: readed, + is_starred: starred, keep_unread: keep_unread } end diff --git a/app/views/application/_story.js.erb b/app/views/application/_story.js.erb index 731651554..9b9dd4fcf 100644 --- a/app/views/application/_story.js.erb +++ b/app/views/application/_story.js.erb @@ -2,7 +2,7 @@