Skip to content

Commit

Permalink
Merge 9090c4a into 9033f42
Browse files Browse the repository at this point in the history
  • Loading branch information
mockdeep committed Feb 22, 2021
2 parents 9033f42 + 9090c4a commit 1f6524b
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/factories/feeds.rb
@@ -0,0 +1,9 @@
module Factories
def create_feed(params = {})
build_feed(params).tap(&:save!)
end

def build_feed(params = {})
Feed.new(**params)
end
end
9 changes: 9 additions & 0 deletions spec/factories/stories.rb
@@ -0,0 +1,9 @@
module Factories
def create_story(params = {})
build_story(params).tap(&:save!)
end

def build_story(params = {})
Story.new(feed: build_feed, **params)
end
end
12 changes: 12 additions & 0 deletions spec/models/group_spec.rb
@@ -0,0 +1,12 @@
require "spec_helper"
require "support/active_record"

RSpec.describe Group do
describe "#as_fever_json" do
it "returns a hash of the group in fever format" do
group = Group.new(id: 5, name: "wat group")

expect(group.as_fever_json).to eq(id: 5, title: "wat group")
end
end
end
83 changes: 83 additions & 0 deletions spec/models/story_spec.rb
Expand Up @@ -46,4 +46,87 @@
expect(story.source).to eq(feed.name)
end
end

describe "#pretty_date" do
it "returns a formatted published date" do
published_at = Time.now
story = Story.new(published: published_at)

expect(story.pretty_date).to eq(I18n.l(published_at))
end

it "raises an error when published is nil" do
story = Story.new

expect { story.pretty_date }.to raise_error(ArgumentError)
end
end

describe "#as_json" do
it "returns a hash of the story" do
feed = create_feed(name: "my feed")
published_at = 1.day.ago
created_at = 1.hour.ago
updated_at = 1.minute.ago
story = create_story(
body: "story body",
created_at: created_at,
entry_id: 5,
feed: feed,
is_read: true,
is_starred: false,
keep_unread: true,
permalink: "www.exampoo.com/perma",
published: published_at,
title: "the story title",
updated_at: updated_at
)

expect(story.as_json).to eq({
body: "story body",
created_at: created_at,
entry_id: "5",
feed_id: feed.id,
headline: "the story title",
id: story.id,
is_read: true,
is_starred: false,
keep_unread: true,
lead: "story body",
permalink: "www.exampoo.com/perma",
pretty_date: I18n.l(published_at),
published: published_at,
source: "my feed",
title: "the story title",
updated_at: updated_at
}.stringify_keys)
end
end

describe "#as_fever_json" do
it "returns a hash of the story in fever format" do
feed = create_feed(name: "my feed")
published_at = 1.day.ago
story = create_story(
feed: feed,
title: "the story title",
body: "story body",
permalink: "www.exampoo.com/perma",
published: published_at,
is_read: true
)

expect(story.as_fever_json).to eq(
id: story.id,
feed_id: feed.id,
title: "the story title",
author: "my feed",
html: "story body",
url: "www.exampoo.com/perma",
is_saved: 0,
is_read: 1,
created_on_time: published_at.to_i
)
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -13,6 +13,8 @@
require "factories/story_factory"
require "factories/user_factory"
require "factories/group_factory"
require "factories/feeds"
require "factories/stories"
require "factories/users"

require "./app"
Expand Down

0 comments on commit 1f6524b

Please sign in to comment.