diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 63b2a0cef..e9ccb8b0d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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' @@ -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' diff --git a/app/views/feeds/new.html.erb b/app/views/feeds/new.html.erb index 9080fa853..bc717256e 100644 --- a/app/views/feeds/new.html.erb +++ b/app/views/feeds/new.html.erb @@ -11,7 +11,7 @@
- +
diff --git a/spec/system/add_feed_spec.rb b/spec/system/add_feed_spec.rb new file mode 100644 index 000000000..e25bc660f --- /dev/null +++ b/spec/system/add_feed_spec.rb @@ -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 diff --git a/spec/system/login_spec.rb b/spec/system/login_spec.rb new file mode 100644 index 000000000..01b3b38a5 --- /dev/null +++ b/spec/system/login_spec.rb @@ -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