docbrown/spec/requests/admin/badges_spec.rb
Julianna Tetreault 24a3b50d4a
Add the Ability to Remove Badge Achievements From Users (#9896) [deploy]
* Moves badge_achievement-related code from /admin/bagdes to /admin/badge_achievements
  - Adds an Admin::BadgeAchievements::Controller
  - Moves #award and #award_badges to Admin::BadgeAchievements::Controller
  - Removes #award and #award_badges from Admin::Badges::Controller
  - Moves award.html.erb from /admin/badges to /admin/badge_achievements
  - Removes badge_achievement routes from /admin/badges
  - Adds a redirect for /admin/badges/badge_achievements to routes.rb
  - Cleans up and refactors code in controllers, views, and routes

* Add more actions to Admin::BadgeAchievements::Controller and matching routes
  - Adds an #index and #destory action to the BadgeAchievements::Controller
  - Adds destroy to the badge_achievements routes
  - Adjusts redirects for badge_achievements in routes.rb
  - Removes dead code from the index view for Badges
  - Refactors the existing code in the index view for BadgeAchievements

* Adds an /admin/badge_achievements_spec and cleans up the /admin/badges_spec
  - Removes the badge_achievement-related tests from badges_spec.rb
  - Adds an additional test around deleting badge_achievements

* Add pagination to badge_achievements index view

* Adds badge_achievements to Admin menu items and add comment to routes.rb
  -Add badge_achievements to the Admin nav bar
  -Add a comment regarding redirects for badge_achievements

* Resolve JS console stacktrace notices and change wording on deletion buttons

* Add a Back to Badge Achievements button to the badge award form

* Adjust styling to fix failing /admin/badges_spec.rb

* Uses SQL paging to optimize scalibility and adds search functionality to index.html.erb
  - Use SQL paging in Admin::BadgeAchievements::Controller in #index and #award
  - Add a search by user ID to Badge Achievements index view
  - Add a limit of 15 badges to be shown on the Badge Achievement index view
  - Add a User ID column to the Badge Achievement index view

* Add Award Badge button back to Badge Achievement index.html.erb

* Change @badge to be more explicit and reword warning around badge deletion

* Adds award badge button back, rewords success message, and adjusts SQL paging
2020-08-25 11:14:47 -06:00

43 lines
1.2 KiB
Ruby

require "rails_helper"
require "requests/shared_examples/internal_policy_dependant_request"
RSpec.describe "/admin/badges", type: :request do
let(:admin) { create(:user, :super_admin) }
let!(:badge) { create(:badge, title: "Not 'Hello, world!'") }
let(:params) do
{
badge: {
title: "Hello, world!",
slug: "greeting-badge",
description: "Awarded to welcoming users",
badge_image: Rack::Test::UploadedFile.new("spec/support/fixtures/images/image1.jpeg", "image/jpeg")
}
}
end
it_behaves_like "an InternalPolicy dependant request", Badge do
let(:request) { get "/admin/badges" }
end
describe "POST /admin/badges" do
let(:post_resource) { post "/admin/badges", params: params }
before { sign_in admin }
it "successfully creates a badge" do
expect do
post_resource
end.to change { Badge.all.count }.by(1)
end
end
describe "PUT /admin/badges" do
before { sign_in admin }
it "successfully updates the badge" do
expect do
patch "/admin/badges/#{badge.id}", params: params
end.to change { badge.reload.title }.to("Hello, world!")
end
end
end