Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ RSpec/ExampleLength:
- 'spec/models/story_spec.rb'
- 'spec/repositories/group_repository_spec.rb'
- 'spec/repositories/story_repository_spec.rb'
- 'spec/system/add_feed_spec.rb'
- 'spec/system/good_job_spec.rb'
- 'spec/tasks/remove_old_stories_spec.rb'
- 'spec/utils/feed_discovery_spec.rb'
Expand Down Expand Up @@ -161,6 +162,7 @@ RSpec/MultipleExpectations:
- 'spec/commands/feed/import_from_opml_spec.rb'
- 'spec/repositories/feed_repository_spec.rb'
- 'spec/repositories/story_repository_spec.rb'
- 'spec/system/add_feed_spec.rb'
- 'spec/tasks/remove_old_stories_spec.rb'
- 'spec/utils/feed_discovery_spec.rb'
- 'spec/utils/i18n_support_spec.rb'
Expand Down
2 changes: 1 addition & 1 deletion app/views/feeds/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="form-group">
<input name="feed_url" class="form-control" id="feed-url" type="text" value="<%= @feed_url %>" autofocus/>
<i class="fa fa-rss field-icon"></i>
<label id="feed_url-label" class="field-label" for="feed_url"><%= t('feeds.add.fields.feed_url') %></label>
<label id="feed_url-label" class="field-label" for="feed-url"><%= t('feeds.add.fields.feed_url') %></label>
</div>

<input type="submit" id="submit" class="btn btn-primary pull-right" value="<%= t('feeds.add.fields.submit') %>"/>
Expand Down
44 changes: 44 additions & 0 deletions spec/system/add_feed_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

RSpec.describe "adding a feed" do
def stub_discovery(url:, title: "My Feed")
feed = instance_double(Feedjira::Parser::Atom, title:, feed_url: url)
expect(FeedDiscovery).to receive(:call).with(url).and_return(feed)
end

def submit_feed(url)
visit(feeds_new_path)
fill_in("Feed URL", with: url)
click_on("Add")
end

it "allows adding a new feed" do
login_as(default_user)
stub_discovery(url: "http://example.com/feed.xml")
expect(CallableJob).to receive(:perform_later)

submit_feed("http://example.com/feed.xml")

expect(page).to have_content("We've added your new feed")
end

it "shows an error when the feed is not found" do
login_as(default_user)
expect(FeedDiscovery).to receive(:call).and_return(false)

submit_feed("http://example.com/bad")

expect(page).to have_content("We couldn't find that feed")
end

it "shows an error when already subscribed" do
login_as(default_user)
url = "http://example.com/feed.xml"
stub_discovery(url:)
create(:feed, url:, user: default_user)

submit_feed(url)

expect(page).to have_content("You are already subscribed")
end
end
34 changes: 34 additions & 0 deletions spec/system/login_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

RSpec.describe "login" do
def submit_login(username:, password:)
visit("/")
fill_in("Username", with: username)
fill_in("Password", with: password)
click_on("Login")
end

it "allows a user to log in" do
user = create(:user)

submit_login(username: user.username, password: user.password)

expect(page).to have_content("Logged in as #{user.username}")
end

it "shows an error for wrong password" do
user = create(:user)

submit_login(username: user.username, password: "wrong-password")

expect(page).to have_content("That's the wrong password")
end

it "allows a user to log out" do
login_as(default_user)

click_on("Logout")

expect(page).to have_content("You have been signed out!")
end
end