Fix all the errors to get our tests green on Rails 5.1.

This commit is contained in:
Guo Xiang Tan
2017-08-31 12:06:56 +08:00
parent 898ee93547
commit 77d4c4d8dc
989 changed files with 5114 additions and 3117 deletions

View File

@ -15,14 +15,15 @@ describe Admin::ThemesController do
render_views
let(:upload) do
ActionDispatch::Http::UploadedFile.new(filename: 'test.woff2',
tempfile: file_from_fixtures("fake.woff2", "woff2"))
Rack::Test::UploadedFile.new(file_from_fixtures("fake.woff2", "woff2"))
end
it 'can create a theme upload' do
xhr :post, :upload_asset, file: upload
post :upload_asset, params: { file: upload }, format: :json
expect(response.status).to eq(201)
upload = Upload.find_by(original_filename: "test.woff2")
upload = Upload.find_by(original_filename: "fake.woff2")
expect(upload.id).not_to be_nil
expect(JSON.parse(response.body)["upload_id"]).to eq(upload.id)
end
@ -30,12 +31,11 @@ describe Admin::ThemesController do
context '.import' do
let(:theme_file) do
ActionDispatch::Http::UploadedFile.new(filename: 'sam-s-simple-theme.dcstyle.json',
tempfile: file_from_fixtures("sam-s-simple-theme.dcstyle.json", "json"))
Rack::Test::UploadedFile.new(file_from_fixtures("sam-s-simple-theme.dcstyle.json", "json"))
end
it 'imports a theme' do
xhr :post, :import, theme: theme_file
post :import, params: { theme: theme_file }, format: :json
expect(response).to be_success
json = ::JSON.parse(response.body)
@ -68,7 +68,7 @@ describe Admin::ThemesController do
# this will get serialized as well
ColorScheme.create_from_base(name: "test", colors: [])
xhr :get, :index
get :index, format: :json
expect(response).to be_success
@ -83,7 +83,13 @@ describe Admin::ThemesController do
context ' .create' do
it 'creates a theme' do
xhr :post, :create, theme: { name: 'my test name', theme_fields: [name: 'scss', target: 'common', value: 'body{color: red;}'] }
post :create, params: {
theme: {
name: 'my test name',
theme_fields: [name: 'scss', target: 'common', value: 'body{color: red;}']
}
}, format: :json
expect(response).to be_success
json = ::JSON.parse(response.body)
@ -96,14 +102,22 @@ describe Admin::ThemesController do
context ' .update' do
it 'can change default theme' do
theme = Theme.create(name: 'my name', user_id: -1)
xhr :put, :update, id: theme.id, theme: { default: true }
put :update, params: {
id: theme.id, theme: { default: true }
}, format: :json
expect(SiteSetting.default_theme_key).to eq(theme.key)
end
it 'can unset default theme' do
theme = Theme.create(name: 'my name', user_id: -1)
SiteSetting.default_theme_key = theme.key
xhr :put, :update, id: theme.id, theme: { default: false }
put :update, params: {
id: theme.id, theme: { default: false }
}, format: :json
expect(SiteSetting.default_theme_key).to be_blank
end
@ -116,16 +130,19 @@ describe Admin::ThemesController do
upload = Fabricate(:upload)
xhr :put, :update, id: theme.id,
theme: {
child_theme_ids: [child_theme.id],
name: 'my test name',
theme_fields: [
{ name: 'scss', target: 'common', value: '' },
{ name: 'scss', target: 'desktop', value: 'body{color: blue;}' },
{ name: 'bob', target: 'common', value: '', type_id: 2, upload_id: upload.id },
]
}
put :update, params: {
id: theme.id,
theme: {
child_theme_ids: [child_theme.id],
name: 'my test name',
theme_fields: [
{ name: 'scss', target: 'common', value: '' },
{ name: 'scss', target: 'desktop', value: 'body{color: blue;}' },
{ name: 'bob', target: 'common', value: '', type_id: 2, upload_id: upload.id },
]
}
}, format: :json
expect(response).to be_success
json = ::JSON.parse(response.body)
@ -135,11 +152,8 @@ describe Admin::ThemesController do
expect(fields[0]["value"]).to eq('')
expect(fields[0]["upload_id"]).to eq(upload.id)
expect(fields[1]["value"]).to eq('body{color: blue;}')
expect(fields.length).to eq(2)
expect(json["theme"]["child_themes"].length).to eq(1)
expect(UserHistory.where(action: UserHistory.actions[:change_theme]).count).to eq(1)
end
end