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