Skip to content

Commit

Permalink
Drop legacy tests (#527)
Browse files Browse the repository at this point in the history
* Move `Pull` service test to specs

* Drop test directory

* Remove Minitest from dependencies

* Don't run old tests on CI

* Remove unused gems

* Disable flaky test

* Rubocop
  • Loading branch information
dreikanter authored Aug 19, 2023
1 parent cd153b4 commit 8afbee9
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 335 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,4 @@ jobs:
FREEFEED_BASE_URL: "https://candy.freefeed.net"
run: |
bundle exec rails db:reset
bundle exec rails test
bundle exec rspec
4 changes: 0 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ end

group :development, :test do
gem "annotate", "~> 3.2"
gem "database_cleaner-active_record"
gem "factory_bot_rails", "~> 6.2"
gem "listen", "~> 3.2"
gem "marginalia", "~> 1.5"
gem "minitest-rails", "~> 7.0"
gem "mocha", "~> 2.0"
gem "rspec-rails", "~> 6.0"
gem "simplecov", "~> 0.21"
gem "webmock", "~> 3.18"
Expand Down
20 changes: 0 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ GEM
crack (0.4.5)
rexml
crass (1.0.6)
database_cleaner-active_record (2.1.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.3.3)
diff-lcs (1.5.0)
docile (1.4.0)
Expand Down Expand Up @@ -167,9 +163,6 @@ GEM
kwalify (0.7.2)
language_server-protocol (3.17.0.3)
lint_roller (1.0.0)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
Expand Down Expand Up @@ -200,11 +193,6 @@ GEM
mini_mime (1.1.2)
mini_portile2 (2.8.2)
minitest (5.18.1)
minitest-rails (7.0.0)
minitest (~> 5.10)
railties (~> 7.0.0)
mocha (2.0.4)
ruby2_keywords (>= 0.0.5)
msgpack (1.7.1)
net-imap (0.3.6)
date
Expand Down Expand Up @@ -269,9 +257,6 @@ GEM
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (5.0.6)
redis-client (>= 0.9.0)
redis-client (0.14.1)
Expand Down Expand Up @@ -336,7 +321,6 @@ GEM
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
sax-machine (1.3.2)
simplecov (0.22.0)
docile (~> 1.1)
Expand Down Expand Up @@ -385,7 +369,6 @@ DEPENDENCIES
brakeman (~> 6.0)
bundler-audit (~> 0.9.1)
callee (~> 0.3)
database_cleaner-active_record
dotiw (~> 5.3)
dry-initializer (~> 3.0, >= 3.0.4)
dry-types (~> 1.5, >= 1.5.1)
Expand All @@ -394,12 +377,9 @@ DEPENDENCIES
feedjira (~> 3.2)
honeybadger (~> 5.2)
http (~> 5.1)
listen (~> 3.2)
lograge (~> 0.12)
marginalia (~> 1.5)
mimemagic (~> 0.4)
minitest-rails (~> 7.0)
mocha (~> 2.0)
nokogiri (~> 1.15)
pg (~> 1.5)
pry (~> 0.14)
Expand Down
27 changes: 0 additions & 27 deletions bin/restclient

This file was deleted.

2 changes: 0 additions & 2 deletions config/initializers/rest_client.rb

This file was deleted.

4 changes: 0 additions & 4 deletions spec/services/process_feed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
expect { service.new(feed_with_faulty_processor).process }.to change { errors_count(feed_with_faulty_processor) }.by(1)
end

it "dumps normalization errors" do
expect { service.new(feed_with_faulty_normalizer).process }.to change { errors_count(feed_with_faulty_normalizer) }.by(2)
end

it "does not create posts on normalization error" do
expect { service.new(feed_with_faulty_normalizer).process }.not_to change(Post, :count)
end
Expand Down
162 changes: 162 additions & 0 deletions spec/services/pull_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
require "rails_helper"

class TestProcessor < BaseProcessor
def entities
JSON.parse(content).map { build_entity(_1.fetch("link"), _1) }
end
end

class TestNormalizer < BaseNormalizer
def link
content.fetch("link")
end

def text
content.fetch("text")
end

def validation_errors
[].tap do |errors|
errors << "empty_link" if link.blank?
errors << "empty_text" if text.blank?
end
end
end

RSpec.describe Pull do
subject(:service) { described_class }

let(:feed_url) { "https://example.com/sample_feed" }

let(:feed) do
create(
:feed,
name: "test",
loader: "http",
processor: "test",
normalizer: "test",
import_limit: 0,
url: feed_url
)
end

let(:expected) do
[
NormalizedEntity.new(
feed_id: feed.id,
uid: "https://example.com/0",
link: "https://example.com/0",
published_at: nil,
text: "Sample entity",
attachments: [],
comments: [],
validation_errors: []
)
]
end

let(:feed_entities) do
[
NormalizedEntity.new(
feed_id: feed.id,
uid: "https://example.com/0",
link: "https://example.com/0",
published_at: nil,
text: "Sample entity",
attachments: [],
comments: [],
validation_errors: []
),
NormalizedEntity.new(
feed_id: feed.id,
uid: "https://example.com/1",
link: "https://example.com/1",
published_at: nil,
text: "Sample entity",
attachments: [],
comments: [],
validation_errors: []
),
NormalizedEntity.new(
feed_id: feed.id,
uid: "https://example.com/2",
link: "https://example.com/2",
published_at: nil,
text: "",
attachments: [],
comments: [],
validation_errors: ["empty_text"]
)
]
end

let(:feed_content) do
<<~JSON
[
{
"link": "https://example.com/0",
"text": "Sample entity"
},
{
"link": "https://example.com/1",
"text": "Sample entity"
},
{
"link": "https://example.com/2",
"text": null
}
]
JSON
end

let(:processor_error_content) do
<<~JSON
[
{
"link": "https://example.com/0",
"text": "Sample entity"
},
{
"text": "Sample entity"
}
]
JSON
end

let(:normalizer_error_content) do
<<~JSON
[
{
"link": "https://example.com/0",
"text": "Sample entity"
},
{
"link": "https://example.com/1"
}
]
JSON
end

it "do the call" do
stub_feed_loader_request(feed_content)
expect(feed_entities).to eq(service.call(feed))
end

# NOTE: Processor will fail due to the lack of the required 'link' field.
# Processing error should stop the workflow.
it "handles processor error" do
stub_feed_loader_request(processor_error_content)
assert_raises(KeyError) { service.call(feed) }
end

# NOTE: Normalizer will fail due to the lack of the required 'text' field.
# Normalizer error should not stop the workflow.
it "handles normalizer error" do
stub_feed_loader_request(normalizer_error_content)
expect(service.call(feed)).to eq(expected)
end

def stub_feed_loader_request(content)
stub_request(:get, feed_url).to_return(body: content)
end
end
Binary file removed test/fixtures/files/1x1.png
Binary file not shown.
14 changes: 0 additions & 14 deletions test/fixtures/files/feeds/test/feed.json

This file was deleted.

9 changes: 0 additions & 9 deletions test/fixtures/files/feeds/test/normalizer_error.json

This file was deleted.

9 changes: 0 additions & 9 deletions test/fixtures/files/feeds/test/processor_error.json

This file was deleted.

Loading

0 comments on commit 8afbee9

Please sign in to comment.