push_type_api 0.10.0.beta.3

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.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +20 -0
  3. data/README.md +28 -0
  4. data/app/controllers/push_type/api/assets_controller.rb +72 -0
  5. data/app/controllers/push_type/api/nodes_controller.rb +108 -0
  6. data/app/controllers/push_type/api/users_controller.rb +67 -0
  7. data/app/controllers/push_type/api_controller.rb +13 -0
  8. data/app/helpers/push_type/api_helper.rb +4 -0
  9. data/app/views/push_type/api/assets/_asset.json.jbuilder +9 -0
  10. data/app/views/push_type/api/assets/index.json.jbuilder +12 -0
  11. data/app/views/push_type/api/assets/show.json.jbuilder +3 -0
  12. data/app/views/push_type/api/nodes/_node.json.jbuilder +13 -0
  13. data/app/views/push_type/api/nodes/index.json.jbuilder +11 -0
  14. data/app/views/push_type/api/nodes/show.json.jbuilder +17 -0
  15. data/app/views/push_type/api/shared/_pagination.json.jbuilder +5 -0
  16. data/app/views/push_type/api/users/_user.json.jbuilder +5 -0
  17. data/app/views/push_type/api/users/index.json.jbuilder +7 -0
  18. data/app/views/push_type/api/users/show.json.jbuilder +16 -0
  19. data/config/routes.rb +31 -0
  20. data/lib/push_type/api/engine.rb +15 -0
  21. data/lib/push_type/api.rb +12 -0
  22. data/lib/push_type_api.rb +1 -0
  23. data/lib/tasks/api_tasks.rake +4 -0
  24. data/test/controllers/push_type/api/assets_controller_test.rb +104 -0
  25. data/test/controllers/push_type/api/nodes_controller_test.rb +168 -0
  26. data/test/controllers/push_type/api/users_controller_test.rb +67 -0
  27. data/test/dummy/README.md +24 -0
  28. data/test/dummy/Rakefile +6 -0
  29. data/test/dummy/app/assets/config/manifest.js +3 -0
  30. data/test/dummy/app/assets/javascripts/application.js +16 -0
  31. data/test/dummy/app/assets/javascripts/cable.js +13 -0
  32. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  33. data/test/dummy/app/channels/application_cable/channel.rb +4 -0
  34. data/test/dummy/app/channels/application_cable/connection.rb +4 -0
  35. data/test/dummy/app/controllers/application_controller.rb +3 -0
  36. data/test/dummy/app/helpers/application_helper.rb +2 -0
  37. data/test/dummy/app/jobs/application_job.rb +2 -0
  38. data/test/dummy/app/mailers/application_mailer.rb +4 -0
  39. data/test/dummy/app/models/application_record.rb +3 -0
  40. data/test/dummy/app/models/location.rb +6 -0
  41. data/test/dummy/app/models/page.rb +11 -0
  42. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  43. data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
  44. data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
  45. data/test/dummy/app/views/nodes/page.html.erb +5 -0
  46. data/test/dummy/bin/bundle +3 -0
  47. data/test/dummy/bin/rails +4 -0
  48. data/test/dummy/bin/rake +4 -0
  49. data/test/dummy/bin/setup +34 -0
  50. data/test/dummy/bin/update +29 -0
  51. data/test/dummy/config/application.rb +14 -0
  52. data/test/dummy/config/boot.rb +4 -0
  53. data/test/dummy/config/cable.yml +9 -0
  54. data/test/dummy/config/database.yml +85 -0
  55. data/test/dummy/config/environment.rb +5 -0
  56. data/test/dummy/config/environments/development.rb +54 -0
  57. data/test/dummy/config/environments/production.rb +86 -0
  58. data/test/dummy/config/environments/test.rb +42 -0
  59. data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
  60. data/test/dummy/config/initializers/assets.rb +11 -0
  61. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
  63. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/test/dummy/config/initializers/inflections.rb +16 -0
  65. data/test/dummy/config/initializers/mime_types.rb +4 -0
  66. data/test/dummy/config/initializers/new_framework_defaults.rb +24 -0
  67. data/test/dummy/config/initializers/push_type.rb +50 -0
  68. data/test/dummy/config/initializers/session_store.rb +3 -0
  69. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  70. data/test/dummy/config/locales/en.yml +23 -0
  71. data/test/dummy/config/puma.rb +47 -0
  72. data/test/dummy/config/routes.rb +15 -0
  73. data/test/dummy/config/secrets.yml +22 -0
  74. data/test/dummy/config/spring.rb +6 -0
  75. data/test/dummy/config.ru +5 -0
  76. data/test/dummy/db/migrate/20161116222825_create_push_type_users.push_type.rb +13 -0
  77. data/test/dummy/db/migrate/20161116222826_create_push_type_nodes.push_type.rb +25 -0
  78. data/test/dummy/db/migrate/20161116222827_create_push_type_node_hierarchies.push_type.rb +17 -0
  79. data/test/dummy/db/migrate/20161116222828_create_push_type_assets.push_type.rb +19 -0
  80. data/test/dummy/db/migrate/20161116222829_add_field_store_default_values.push_type.rb +7 -0
  81. data/test/dummy/db/migrate/20161116222830_drop_legacy_push_type_taxonomies.push_type.rb +14 -0
  82. data/test/dummy/db/schema.rb +65 -0
  83. data/test/dummy/db/seeds.rb +7 -0
  84. data/test/dummy/log/test.log +5968 -0
  85. data/test/dummy/public/404.html +67 -0
  86. data/test/dummy/public/422.html +67 -0
  87. data/test/dummy/public/500.html +66 -0
  88. data/test/dummy/public/apple-touch-icon-precomposed.png +0 -0
  89. data/test/dummy/public/apple-touch-icon.png +0 -0
  90. data/test/dummy/public/favicon.ico +0 -0
  91. data/test/dummy/public/robots.txt +5 -0
  92. data/test/lib/push_type/api_test.rb +11 -0
  93. data/test/test_helper.rb +23 -0
  94. metadata +249 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 75bbc95444676040e4b78f21a4a562205d705842
4
+ data.tar.gz: 1fa0b87e1175fd79e62258afd907127d18fa8321
5
+ SHA512:
6
+ metadata.gz: 3dea2e28935fd0d595c83a4ad8f1a1f1743016b7474f81382ed807d65d134f5b09860b41d6857f71ee8775f1f6eca30fab0ef2f9bd415d8adb8246bd842702bc
7
+ data.tar.gz: 136134ca14377dbcc5da58605817df1219f39b200f943d19be9bce21904f5b4af379be855fe11c72c0d5d489587a6f6e0f301e18805bbb8b7882734a1209547b
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014-2016 Push Code Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Api
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'api'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install api
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,72 @@
1
+ require_dependency "push_type/api_controller"
2
+
3
+ module PushType
4
+ class Api::AssetsController < ApiController
5
+
6
+ before_action :build_asset, only: [:create]
7
+ before_action :load_asset, only: [:show, :update, :destroy, :restore]
8
+
9
+ def index
10
+ @assets = PushType::Asset.not_trash.page(params[:page]).per(12)
11
+ end
12
+
13
+ def trash
14
+ @assets = PushType::Asset.trashed.page(params[:page]).per(12)
15
+ render :index
16
+ end
17
+
18
+ def show
19
+ end
20
+
21
+ def create
22
+ if @asset.save
23
+ render :show, status: :created
24
+ else
25
+ render json: { errors: @asset.errors }, status: :unprocessable_entity
26
+ end
27
+ end
28
+
29
+ def update
30
+ if @asset.update_attributes asset_params
31
+ render :show
32
+ else
33
+ render json: { errors: @asset.errors }, status: :unprocessable_entity
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ if @asset.trashed?
39
+ @asset.destroy
40
+ head :no_content
41
+ else
42
+ @asset.trash!
43
+ render :show
44
+ end
45
+ end
46
+
47
+ def restore
48
+ @asset.restore!
49
+ render :show
50
+ end
51
+
52
+ def empty
53
+ PushType::Asset.trashed.destroy_all
54
+ head :no_content
55
+ end
56
+
57
+ private
58
+
59
+ def build_asset
60
+ @asset = PushType::Asset.new asset_params.merge(uploader: push_type_user)
61
+ end
62
+
63
+ def load_asset
64
+ @asset = PushType::Asset.find params[:id]
65
+ end
66
+
67
+ def asset_params
68
+ params.fetch(:asset, {}).permit(:file, :description)
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,108 @@
1
+ require_dependency "push_type/api_controller"
2
+
3
+ module PushType
4
+ class Api::NodesController < ApiController
5
+
6
+ before_action :build_node, only: [:create]
7
+ before_action :load_node, only: [:show, :update, :destroy, :restore, :position]
8
+
9
+ def index
10
+ @nodes = node_scope.not_trash.page(params[:page]).per(30)
11
+ end
12
+
13
+ def trash
14
+ @nodes = PushType::Node.all.trashed.page(params[:page]).per(30).reorder(deleted_at: :desc)
15
+ render :index
16
+ end
17
+
18
+ def show
19
+ end
20
+
21
+ def create
22
+ if @node.save
23
+ render :show, status: :created
24
+ else
25
+ render json: { errors: @node.errors }, status: :unprocessable_entity
26
+ end
27
+ end
28
+
29
+ def update
30
+ if @node.update_attributes node_params_with_fields.merge(updater: push_type_user)
31
+ render :show
32
+ else
33
+ render json: { errors: @node.errors }, status: :unprocessable_entity
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ if @node.trashed?
39
+ @node.destroy
40
+ head :no_content
41
+ else
42
+ @node.trash!
43
+ render :show
44
+ end
45
+ end
46
+
47
+ def position
48
+ if reorder_node
49
+ head :no_content
50
+ else
51
+ render json: { errors: @node.errors }, status: :unprocessable_entity
52
+ end
53
+ end
54
+
55
+ def restore
56
+ @node.restore!
57
+ render :show
58
+ end
59
+
60
+ def empty
61
+ PushType::Node.trashed.destroy_all
62
+ head :no_content
63
+ end
64
+
65
+ private
66
+
67
+ def node_scope
68
+ @node_scope ||= if params[:node_id]
69
+ @parent = PushType::Node.find params[:node_id]
70
+ @parent.children
71
+ else
72
+ PushType::Node.roots
73
+ end
74
+ end
75
+
76
+ def build_node
77
+ @node = node_scope.new type: node_type, creator: push_type_user, updater: push_type_user
78
+ @node.attributes = @node.attributes.merge(node_params_with_fields.to_h)
79
+ end
80
+
81
+ def load_node
82
+ @node = PushType::Node.find params[:id]
83
+ end
84
+
85
+ def node_params
86
+ @node_params ||= params.fetch(:node, {}).permit(:type, :parent_id, :title, :slug, :status, :published_at, :published_to)
87
+ end
88
+
89
+ def node_type
90
+ node_params[:type]
91
+ end
92
+
93
+ def node_params_with_fields
94
+ node_params.tap do |whitelist|
95
+ @node.fields.keys.each { |k| whitelist[k] = params[:node][k] if params[:node][k].present? }
96
+ end
97
+ end
98
+
99
+ def reorder_node
100
+ if params[:prev]
101
+ PushType::Node.find(params[:prev]).append_sibling(@node)
102
+ elsif params[:next]
103
+ PushType::Node.find(params[:next]).prepend_sibling(@node)
104
+ end
105
+ end
106
+
107
+ end
108
+ end
@@ -0,0 +1,67 @@
1
+ require_dependency "push_type/api_controller"
2
+
3
+ module PushType
4
+ class Api::UsersController < ApiController
5
+
6
+ before_action :build_user, only: [:create]
7
+ before_action :load_user, only: [:show, :update, :destroy]
8
+
9
+ def index
10
+ @users = user_scope.page(params[:page]).per(30)
11
+ end
12
+
13
+ def show
14
+ end
15
+
16
+ def create
17
+ if @user.save
18
+ render :show, status: :created
19
+ else
20
+ render json: { errors: @user.errors }, status: :unprocessable_entity
21
+ end
22
+ end
23
+
24
+ def update
25
+ if @user.update_attributes user_params_with_fields
26
+ render :show
27
+ else
28
+ render json: { errors: @user.errors }, status: :unprocessable_entity
29
+ end
30
+ end
31
+
32
+ def destroy
33
+ if @user != push_type_user
34
+ @user.destroy
35
+ head :no_content
36
+ else
37
+ head :bad_request
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def user_scope
44
+ PushType::User
45
+ end
46
+
47
+ def build_user
48
+ @user = user_scope.new
49
+ @user.attributes = @user.attributes.merge(user_params_with_fields.to_h)
50
+ end
51
+
52
+ def load_user
53
+ @user = user_scope.find params[:id]
54
+ end
55
+
56
+ def user_params
57
+ @node_params ||= params.fetch(:user, {}).permit(:name, :email)
58
+ end
59
+
60
+ def user_params_with_fields
61
+ user_params.tap do |whitelist|
62
+ @user.fields.keys.each { |k| whitelist[k] = params[:user][k] if params[:user][k].present? }
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,13 @@
1
+ module PushType
2
+ class ApiController < ActionController::Base
3
+
4
+ protect_from_forgery with: :null_session
5
+
6
+ protected
7
+
8
+ def push_type_user
9
+ respond_to?(:current_user) ? current_user : nil
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module PushType
2
+ module ApiHelper
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ json.id asset.id
2
+ json.file_name asset.file_name
3
+ json.file_size asset.file_size
4
+ json.mime_type asset.mime_type
5
+ json.description asset.description
6
+ json.created_at asset.created_at
7
+ json.updated_at asset.updated_at
8
+ json.is_image asset.image?
9
+ json.is_trashed asset.trashed?
@@ -0,0 +1,12 @@
1
+ json.assets @assets do |asset|
2
+ json.partial! 'asset', asset: asset
3
+
4
+ json.links do
5
+ json.url media_path(asset)
6
+ json.preview asset.image? ? media_path(asset, style: :push_type_thumb) : image_path("push_type/icons-assets.svg##{ asset.kind }")
7
+ end
8
+ end
9
+
10
+ json.meta do
11
+ json.partial! 'push_type/api/shared/pagination', collection: @assets
12
+ end
@@ -0,0 +1,3 @@
1
+ json.asset do
2
+ json.partial! 'asset', asset: @asset
3
+ end
@@ -0,0 +1,13 @@
1
+ json.id node.id
2
+ json.type node.type
3
+ json.is_exposed node.exposed?
4
+ json.parent_id node.parent_id
5
+ json.title node.title
6
+ json.slug node.slug
7
+ json.permalink node_url(node)
8
+ json.created_at node.created_at
9
+ json.updated_at node.updated_at
10
+ json.published_at node.published_at
11
+ json.published_to node.published_to
12
+ json.children node.children.count
13
+ json.is_trashed node.trashed?
@@ -0,0 +1,11 @@
1
+ json.nodes @nodes do |node|
2
+ json.partial! 'node', node: node
3
+ end
4
+
5
+ json.meta do
6
+ json.partial! 'push_type/api/shared/pagination', collection: @nodes
7
+
8
+ if params[:action] == 'index'
9
+ json.child_nodes @parent ? @parent.child_nodes : PushType.root_nodes
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ json.node do
2
+ json.partial! 'node', node: @node
3
+
4
+ @node.fields.each do |key, field|
5
+ json.set! key, field.value
6
+ end
7
+ end
8
+
9
+ if params[:action] == 'show'
10
+ json.meta do
11
+ json.fields @node.fields do |key, field|
12
+ json.name field.name
13
+ json.kind field.kind
14
+ end
15
+ json.child_nodes @node.child_nodes
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ json.current_page collection.current_page
2
+ json.next_page collection.next_page
3
+ json.prev_page collection.prev_page
4
+ json.total_pages collection.total_pages
5
+ json.total_count collection.total_count
@@ -0,0 +1,5 @@
1
+ json.id user.id
2
+ json.name user.name
3
+ json.email user.email
4
+ json.created_at user.created_at
5
+ json.updated_at user.updated_at
@@ -0,0 +1,7 @@
1
+ json.users @users do |user|
2
+ json.partial! 'user', user: user
3
+ end
4
+
5
+ json.meta do
6
+ json.partial! 'push_type/api/shared/pagination', collection: @users
7
+ end
@@ -0,0 +1,16 @@
1
+ json.user do
2
+ json.partial! 'user', user: @user
3
+
4
+ @user.fields.each do |key, field|
5
+ json.set! key, field.value
6
+ end
7
+ end
8
+
9
+ if params[:action] == 'show'
10
+ json.meta do
11
+ json.fields @user.fields do |key, field|
12
+ json.name field.name
13
+ json.kind field.kind
14
+ end
15
+ end
16
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,31 @@
1
+ PushType::Api::Engine.routes.draw do
2
+
3
+ scope module: 'api', except: [:new, :edit], defaults: { format: :json } do
4
+
5
+ resources :nodes do
6
+ collection do
7
+ get 'trash'
8
+ delete 'trash' => 'nodes#empty'
9
+ end
10
+ member do
11
+ post 'position'
12
+ put 'restore'
13
+ end
14
+ resources :nodes, only: [:index]
15
+ end
16
+
17
+ resources :assets, path: 'media' do
18
+ collection do
19
+ get 'trash'
20
+ delete 'trash' => 'assets#empty'
21
+ end
22
+ member do
23
+ put 'restore'
24
+ end
25
+ end
26
+
27
+ resources :users
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,15 @@
1
+ module PushType
2
+ module Api
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace PushType
5
+ engine_name 'push_type_api'
6
+
7
+ config.generators do |g|
8
+ g.assets false
9
+ g.helper false
10
+ g.test_framework :test_unit, fixture: false
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require 'push_type_core'
2
+
3
+ require 'jbuilder'
4
+ require 'kaminari'
5
+
6
+ module PushType
7
+ module Api
8
+ PushType.register_engine self, mount: 'api'
9
+ end
10
+ end
11
+
12
+ require 'push_type/api/engine'
@@ -0,0 +1 @@
1
+ require 'push_type/api'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :api do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,104 @@
1
+ require 'test_helper'
2
+
3
+ module PushType
4
+ class Api::AssetsControllerTest < ActionController::TestCase
5
+
6
+ let(:asset_attrs) { FactoryGirl.attributes_for(:asset) }
7
+ let(:asset) { FactoryGirl.create :asset }
8
+
9
+ describe 'GET #index' do
10
+ before do
11
+ 5.times { FactoryGirl.create :asset }
12
+ get :index
13
+ end
14
+ it { response.must_respond_with :success }
15
+ it { json_response['assets'].size.must_equal 5 }
16
+ it { json_response['meta'].must_be :present? }
17
+ it { json_response['meta']['current_page'].must_equal 1 }
18
+ end
19
+
20
+ describe 'GET #trash' do
21
+ before do
22
+ 2.times { FactoryGirl.create :asset }
23
+ 3.times { FactoryGirl.create :asset, deleted_at: Time.zone.now }
24
+ get :trash
25
+ end
26
+ it { response.must_respond_with :success }
27
+ it { json_response['assets'].size.must_equal 3 }
28
+ it { json_response['meta'].must_be :present? }
29
+ end
30
+
31
+ describe 'GET #show' do
32
+ before { get :show, params: { id: asset.id } }
33
+ it { response.must_respond_with :success }
34
+ it { json_response['asset'].must_be :present? }
35
+ it { json_response['asset']['id'].must_equal asset.id }
36
+ end
37
+
38
+ describe 'POST #create' do
39
+ before { @count = Asset.count }
40
+ describe 'with in-valid asset' do
41
+ before { post :create, params: { asset: {} } }
42
+ it { response.must_respond_with :unprocessable_entity }
43
+ it { json_response['errors'].must_be :present? }
44
+ end
45
+ describe 'with valid asset' do
46
+ before { post :create, params: { asset: asset_attrs } }
47
+ it { response.must_respond_with :created }
48
+ it { json_response['asset'].must_be :present? }
49
+ it { Asset.count.must_equal @count + 1 }
50
+ end
51
+ end
52
+
53
+ describe 'PUT #update' do
54
+ before { put :update, params: { id: asset.id, asset: { description: new_description } } }
55
+ describe 'with valid asset' do
56
+ let(:new_description) { 'Foo bar baz' }
57
+ it { response.must_respond_with :ok }
58
+ it { json_response['asset'].must_be :present? }
59
+ it { json_response['asset']['description'].must_equal new_description }
60
+ end
61
+ end
62
+
63
+ describe 'DELETE #destroy' do
64
+ describe 'with untrashed asset' do
65
+ before { delete :destroy, params: { id: asset.id } }
66
+ it { response.must_respond_with :ok }
67
+ it { json_response['asset'].must_be :present? }
68
+ it { json_response['asset']['is_trashed'].must_equal true }
69
+ it { asset.reload.must_be :trashed? }
70
+ end
71
+ describe 'with trashed asset' do
72
+ before do
73
+ asset.trash!
74
+ delete :destroy, params: { id: asset.id }
75
+ end
76
+ it { response.must_respond_with :no_content }
77
+ it { response.body.must_be :blank? }
78
+ it { proc { asset.reload }.must_raise ActiveRecord::RecordNotFound }
79
+ end
80
+ end
81
+
82
+ describe 'PUT #restore' do
83
+ before do
84
+ asset.trash!
85
+ put :restore, params: { id: asset.id }
86
+ end
87
+ it { response.must_respond_with :ok }
88
+ it { json_response['asset'].must_be :present? }
89
+ it { json_response['asset']['is_trashed'].must_equal false }
90
+ it { asset.reload.wont_be :trashed? }
91
+ end
92
+
93
+ describe 'DELETE #empty' do
94
+ before do
95
+ 3.times { FactoryGirl.create :asset, deleted_at: Time.zone.now }
96
+ delete :empty
97
+ end
98
+ it { response.must_respond_with :no_content }
99
+ it { response.body.must_be :blank? }
100
+ it { PushType::Asset.trashed.must_be :empty? }
101
+ end
102
+
103
+ end
104
+ end