forked from forem/forem
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove controller specs (forem#2224)
* Create more request specs * Update wording * Update guard to work with requests * Fix broken spec * Remove rails-controller-testing gem * Move article_specs * Move last controller spec out * Remove controller spec config * Fix broken spec * Remove all use of render_template * Refactor spec * Tweak User#remember_me * Create ArticleAnalyticFetcher spec * Undo User#remember_me * Use srand in rspec * Create FeedbackMessagesHelper spec * Add DigestMailer spec * Fix broken test
- Loading branch information
1 parent
b22b3e3
commit 73127ac
Showing
18 changed files
with
150 additions
and
67 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
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
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
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
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
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,21 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe FeedbackMessagesHelper, type: :helper do | ||
describe "#offender_email_details" do | ||
it "have proper subject and body" do | ||
expect(helper.offender_email_details).to include(subject: "DEV Code of Conduct Violation", body: a_string_starting_with("Hi")) | ||
end | ||
end | ||
|
||
describe "#reporter_email_details" do | ||
it "have proper subject and body" do | ||
expect(helper.reporter_email_details).to include(subject: "DEV Report", body: a_string_starting_with("Hi")) | ||
end | ||
end | ||
|
||
describe "#affected_email_details" do | ||
it "have proper subject and body" do | ||
expect(helper.affected_email_details).to include(subject: "Courtesy Notice from DEV", body: a_string_starting_with("Hi")) | ||
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,47 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe ArticleAnalyticsFetcher do | ||
let(:stubbed_ga) { double } | ||
|
||
before do | ||
srand(2) # disabling #occasionally_force_fetch | ||
allow(Notification).to receive(:send_milestone_notification) | ||
allow(GoogleAnalytics).to receive(:new).and_return(stubbed_ga) | ||
end | ||
|
||
describe "#update_analytics" do | ||
context "when positive_reactions_count is LOWER than previous_positive_reactions_count" do | ||
it "does nothing " do | ||
article = build_stubbed(:article, positive_reactions_count: 2, previous_positive_reactions_count: 3) | ||
allow(Article).to receive(:where).and_return([article]) | ||
described_class.new.update_analytics(1) | ||
expect(Notification).not_to have_received(:send_milestone_notification) | ||
end | ||
end | ||
|
||
context "when positive_reactions_count is HIGHER than previous_positive_reactions_count" do | ||
let(:article) { build_stubbed(:article, positive_reactions_count: 5, previous_positive_reactions_count: 3) } | ||
let(:pageview) { {} } | ||
let(:counts) { 1000 } | ||
|
||
before do | ||
pageview[article.id] = counts | ||
allow(stubbed_ga).to receive(:get_pageviews).and_return(pageview) | ||
allow(article).to receive(:update_columns) | ||
allow(Article).to receive(:where).and_return([article]) | ||
described_class.new.update_analytics(1) | ||
end | ||
|
||
it "sends send_milestone_notification for Reaction and View" do | ||
%w[Reaction View].each do |type| | ||
expect(Notification).to have_received(:send_milestone_notification).with(type: type, article: article) | ||
end | ||
end | ||
|
||
it "updates appropriate column" do | ||
expect(article).to have_received(:update_columns).with(previous_positive_reactions_count: article.positive_reactions_count) | ||
expect(article).to have_received(:update_columns).with(page_views_count: counts) | ||
end | ||
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,16 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe DigestMailer, type: :mailer do | ||
describe "#digest_email" do | ||
it "works correctly" do | ||
user = build_stubbed(:user) | ||
article = build_stubbed(:article) | ||
allow(article).to receive(:title).and_return("test title") | ||
email = described_class.digest_email(user, [article]) | ||
|
||
expect(email.subject).not_to be_nil | ||
expect(email.to).to eq([user.email]) | ||
expect(email.from).to eq(["[email protected]"]) | ||
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
2 changes: 1 addition & 1 deletion
2
spec/requests/articles_api_spec.rb → spec/requests/api/v0/articles_spec.rb
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
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
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
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
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
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
2 changes: 1 addition & 1 deletion
2
...rollers/internal_users_controller_spec.rb → spec/requests/internal/users_spec.rb
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
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,27 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Notifications::Reads", type: :request do | ||
describe "POST /notifications/reads" do | ||
let(:stubbed_service_object) { double } | ||
let(:user) { create(:user) } | ||
|
||
before do | ||
sign_in user | ||
allow(ReadNotificationsService).to receive(:new).and_return(stubbed_service_object) | ||
allow(stubbed_service_object).to receive(:mark_as_read) | ||
end | ||
|
||
it "marks notifications as read" do | ||
post "/notifications/reads/" | ||
expect(response).to have_http_status(:ok) | ||
expect(stubbed_service_object).to have_received(:mark_as_read).once | ||
end | ||
|
||
it "marks personal and org Notifications as read" do | ||
allow(user).to receive(:organization_id).and_return(1) | ||
post "/notifications/reads/", params: { org_id: 1 } | ||
expect(response).to have_http_status(:ok) | ||
expect(stubbed_service_object).to have_received(:mark_as_read).twice | ||
end | ||
end | ||
end |
Oops, something went wrong.