-
Notifications
You must be signed in to change notification settings - Fork 650
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe DiscouragedArticlesController, type: :controller do | ||
describe 'GET #category_member?' do | ||
it 'returns true when a category member exists' do | ||
FactoryBot.create(:wikipedia_category_member, category_member: 'Example Article') | ||
get :category_member?, params: { article_title: 'Example Article' } | ||
expect(response).to have_http_status(:success) | ||
expect(JSON.parse(response.body)['is_category_member']).to be_truthy | ||
end | ||
|
||
it 'returns false when a category member does not exist' do | ||
get :category_member?, params: { article_title: 'Nonexistent Article' } | ||
expect(response).to have_http_status(:success) | ||
expect(JSON.parse(response.body)['is_category_member']).to be_falsey | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :wikipedia_category_member do | ||
category_members { "MyText" } | ||
category_member { 'Example Category Member' } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe WikipediaCategoryMember, type: :model do | ||
pending "add some examples to (or delete) #{__FILE__}" | ||
describe '#fetch_category_members' do | ||
it 'fetches and saves category members' do | ||
response = instance_double('response', status: 200, | ||
data: { 'categorymembers' => [{ 'title' => 'Member 1' }, { 'title' => 'Member 2' }] }) | ||
|
||
wiki_api = instance_double('wiki_api', query: response) | ||
allow(WikiApi).to receive(:new).and_return(wiki_api) | ||
|
||
described_class.create(category_member: 'Member 2') | ||
described_class.create(category_member: 'Member 3') | ||
|
||
subject.fetch_category_members | ||
|
||
expect(described_class.pluck(:category_member)).to contain_exactly('Member 1', 'Member 2') | ||
|
||
expect(described_class.find_by(category_member: 'Member 3')).to be_nil | ||
end | ||
|
||
it 'logs a warning on API failure' do | ||
response = instance_double('response', status: 500) | ||
|
||
wiki_api = instance_double('wiki_api', query: response) | ||
allow(WikiApi).to receive(:new).and_return(wiki_api) | ||
|
||
expect(Rails.logger).to receive(:warn).with('Failed to fetch categorymembers data') | ||
|
||
subject.fetch_category_members | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'sidekiq/testing' | ||
|
||
Sidekiq::Testing.fake! | ||
|
||
RSpec.describe UpdateWikipediaCategoryWorker, type: :worker do | ||
it 'fetches and saves Wikipedia category members' do | ||
allow_any_instance_of(WikipediaCategoryMember).to receive(:fetch_category_members) | ||
|
||
expect do | ||
described_class.perform_async | ||
end.to change(described_class.jobs, :size).by(1) | ||
|
||
described_class.drain | ||
end | ||
end |