docbrown/spec/requests/follows_bulk_update_spec.rb
Chien-Wei Huang (Michael) 025a46e012
Update all followed tag with one click (#11454)
* Replace follows#update with follows#bulk_update

* Allow follows#bulk_update to receive multiple follows and remove follows#update

* Add FollowPolicy#bulk_update? and remove update?

* Combine save button into one in following_tag.html

* Rename follows_update_spec to follows_bulk_update_spec and update

* Update buildTagsHTML to conform to the view

* Allow scrolls down dashboard test to update multiple tag values

* Includes follower and followable in follows#bulk_update

* Mark and pass changed field.

* fix typo in html

* Update follows in transaction

* Extract js script to another file and update view

* Rename disableUnchangedButton.js to dashboardTagsDisableUnchangedButtons.js
2021-01-05 16:15:37 +01:00

32 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe "Following/Unfollowing", type: :request do
let(:user) { create(:user) }
let(:user_2) { create(:user) }
let(:tags) { create_list(:tag, 2) }
let(:follow_1) { create(:follow, follower: user, followable: tags[0]) }
let(:follow_2) { create(:follow, follower: user, followable: tags[1]) }
before do
sign_in user
end
describe "PATCH bulk_update" do
let(:params) { [{ id: follow_1.id, explicit_points: 3.0 }, { id: follow_2.id, explicit_points: 10.0 }] }
it "bulk updates follow explicit_points" do
patch "/follows/bulk_update", params: { follows: params }
expect(Follow.find(follow_1.id).explicit_points).to eq(3.0)
expect(Follow.find(follow_1.id).points).to eq(3.0)
expect(Follow.find(follow_2.id).explicit_points).to eq(10.0)
expect(Follow.find(follow_2.id).points).to eq(10.0)
end
it "does not update if follow does not belong to user" do
user_2.follow(tags[0])
expect do
patch "/follows/bulk_update", params: { follows: [{ id: Follow.last.id, explicit_points: 3.0 }] }
end.to raise_error(Pundit::NotAuthorizedError)
end
end
end