mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
DEV: Apply syntax_tree formatting to spec/*
This commit is contained in:
@ -17,21 +17,21 @@ RSpec.describe Admin::DashboardController do
|
||||
"emoji" => "🤾",
|
||||
"title" => "Cool Beans",
|
||||
"description" => "Now beans are included",
|
||||
"created_at" => date1 || (Time.zone.now - 40.minutes)
|
||||
"created_at" => date1 || (Time.zone.now - 40.minutes),
|
||||
},
|
||||
{
|
||||
"id" => "2",
|
||||
"emoji" => "🙈",
|
||||
"title" => "Fancy Legumes",
|
||||
"description" => "Legumes too!",
|
||||
"created_at" => date2 || (Time.zone.now - 20.minutes)
|
||||
}
|
||||
"created_at" => date2 || (Time.zone.now - 20.minutes),
|
||||
},
|
||||
]
|
||||
|
||||
Discourse.redis.set('new_features', MultiJson.dump(sample_features))
|
||||
Discourse.redis.set("new_features", MultiJson.dump(sample_features))
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
describe "#index" do
|
||||
shared_examples "version info present" do
|
||||
it "returns discourse version info" do
|
||||
get "/admin/dashboard.json"
|
||||
@ -42,9 +42,7 @@ RSpec.describe Admin::DashboardController do
|
||||
end
|
||||
|
||||
shared_examples "version info absent" do
|
||||
before do
|
||||
SiteSetting.version_checks = false
|
||||
end
|
||||
before { SiteSetting.version_checks = false }
|
||||
|
||||
it "does not return discourse version info" do
|
||||
get "/admin/dashboard.json"
|
||||
@ -59,17 +57,13 @@ RSpec.describe Admin::DashboardController do
|
||||
before { sign_in(admin) }
|
||||
|
||||
context "when version checking is enabled" do
|
||||
before do
|
||||
SiteSetting.version_checks = true
|
||||
end
|
||||
before { SiteSetting.version_checks = true }
|
||||
|
||||
include_examples "version info present"
|
||||
end
|
||||
|
||||
context "when version checking is disabled" do
|
||||
before do
|
||||
SiteSetting.version_checks = false
|
||||
end
|
||||
before { SiteSetting.version_checks = false }
|
||||
|
||||
include_examples "version info absent"
|
||||
end
|
||||
@ -79,24 +73,20 @@ RSpec.describe Admin::DashboardController do
|
||||
before { sign_in(moderator) }
|
||||
|
||||
context "when version checking is enabled" do
|
||||
before do
|
||||
SiteSetting.version_checks = true
|
||||
end
|
||||
before { SiteSetting.version_checks = true }
|
||||
|
||||
include_examples "version info present"
|
||||
end
|
||||
|
||||
context "when version checking is disabled" do
|
||||
before do
|
||||
SiteSetting.version_checks = false
|
||||
end
|
||||
before { SiteSetting.version_checks = false }
|
||||
|
||||
include_examples "version info absent"
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in as a non-staff user" do
|
||||
before { sign_in(user) }
|
||||
before { sign_in(user) }
|
||||
|
||||
it "denies access with a 404 response" do
|
||||
get "/admin/dashboard.json"
|
||||
@ -107,36 +97,34 @@ RSpec.describe Admin::DashboardController do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#problems' do
|
||||
describe "#problems" do
|
||||
context "when logged in as an admin" do
|
||||
before { sign_in(admin) }
|
||||
|
||||
context 'when there are no problems' do
|
||||
before do
|
||||
AdminDashboardData.stubs(:fetch_problems).returns([])
|
||||
end
|
||||
context "when there are no problems" do
|
||||
before { AdminDashboardData.stubs(:fetch_problems).returns([]) }
|
||||
|
||||
it 'returns an empty array' do
|
||||
it "returns an empty array" do
|
||||
get "/admin/dashboard/problems.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = response.parsed_body
|
||||
expect(json['problems'].size).to eq(0)
|
||||
expect(json["problems"].size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are problems' do
|
||||
context "when there are problems" do
|
||||
before do
|
||||
AdminDashboardData.stubs(:fetch_problems).returns(['Not enough awesome', 'Too much sass'])
|
||||
AdminDashboardData.stubs(:fetch_problems).returns(["Not enough awesome", "Too much sass"])
|
||||
end
|
||||
|
||||
it 'returns an array of strings' do
|
||||
it "returns an array of strings" do
|
||||
get "/admin/dashboard/problems.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = response.parsed_body
|
||||
expect(json['problems'].size).to eq(2)
|
||||
expect(json['problems'][0]).to be_a(String)
|
||||
expect(json['problems'][1]).to be_a(String)
|
||||
expect(json["problems"].size).to eq(2)
|
||||
expect(json["problems"][0]).to be_a(String)
|
||||
expect(json["problems"][1]).to be_a(String)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -144,23 +132,21 @@ RSpec.describe Admin::DashboardController do
|
||||
context "when logged in as a moderator" do
|
||||
before do
|
||||
sign_in(moderator)
|
||||
AdminDashboardData
|
||||
.stubs(:fetch_problems)
|
||||
.returns(['Not enough awesome', 'Too much sass'])
|
||||
AdminDashboardData.stubs(:fetch_problems).returns(["Not enough awesome", "Too much sass"])
|
||||
end
|
||||
|
||||
it 'returns a list of problems' do
|
||||
it "returns a list of problems" do
|
||||
get "/admin/dashboard/problems.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
json = response.parsed_body
|
||||
expect(json['problems'].size).to eq(2)
|
||||
expect(json['problems']).to contain_exactly('Not enough awesome', 'Too much sass')
|
||||
expect(json["problems"].size).to eq(2)
|
||||
expect(json["problems"]).to contain_exactly("Not enough awesome", "Too much sass")
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in as a non-staff user" do
|
||||
before { sign_in(user) }
|
||||
before { sign_in(user) }
|
||||
|
||||
it "denies access with a 404 response" do
|
||||
get "/admin/dashboard/problems.json"
|
||||
@ -171,45 +157,41 @@ RSpec.describe Admin::DashboardController do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#new_features' do
|
||||
after do
|
||||
DiscourseUpdates.clean_state
|
||||
end
|
||||
describe "#new_features" do
|
||||
after { DiscourseUpdates.clean_state }
|
||||
|
||||
context "when logged in as an admin" do
|
||||
before do
|
||||
sign_in(admin)
|
||||
end
|
||||
before { sign_in(admin) }
|
||||
|
||||
it 'is empty by default' do
|
||||
it "is empty by default" do
|
||||
get "/admin/dashboard/new-features.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = response.parsed_body
|
||||
expect(json['new_features']).to eq(nil)
|
||||
expect(json["new_features"]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'fails gracefully for invalid JSON' do
|
||||
it "fails gracefully for invalid JSON" do
|
||||
Discourse.redis.set("new_features", "INVALID JSON")
|
||||
get "/admin/dashboard/new-features.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = response.parsed_body
|
||||
expect(json['new_features']).to eq(nil)
|
||||
expect(json["new_features"]).to eq(nil)
|
||||
end
|
||||
|
||||
it 'includes new features when available' do
|
||||
it "includes new features when available" do
|
||||
populate_new_features
|
||||
|
||||
get "/admin/dashboard/new-features.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = response.parsed_body
|
||||
|
||||
expect(json['new_features'].length).to eq(2)
|
||||
expect(json['new_features'][0]["emoji"]).to eq("🙈")
|
||||
expect(json['new_features'][0]["title"]).to eq("Fancy Legumes")
|
||||
expect(json['has_unseen_features']).to eq(true)
|
||||
expect(json["new_features"].length).to eq(2)
|
||||
expect(json["new_features"][0]["emoji"]).to eq("🙈")
|
||||
expect(json["new_features"][0]["title"]).to eq("Fancy Legumes")
|
||||
expect(json["has_unseen_features"]).to eq(true)
|
||||
end
|
||||
|
||||
it 'passes unseen feature state' do
|
||||
it "passes unseen feature state" do
|
||||
populate_new_features
|
||||
DiscourseUpdates.mark_new_features_as_seen(admin.id)
|
||||
|
||||
@ -217,7 +199,7 @@ RSpec.describe Admin::DashboardController do
|
||||
expect(response.status).to eq(200)
|
||||
json = response.parsed_body
|
||||
|
||||
expect(json['has_unseen_features']).to eq(false)
|
||||
expect(json["has_unseen_features"]).to eq(false)
|
||||
end
|
||||
|
||||
it "sets/bumps the last viewed feature date for the admin" do
|
||||
@ -229,14 +211,18 @@ RSpec.describe Admin::DashboardController do
|
||||
|
||||
get "/admin/dashboard/new-features.json"
|
||||
expect(response.status).to eq(200)
|
||||
expect(DiscourseUpdates.get_last_viewed_feature_date(admin.id)).to be_within_one_second_of(date2)
|
||||
expect(DiscourseUpdates.get_last_viewed_feature_date(admin.id)).to be_within_one_second_of(
|
||||
date2,
|
||||
)
|
||||
|
||||
date2 = 10.minutes.ago
|
||||
populate_new_features(date1, date2)
|
||||
|
||||
get "/admin/dashboard/new-features.json"
|
||||
expect(response.status).to eq(200)
|
||||
expect(DiscourseUpdates.get_last_viewed_feature_date(admin.id)).to be_within_one_second_of(date2)
|
||||
expect(DiscourseUpdates.get_last_viewed_feature_date(admin.id)).to be_within_one_second_of(
|
||||
date2,
|
||||
)
|
||||
end
|
||||
|
||||
it "doesn't error when there are no new features" do
|
||||
@ -248,17 +234,17 @@ RSpec.describe Admin::DashboardController do
|
||||
context "when logged in as a moderator" do
|
||||
before { sign_in(moderator) }
|
||||
|
||||
it 'includes new features when available' do
|
||||
it "includes new features when available" do
|
||||
populate_new_features
|
||||
|
||||
get "/admin/dashboard/new-features.json"
|
||||
|
||||
json = response.parsed_body
|
||||
|
||||
expect(json['new_features'].length).to eq(2)
|
||||
expect(json['new_features'][0]["emoji"]).to eq("🙈")
|
||||
expect(json['new_features'][0]["title"]).to eq("Fancy Legumes")
|
||||
expect(json['has_unseen_features']).to eq(true)
|
||||
expect(json["new_features"].length).to eq(2)
|
||||
expect(json["new_features"][0]["emoji"]).to eq("🙈")
|
||||
expect(json["new_features"][0]["title"]).to eq("Fancy Legumes")
|
||||
expect(json["has_unseen_features"]).to eq(true)
|
||||
end
|
||||
|
||||
it "doesn't set last viewed feature date for moderators" do
|
||||
@ -284,15 +270,13 @@ RSpec.describe Admin::DashboardController do
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mark_new_features_as_seen' do
|
||||
after do
|
||||
DiscourseUpdates.clean_state
|
||||
end
|
||||
describe "#mark_new_features_as_seen" do
|
||||
after { DiscourseUpdates.clean_state }
|
||||
|
||||
context "when logged in as an admin" do
|
||||
before { sign_in(admin) }
|
||||
|
||||
it 'resets last seen for a given user' do
|
||||
it "resets last seen for a given user" do
|
||||
populate_new_features
|
||||
put "/admin/dashboard/mark-new-features-as-seen.json"
|
||||
|
||||
|
Reference in New Issue
Block a user