rails_admin_content_builder 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +1 -1
- data/.rubocop.yml +10 -0
- data/Gemfile +2 -1
- data/README.md +12 -1
- data/Rakefile +7 -7
- data/app/assets/images/cb-snippet-image-text.jpg +0 -0
- data/app/assets/images/cb-snippet-image-text.psd +0 -0
- data/app/assets/images/cb-snippet-image.jpg +0 -0
- data/app/assets/images/cb-snippet-image.psd +0 -0
- data/app/assets/images/cb-snippet-quote-text.jpg +0 -0
- data/app/assets/images/cb-snippet-quote-text.psd +0 -0
- data/app/assets/images/cb-snippet-quote.jpg +0 -0
- data/app/assets/images/cb-snippet-quote.psd +0 -0
- data/app/assets/images/cb-snippet-relational-text.jpg +0 -0
- data/app/assets/images/cb-snippet-relational-text.psd +0 -0
- data/app/assets/images/cb-snippet-text-image.jpg +0 -0
- data/app/assets/images/cb-snippet-text-image.psd +0 -0
- data/app/assets/images/cb-snippet-text-quote.jpg +0 -0
- data/app/assets/images/cb-snippet-text-quote.psd +0 -0
- data/app/assets/images/cb-snippet-text-relational.jpg +0 -0
- data/app/assets/images/cb-snippet-text-relational.psd +0 -0
- data/app/assets/images/cb-snippet-text.jpg +0 -0
- data/app/assets/images/cb-snippet-text.psd +0 -0
- data/app/assets/images/cb-snippet-video.jpg +0 -0
- data/app/assets/images/cb-snippet-video.psd +0 -0
- data/app/assets/javascripts/rails_admin/content_builder.js.erb +27 -20
- data/app/assets/stylesheets/rails_admin/content_builder.scss +174 -81
- data/app/controllers/rails_admin_content_builder/content_builder_controller.rb +7 -9
- data/app/helpers/rails_admin_content_builder/content_builder_helpers.rb +9 -3
- data/app/models/rails_admin_content_builder/content_builder.rb +21 -5
- data/app/views/rails_admin/main/content_builder.html.erb +3 -3
- data/bin/console +3 -3
- data/config/initializers/assets.rb +13 -13
- data/config/locales/content_builder.en.yml +4 -0
- data/config/locales/content_builder.pt-BR.yml +4 -0
- data/config/routes.rb +6 -6
- data/lib/generators/rails_admin_content_builder_generator.rb +17 -9
- data/lib/generators/templates/content_builder_image_uploader.rb +3 -13
- data/lib/rails_admin_content_builder.rb +3 -3
- data/lib/rails_admin_content_builder/engine.rb +1 -1
- data/lib/rails_admin_content_builder/version.rb +1 -1
- data/rails_admin_content_builder.gemspec +22 -20
- data/screenshot/image1.png +0 -0
- data/spec/controllers/rails_admin_content_builder/content_builder_controller_spec.rb +41 -5
- data/spec/dummy/Gemfile +0 -1
- data/spec/dummy/app/uploaders/content_builder_image_uploader.rb +2 -3
- data/spec/dummy/bin/setup +8 -8
- data/spec/dummy/config/application.rb +7 -7
- data/spec/dummy/config/initializers/rails_admin.rb +0 -1
- data/spec/dummy/config/initializers/simple_form.rb +1 -1
- data/spec/dummy/db/schema.rb +23 -25
- data/spec/factories/content_builder_categories.rb +2 -1
- data/spec/factories/content_builder_images.rb +7 -2
- data/spec/features/create_content_builder_category_spec.rb +4 -3
- data/spec/features/create_content_builder_spec.rb +5 -4
- data/spec/features/status_content_builder_spec.rb +8 -5
- data/spec/helpers/rails_admin_content_builder/content_builder_helper_spec.rb +15 -12
- data/spec/models/rails_admin_content_builder/content_builder_category_spec.rb +1 -1
- data/spec/models/rails_admin_content_builder/content_builder_image_spec.rb +1 -1
- data/spec/models/rails_admin_content_builder/content_builder_spec.rb +22 -8
- data/spec/spec_helper.rb +4 -4
- data/spec/version_spec.rb +1 -1
- data/vendor/assets/stylesheets/rails_admin_content_builder.scss +47 -30
- metadata +1726 -4
- data/spec/dummy/db/development.sqlite3 +0 -0
@@ -1,15 +1,13 @@
|
|
1
1
|
module RailsAdminContentBuilder
|
2
|
+
# This class
|
2
3
|
class ContentBuilderController < ::ApplicationController
|
3
4
|
def search_content
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
content_builder = RailsAdminContentBuilder::ContentBuilder
|
6
|
+
@content_builder = content_builder.order('date_publish desc')
|
7
|
+
.limit(10)
|
8
|
+
.search(params[:term])
|
7
9
|
if @content_builder
|
8
|
-
render json: @content_builder.to_json(:
|
9
|
-
:content_builder_category => {
|
10
|
-
:only => [:name, :slug]
|
11
|
-
}
|
12
|
-
})
|
10
|
+
render json: @content_builder.to_json(include: {content_builder_category: {only: [:name, :slug]}})
|
13
11
|
else
|
14
12
|
render json: @content_builder.errors
|
15
13
|
end
|
@@ -19,7 +17,7 @@ module RailsAdminContentBuilder
|
|
19
17
|
@content_builder = ContentBuilder.find(params[:id])
|
20
18
|
@image = @content_builder.content_builder_images
|
21
19
|
.create(image: params[:content_builder_image])
|
22
|
-
if @image
|
20
|
+
if @image.valid?
|
23
21
|
render json: find_image(@image.id)
|
24
22
|
else
|
25
23
|
render json: @image.errors
|
@@ -7,26 +7,32 @@
|
|
7
7
|
# end
|
8
8
|
# end
|
9
9
|
module RailsAdminContentBuilder
|
10
|
+
# This is a Module
|
10
11
|
module ContentBuilderHelpers
|
11
12
|
# Return content Object
|
12
13
|
#
|
13
14
|
# @content = content_created
|
14
15
|
def content_created
|
15
|
-
|
16
|
+
set_content_builder
|
16
17
|
end
|
17
18
|
|
18
19
|
# Return all contents created
|
19
20
|
#
|
20
21
|
# @content = all_contents_created
|
21
22
|
def all_contents_created
|
22
|
-
|
23
|
+
set_content_builder.where(status: true)
|
23
24
|
end
|
24
25
|
|
25
26
|
# Return specific contents created by slug
|
26
27
|
#
|
27
28
|
# @content = find_content_created_by_slug('slug')
|
28
29
|
def find_content_created_by_slug(slug)
|
29
|
-
|
30
|
+
set_content_builder.where(status: true, slug: slug).first
|
31
|
+
end
|
32
|
+
|
33
|
+
# Return object RailsAdminContentBuilder::ContentBuilder
|
34
|
+
def set_content_builder
|
35
|
+
RailsAdminContentBuilder::ContentBuilder
|
30
36
|
end
|
31
37
|
end
|
32
38
|
end
|
@@ -7,9 +7,11 @@ module RailsAdminContentBuilder
|
|
7
7
|
|
8
8
|
friendly_id :title, use: :slugged
|
9
9
|
|
10
|
-
validates :title, :date_publish, :content_builder_category,
|
10
|
+
validates :title, :date_publish, :content_builder_category,
|
11
|
+
:written_by, presence: true
|
11
12
|
|
12
|
-
has_many :content_builder_images, inverse_of: :content_builder,
|
13
|
+
has_many :content_builder_images, inverse_of: :content_builder,
|
14
|
+
dependent: :destroy
|
13
15
|
belongs_to :content_builder_category, inverse_of: :content_builders
|
14
16
|
|
15
17
|
search_scope :search do
|
@@ -19,9 +21,23 @@ module RailsAdminContentBuilder
|
|
19
21
|
def content_sanitized
|
20
22
|
white_list_sanitizer = Rails::Html::WhiteListSanitizer.new
|
21
23
|
white_list_sanitizer.sanitize(
|
22
|
-
|
23
|
-
tags:
|
24
|
-
attributes:
|
24
|
+
content,
|
25
|
+
tags: tags_hash,
|
26
|
+
attributes: attributes_hash
|
27
|
+
).try(:html_safe)
|
28
|
+
end
|
29
|
+
|
30
|
+
def tags_hash
|
31
|
+
%w(
|
32
|
+
div b i a u p img figure figcaption a iframe footer aside
|
33
|
+
section blockquote ul ol li h1 h2 h3 h4 h5 h6
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def attributes_hash
|
38
|
+
%w(
|
39
|
+
src class alt href allowfullscreen frameborder height width
|
40
|
+
)
|
25
41
|
end
|
26
42
|
end
|
27
43
|
end
|
@@ -75,11 +75,11 @@
|
|
75
75
|
|
76
76
|
<%= simple_form_for rails_admin.content_builder_url(@abstract_model.to_param, id: @object.id), html: { class: 'cb-form' }, remote: false do |f| %>
|
77
77
|
<div class="cb-controls">
|
78
|
-
<%= f.button :submit, t('admin.actions.content_builder.button.save'), name: 'save', class: 'btn btn-block btn-primary' %>
|
78
|
+
<%= f.button :submit, t('admin.actions.content_builder.button.save'), name: 'save', class: 'btn btn-block btn-primary btn-right' %>
|
79
79
|
<% if @object.status %>
|
80
|
-
<%= f.button :submit, t('admin.actions.content_builder.button.unpublish'), name: 'unpublish', class: 'btn btn-block btn-danger' %>
|
80
|
+
<%= f.button :submit, t('admin.actions.content_builder.button.unpublish'), name: 'unpublish', class: 'btn btn-block btn-danger btn-left' %>
|
81
81
|
<% else %>
|
82
|
-
<%= f.button :submit, t('admin.actions.content_builder.button.publish'), name: 'publish', class: 'btn btn-block btn-success' %>
|
82
|
+
<%= f.button :submit, t('admin.actions.content_builder.button.publish'), name: 'publish', class: 'btn btn-block btn-success btn-left' %>
|
83
83
|
<% end %>
|
84
84
|
</div>
|
85
85
|
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rails_admin_content_builder'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "rails_admin_content_builder"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
@@ -1,13 +1,13 @@
|
|
1
|
-
Rails.application.config.assets.precompile += %w(
|
2
|
-
Rails.application.config.assets.precompile += %w(
|
3
|
-
Rails.application.config.assets.precompile += %w(
|
4
|
-
Rails.application.config.assets.precompile += %w(
|
5
|
-
Rails.application.config.assets.precompile += %w(
|
6
|
-
Rails.application.config.assets.precompile += %w(
|
7
|
-
Rails.application.config.assets.precompile += %w(
|
8
|
-
Rails.application.config.assets.precompile += %w(
|
9
|
-
Rails.application.config.assets.precompile += %w(
|
10
|
-
Rails.application.config.assets.precompile += %w(
|
11
|
-
Rails.application.config.assets.precompile += %w(
|
12
|
-
Rails.application.config.assets.precompile += %w(
|
13
|
-
Rails.application.config.assets.precompile += %w(
|
1
|
+
Rails.application.config.assets.precompile += %w(cb-loading.svg)
|
2
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-text.jpg)
|
3
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-image-text.jpg)
|
4
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-text-image.jpg)
|
5
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-quote.jpg)
|
6
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-quote-text.jpg)
|
7
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-text-quote.jpg)
|
8
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-image.jpg)
|
9
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-video.jpg)
|
10
|
+
Rails.application.config.assets.precompile += %w(cb-image-default.jpg)
|
11
|
+
Rails.application.config.assets.precompile += %w(cb-video-default.jpg)
|
12
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-relational-text.jpg)
|
13
|
+
Rails.application.config.assets.precompile += %w(cb-snippet-text-relational.jpg)
|
@@ -11,6 +11,10 @@ en:
|
|
11
11
|
written_by: "Writter By"
|
12
12
|
news_source: "News source"
|
13
13
|
summary: "Summary"
|
14
|
+
url: "Paste YouTube url"
|
15
|
+
invalid_url: "Invalid url"
|
16
|
+
image_description: 'Image description'
|
17
|
+
search_content: 'Search Content'
|
14
18
|
button:
|
15
19
|
save: "Save"
|
16
20
|
publish: "Publish"
|
@@ -11,6 +11,10 @@ pt-BR:
|
|
11
11
|
written_by: "Autor"
|
12
12
|
news_source: "Fonte"
|
13
13
|
summary: "Resumo"
|
14
|
+
url: "Cole a url do YouTube"
|
15
|
+
invalid_url: "Ops! Você não informou uma url válida"
|
16
|
+
image_description: 'Divulgação'
|
17
|
+
search_content: 'Buscar notícias'
|
14
18
|
button:
|
15
19
|
save: "Salvar"
|
16
20
|
publish: "Publicar"
|
data/config/routes.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
|
3
|
-
|
4
|
-
get
|
2
|
+
get_url = 'admin/rails_admin_content_builder~content_builder/search_content'
|
3
|
+
get_method = 'rails_admin_content_builder/content_builder#search_content'
|
4
|
+
get get_url => get_method
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
put
|
6
|
+
put_url = 'admin/rails_admin_content_builder~content_builder/:id/create_images'
|
7
|
+
put_method = 'rails_admin_content_builder/content_builder#create_images'
|
8
|
+
put put_url => put_method
|
9
9
|
end
|
@@ -4,29 +4,37 @@ class RailsAdminContentBuilderGenerator < Rails::Generators::Base
|
|
4
4
|
include Rails::Generators::Migration
|
5
5
|
|
6
6
|
def self.source_root
|
7
|
-
@source_root ||= File.expand_path(
|
7
|
+
@source_root ||= File.expand_path(
|
8
|
+
File.join(File.dirname(__FILE__), 'templates/')
|
9
|
+
)
|
8
10
|
end
|
9
11
|
|
10
12
|
def self.next_migration_number(*)
|
11
|
-
|
12
|
-
@migration = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
13
|
-
else
|
13
|
+
if @migration
|
14
14
|
@migration += 1
|
15
|
+
else
|
16
|
+
@migration = Time.now.utc.strftime('%Y%m%d%H%M%S').to_i
|
15
17
|
end
|
16
18
|
@migration.to_s
|
17
19
|
end
|
18
20
|
|
19
21
|
def create_uploader_content_builder_image_model
|
20
|
-
template
|
22
|
+
template 'content_builder_image_uploader.rb',
|
23
|
+
'app/uploaders/content_builder_image_uploader.rb'
|
21
24
|
end
|
22
25
|
|
23
26
|
def create_rails_admin_config_in_initializer
|
24
|
-
template
|
27
|
+
template 'rails_admin_content_builder.rb',
|
28
|
+
'config/initializers/rails_admin_content_builder.rb'
|
25
29
|
end
|
26
30
|
|
27
31
|
def create_migrations
|
28
|
-
|
29
|
-
migration_template
|
30
|
-
|
32
|
+
path = 'db/migrate'
|
33
|
+
migration_template 'create_content_builder_category_migration.rb',
|
34
|
+
File.join(path, 'create_content_builder_categories.rb')
|
35
|
+
migration_template 'create_content_builder_migration.rb',
|
36
|
+
File.join(path, 'create_content_builders.rb')
|
37
|
+
migration_template 'create_content_builder_image_migration.rb',
|
38
|
+
File.join(path, 'create_content_builder_images.rb')
|
31
39
|
end
|
32
40
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
3
2
|
class ContentBuilderImageUploader < CarrierWave::Uploader::Base
|
4
3
|
# Include RMagick or MiniMagick support:
|
5
4
|
# include CarrierWave::RMagick
|
@@ -15,14 +14,6 @@ class ContentBuilderImageUploader < CarrierWave::Uploader::Base
|
|
15
14
|
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
16
15
|
end
|
17
16
|
|
18
|
-
# Provide a default URL as a default if there hasn't been a file uploaded:
|
19
|
-
# def default_url
|
20
|
-
# # For Rails 3.1+ asset pipeline compatibility:
|
21
|
-
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
22
|
-
#
|
23
|
-
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
24
|
-
# end
|
25
|
-
|
26
17
|
# Process files as they are uploaded:
|
27
18
|
# process :scale => [200, 300]
|
28
19
|
#
|
@@ -32,11 +23,11 @@ class ContentBuilderImageUploader < CarrierWave::Uploader::Base
|
|
32
23
|
|
33
24
|
# Create different versions of your uploaded files:
|
34
25
|
version :left_or_right do
|
35
|
-
process :
|
26
|
+
process resize_to_fit: [450, 450]
|
36
27
|
end
|
37
28
|
|
38
29
|
version :center do
|
39
|
-
process :
|
30
|
+
process resize_to_fit: [900, 900]
|
40
31
|
end
|
41
32
|
|
42
33
|
# Add a white list of extensions which are allowed to be uploaded.
|
@@ -46,9 +37,8 @@ class ContentBuilderImageUploader < CarrierWave::Uploader::Base
|
|
46
37
|
end
|
47
38
|
|
48
39
|
# Override the filename of the uploaded files:
|
49
|
-
# Avoid using model.id or version_name here, see uploader/store.rb for
|
40
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for detail
|
50
41
|
# def filename
|
51
42
|
# "something.jpg" if original_filename
|
52
43
|
# end
|
53
|
-
|
54
44
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'rails_admin_content_builder/engine'
|
2
2
|
|
3
3
|
module RailsAdminContentBuilder
|
4
4
|
end
|
@@ -23,7 +23,7 @@ module RailsAdmin
|
|
23
23
|
end
|
24
24
|
|
25
25
|
register_instance_option :controller do
|
26
|
-
|
26
|
+
proc do
|
27
27
|
@object = @abstract_model.model.find(params[:id])
|
28
28
|
@response = {}
|
29
29
|
|
@@ -46,7 +46,7 @@ module RailsAdmin
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
render :
|
49
|
+
render action: @action.template_name
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
@@ -1,42 +1,44 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require 'rails_admin_content_builder/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'rails_admin_content_builder'
|
8
8
|
spec.version = RailsAdminContentBuilder::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Luiz Picolo', 'Gabriel Medina']
|
10
|
+
spec.email = ['luizpicolo@gmail.com', 'gmedina.santos@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'Easy way for create contents using rails_admin'
|
13
|
+
spec.description = 'Easy way for create contents using rails_admin'
|
14
|
+
spec.homepage = 'http://github.com/luizpicolo/rails_admin_content_builder'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
|
-
spec.files
|
18
|
-
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
}
|
20
|
+
spec.bindir = 'exe'
|
19
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
21
|
-
spec.test_files = Dir[
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
spec.test_files = Dir['spec/**/*']
|
22
24
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rails', ['>= 4.0', '< 5']
|
28
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'rails_admin', '~> 0.8.1'
|
28
30
|
spec.add_development_dependency 'capybara', '~> 2.7', '>= 2.7.0'
|
29
31
|
spec.add_development_dependency 'launchy', '~> 2.4', '>= 2.4.3'
|
30
|
-
spec.add_development_dependency
|
32
|
+
spec.add_development_dependency 'shoulda-matchers', '~> 3.1'
|
31
33
|
spec.add_development_dependency 'selenium-webdriver', '~> 2.53', '>= 2.53.4'
|
32
34
|
spec.add_development_dependency 'factory_girl_rails', '~> 4.7', '>= 4.7.0'
|
33
35
|
spec.add_development_dependency 'faker', '~> 1.6', '>= 1.6.3'
|
34
36
|
|
35
|
-
spec.add_runtime_dependency
|
37
|
+
spec.add_runtime_dependency 'carrierwave', '~> 0.11.0'
|
36
38
|
spec.add_runtime_dependency 'medium-editor-rails', '~> 2.1', '>= 2.1.0'
|
37
39
|
spec.add_runtime_dependency 'mini_magick', '~> 4.5', '>= 4.5.1'
|
38
40
|
spec.add_runtime_dependency 'friendly_id', '~> 5.1', '>= 5.1.0'
|
39
|
-
spec.add_runtime_dependency
|
41
|
+
spec.add_runtime_dependency 'simple_form', '~> 3.2'
|
40
42
|
spec.add_runtime_dependency 'search_cop', '~> 1.0', '>= 1.0.6'
|
41
43
|
spec.add_runtime_dependency 'rails-html-sanitizer', '~> 1.0', '>= 1.0.0'
|
42
44
|
end
|
data/screenshot/image1.png
CHANGED
Binary file
|
@@ -1,19 +1,55 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
-
|
4
|
+
content_builder_controller = RailsAdminContentBuilder::ContentBuilderController
|
5
|
+
|
6
|
+
describe content_builder_controller, type: :controller do
|
5
7
|
describe 'PUT #create_images' do
|
6
|
-
it
|
8
|
+
it 'returns valid JSON' do
|
7
9
|
content_builder = FactoryGirl.create :content_builder
|
8
10
|
put :create_images, id: content_builder.id,
|
9
|
-
|
11
|
+
content_builder_image: Rack::Test::UploadedFile.new(
|
12
|
+
File.join(
|
13
|
+
'spec', 'fixtures', 'assets', 'example.jpg'
|
14
|
+
)
|
15
|
+
)
|
10
16
|
|
11
17
|
json = JSON.parse(response.body)
|
12
|
-
path = '/uploads/rails_admin_content_builder
|
18
|
+
path = '/uploads/rails_admin_content_builder'
|
19
|
+
path << '/content_builder_image/image/1/'
|
13
20
|
|
14
21
|
expect(response.status).to eq 200
|
15
22
|
expect(json['image']['url']).to eq path + 'example.jpg'
|
16
|
-
expect(
|
23
|
+
expect(
|
24
|
+
json['image']['left_or_right']['url']
|
25
|
+
).to eq path + 'left_or_right_example.jpg'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns error' do
|
29
|
+
content_builder = FactoryGirl.create :content_builder
|
30
|
+
put :create_images, id: content_builder.id, content_builder_image: nil
|
31
|
+
|
32
|
+
json = JSON.parse(response.body)
|
33
|
+
|
34
|
+
expect(response.status).to eq 200
|
35
|
+
expect(json['image']).to include("can't be blank")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'GET #search_content' do
|
40
|
+
it 'returns valid JSON' do
|
41
|
+
5.times do |i|
|
42
|
+
content_builder = FactoryGirl.create :content_builder, title: "content #{i}"
|
43
|
+
end
|
44
|
+
5.times do |i|
|
45
|
+
content_builder = FactoryGirl.create :content_builder, title: "title #{i}"
|
46
|
+
end
|
47
|
+
get :search_content, term: "content"
|
48
|
+
|
49
|
+
json = JSON.parse(response.body)
|
50
|
+
|
51
|
+
expect(response.status).to eq 200
|
52
|
+
expect(json.size).to eq 5
|
17
53
|
end
|
18
54
|
end
|
19
55
|
end
|