REFACTOR: admin user fields controller specs to requests (#5961)
This commit is contained in:
parent
4c8939d530
commit
bf8d392a51
|
@ -1,20 +1,23 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Admin::UserFieldsController do
|
||||
|
||||
it "is a subclass of AdminController" do
|
||||
expect(Admin::UserFieldsController < Admin::AdminController).to eq(true)
|
||||
end
|
||||
|
||||
context "when logged in" do
|
||||
let!(:user) { log_in(:admin) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
context '.create' do
|
||||
before do
|
||||
sign_in(admin)
|
||||
end
|
||||
|
||||
describe '#create' do
|
||||
it "creates a user field" do
|
||||
expect {
|
||||
post :create, params: {
|
||||
post "/admin/customize/user_fields.json", params: {
|
||||
user_field: { name: 'hello', description: 'hello desc', field_type: 'text' }
|
||||
}, format: :json
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
}.to change(UserField, :count).by(1)
|
||||
|
@ -22,14 +25,14 @@ describe Admin::UserFieldsController do
|
|||
|
||||
it "creates a user field with options" do
|
||||
expect do
|
||||
post :create, params: {
|
||||
post "/admin/customize/user_fields.json", params: {
|
||||
user_field: {
|
||||
name: 'hello',
|
||||
description: 'hello desc',
|
||||
field_type: 'dropdown',
|
||||
options: ['a', 'b', 'c']
|
||||
}
|
||||
}, format: :json
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
end.to change(UserField, :count).by(1)
|
||||
|
@ -38,36 +41,35 @@ describe Admin::UserFieldsController do
|
|||
end
|
||||
end
|
||||
|
||||
context '.index' do
|
||||
describe '#index' do
|
||||
let!(:user_field) { Fabricate(:user_field) }
|
||||
|
||||
it "returns a list of user fields" do
|
||||
get :index, format: :json
|
||||
get "/admin/customize/user_fields.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = ::JSON.parse(response.body)
|
||||
expect(json['user_fields']).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
context '.destroy' do
|
||||
describe '#destroy' do
|
||||
let!(:user_field) { Fabricate(:user_field) }
|
||||
|
||||
it "deletes the user field" do
|
||||
expect {
|
||||
delete :destroy, params: { id: user_field.id }, format: :json
|
||||
delete "/admin/customize/user_fields/#{user_field.id}.json"
|
||||
expect(response.status).to eq(200)
|
||||
}.to change(UserField, :count).by(-1)
|
||||
end
|
||||
end
|
||||
|
||||
context '.update' do
|
||||
describe '#update' do
|
||||
let!(:user_field) { Fabricate(:user_field) }
|
||||
|
||||
it "updates the user field" do
|
||||
put :update, params: {
|
||||
id: user_field.id,
|
||||
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
|
||||
user_field: { name: 'fraggle', field_type: 'confirm', description: 'muppet' }
|
||||
}, format: :json
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
user_field.reload
|
||||
|
@ -76,15 +78,14 @@ describe Admin::UserFieldsController do
|
|||
end
|
||||
|
||||
it "updates the user field options" do
|
||||
put :update, params: {
|
||||
id: user_field.id,
|
||||
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
|
||||
user_field: {
|
||||
name: 'fraggle',
|
||||
field_type: 'dropdown',
|
||||
description: 'muppet',
|
||||
options: ['hello', 'hello', 'world']
|
||||
}
|
||||
}, format: :json
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
user_field.reload
|
||||
|
@ -94,8 +95,7 @@ describe Admin::UserFieldsController do
|
|||
end
|
||||
|
||||
it "keeps options when updating the user field" do
|
||||
put :update, params: {
|
||||
id: user_field.id,
|
||||
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
|
||||
user_field: {
|
||||
name: 'fraggle',
|
||||
field_type: 'dropdown',
|
||||
|
@ -103,21 +103,20 @@ describe Admin::UserFieldsController do
|
|||
options: ['hello', 'hello', 'world'],
|
||||
position: 1
|
||||
}
|
||||
}, format: :json
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
user_field.reload
|
||||
expect(user_field.user_field_options.size).to eq(2)
|
||||
|
||||
put :update, params: {
|
||||
id: user_field.id,
|
||||
put "/admin/customize/user_fields/#{user_field.id}.json", params: {
|
||||
user_field: {
|
||||
name: 'fraggle',
|
||||
field_type: 'dropdown',
|
||||
description: 'muppet',
|
||||
position: 2
|
||||
}
|
||||
}, format: :json
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
user_field.reload
|
||||
|
@ -125,5 +124,4 @@ describe Admin::UserFieldsController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue