lady_josephine 0.0.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/lady_josephine/editor_controller.rb +10 -4
- data/app/controllers/lady_josephine/images_controller.rb +6 -3
- data/app/helpers/lady_josephine/sir_trevor_helper.rb +60 -91
- data/app/models/lady_josephine/concerns/model.rb +3 -1
- data/app/models/lady_josephine/concerns/sir_trevor_images.rb +5 -7
- data/app/models/lady_josephine/image.rb +3 -2
- data/config/routes.rb +4 -4
- data/lib/lady_josephine/redcarpet/custom_markdown_formatter.rb +3 -0
- data/lib/lady_josephine/sir_trevor_view.rb +14 -0
- data/lib/lady_josephine/version.rb +1 -1
- data/lib/lady_josephine.rb +5 -0
- data/spec/controllers/lady_josephine/editor_controller_spec.rb +81 -57
- data/spec/controllers/lady_josephine/images_controller_spec.rb +35 -0
- data/spec/dummy/app/assets/images/depressed-cat.jpg +0 -0
- data/spec/dummy/app/models/article.rb +3 -0
- data/spec/dummy/app/models/user.rb +11 -0
- data/spec/dummy/config/environments/test.rb +1 -0
- data/spec/dummy/config/initializers/devise.rb +265 -0
- data/spec/dummy/config/locales/devise.en.yml +60 -0
- data/spec/dummy/config/routes.rb +3 -1
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20160307143232_create_articles.rb +9 -0
- data/spec/dummy/db/migrate/20160307143714_add_lady_josephine_to_articles.rb +9 -0
- data/spec/dummy/db/migrate/20160308091107_create_users.rb +10 -0
- data/spec/dummy/db/migrate/20160308131853_add_devise_to_users.rb +49 -0
- data/spec/dummy/db/schema.rb +44 -1
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +284 -0
- data/spec/dummy/log/test.log +19983 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/depressed-cat.jpg +0 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w1000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w2000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w300_depressed-cat.jpg +0 -0
- data/spec/dummy/public/storage/test/lady_josephine/image/file/1/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361805-21265-0640/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361805-21265-0640/w1000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361805-21265-0640/w300_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361805-21265-5269/w2000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361805-21265-8125/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361816-21343-4543/w2000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361816-21343-6347/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361816-21343-6347/w1000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361816-21343-6347/w300_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457361816-21343-7612/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515799-18442-6177/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515799-18442-6177/w1000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515799-18442-6177/w300_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515800-18442-3701/w2000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515800-18442-7909/w600_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515954-18760-0051/depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515954-18760-0051/w1000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515954-18760-0051/w300_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515955-18760-3846/w2000_depressed-cat.jpg +0 -0
- data/spec/dummy/public/uploads/tmp/1457515955-18760-7040/w600_depressed-cat.jpg +0 -0
- data/spec/helper/lady_josephine/helper_spec.rb +29 -0
- data/spec/helper/lady_josephine/sir_trevor_helper_spec.rb +166 -0
- data/spec/lib/redcarpet/custom_markdown_formatter_spec.rb +98 -0
- data/spec/lib/renderer/sir_trevor_renderer_spec.rb +27 -0
- data/spec/lib/whitelist_spec.rb +48 -0
- data/spec/models/lady_josephine/concerns/model_spec.rb +24 -0
- data/spec/models/lady_josephine/concerns/pingable_spec.rb +79 -0
- data/spec/models/lady_josephine/concerns/server_uuid_spec.rb +23 -0
- data/spec/models/lady_josephine/concerns/sir_trevor_images_spec.rb +50 -0
- data/spec/models/lady_josephine/image_spec.rb +68 -0
- data/spec/spec_helper.rb +4 -1
- metadata +125 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60a6a3687ea48331847dc71805138f3b6538caff
|
4
|
+
data.tar.gz: cc3f703f2ee2a6e7fdddc163a22802aa372b0442
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a3ff2974e150f88c654102fbd83740f1d892044309be6f4afbf59f8d069e5384156233c273493a6eae6458167ab86af4f0e0e0d054c5c3d1c73ec1b71af395b
|
7
|
+
data.tar.gz: debb9ad919884f916f89537a27e5671ecbb4735f0f52eca743125d4943616d67559b754ca97498ab0f096932d8b8abd4878b093a6c6f87e10d4eab12097bd9e9
|
@@ -12,9 +12,10 @@ module LadyJosephine
|
|
12
12
|
result[:ping][:state] = "CONFLICT"
|
13
13
|
end
|
14
14
|
|
15
|
-
result[:ping][:ping_date] = @resource.
|
16
|
-
result[:ping][:user_id] = @resource.
|
17
|
-
result[:ping][:user_name] = @resource.
|
15
|
+
result[:ping][:ping_date] = @resource.lady_josephine_ping_date
|
16
|
+
result[:ping][:user_id] = @resource.lady_josephine_ping_user.try :id
|
17
|
+
result[:ping][:user_name] = @resource.lady_josephine_ping_user.try :name
|
18
|
+
|
18
19
|
render json: result
|
19
20
|
end
|
20
21
|
end
|
@@ -28,7 +29,8 @@ module LadyJosephine
|
|
28
29
|
private
|
29
30
|
|
30
31
|
def find_resource
|
31
|
-
|
32
|
+
resource_class = whitelisted_class(params[:resource])
|
33
|
+
if (resource_class && @resource = resource_class.where(lady_josephine_server_uuid: params[:id]).first)
|
32
34
|
@resource
|
33
35
|
else
|
34
36
|
render nothing: true, status: 404
|
@@ -36,5 +38,9 @@ module LadyJosephine
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
41
|
+
def whitelisted_class(resource)
|
42
|
+
resource.capitalize.constantize if LadyJosephine::Whitelist.instance.is_whitelisted?(resource)
|
43
|
+
end
|
44
|
+
|
39
45
|
end
|
40
46
|
end
|
@@ -4,15 +4,18 @@ module LadyJosephine
|
|
4
4
|
def create
|
5
5
|
image = Image.from_params image_params
|
6
6
|
|
7
|
-
if image.save
|
7
|
+
if image && image.save
|
8
8
|
response = {file: {url: image.file.url}}
|
9
9
|
render json: response.as_json, status: 200
|
10
|
-
|
10
|
+
elsif image
|
11
11
|
render json: image.file.errors, status: 500
|
12
|
+
else
|
13
|
+
render json: { error: 'Could not save Image.'} , status: 500
|
12
14
|
end
|
13
|
-
|
14
15
|
end
|
15
16
|
|
17
|
+
private
|
18
|
+
|
16
19
|
def image_params
|
17
20
|
params.require(:attachment).permit([:name, :file])
|
18
21
|
params.require("block-uuid")
|
@@ -3,23 +3,12 @@ require 'redcarpet'
|
|
3
3
|
module LadyJosephine
|
4
4
|
module SirTrevorHelper
|
5
5
|
|
6
|
-
def render_sir_trevor(json, without_notes = true
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
options = {first: first_definition_block}
|
13
|
-
first_definition_block = false
|
14
|
-
render_sir_trevor_block(object, image_type, options)
|
15
|
-
else
|
16
|
-
render_sir_trevor_block(object, image_type)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
}.compact.join.html_safe
|
20
|
-
else
|
21
|
-
''
|
22
|
-
end
|
6
|
+
def render_sir_trevor(json, without_notes = true)
|
7
|
+
parse_sir_trevor(json).map do |object|
|
8
|
+
if object["data"]["note"] != "yes" || !without_notes
|
9
|
+
render_sir_trevor_block(object)
|
10
|
+
end
|
11
|
+
end.compact.join.html_safe
|
23
12
|
end
|
24
13
|
|
25
14
|
def component_attributes_for(block, classes)
|
@@ -50,82 +39,74 @@ module LadyJosephine
|
|
50
39
|
tag "img", options.merge(:src => src, :srcset => srcset, :sizes => sizes)
|
51
40
|
end
|
52
41
|
|
53
|
-
def protocol_relative(path)
|
54
|
-
path.gsub(/\Ahttps?:/, '')
|
55
|
-
end
|
56
|
-
|
57
42
|
def sir_trevor_video(block)
|
58
|
-
|
59
43
|
if block["source"] == "youtube"
|
60
|
-
|
61
|
-
options = {
|
62
|
-
frameborder: 0,
|
63
|
-
wmode: nil,
|
64
|
-
autoplay: false,
|
65
|
-
hide_related: true,
|
66
|
-
showinfo: 0,
|
67
|
-
color: "white",
|
68
|
-
modestbranding: 1,
|
69
|
-
iv_load_policy: 3,
|
70
|
-
theme: "light",
|
71
|
-
fullscreen: block["note"] == "yes" ? 0 : 1
|
72
|
-
}
|
73
|
-
|
74
|
-
src = "//www.youtube.com/embed/#{block['remote_id']}"
|
75
|
-
|
76
|
-
params = []
|
77
|
-
params << "wmode=#{options[:wmode]}" if options[:wmode]
|
78
|
-
params << "autoplay=1" if options[:autoplay]
|
79
|
-
params << "rel=0" if options[:hide_related]
|
80
|
-
params << "showinfo=#{options[:showinfo]}" if options[:showinfo]
|
81
|
-
params << "modestbranding=#{options[:modestbranding]}" if options[:modestbranding]
|
82
|
-
params << "color=#{options[:color]}" if options[:color]
|
83
|
-
params << "iv_load_policy=#{options[:iv_load_policy]}" if options[:iv_load_policy]
|
84
|
-
params << "theme=#{options[:theme]}" if options[:theme]
|
85
|
-
params << "fs=#{options[:fullscreen]}" if options[:fullscreen]
|
86
|
-
|
87
|
-
src += "?#{params.join '&'}" unless params.empty?
|
88
|
-
|
89
|
-
%{<div class="ratio-container youtube-block" data-youtube-url=#{src} data-video-id=#{block['remote_id']}></div>}
|
90
|
-
|
91
|
-
|
44
|
+
sir_trevor_video_youtube(block)
|
92
45
|
elsif block["source"] == "vimeo"
|
46
|
+
sir_trevor_video_vimeo(block)
|
47
|
+
else
|
48
|
+
""
|
49
|
+
end
|
50
|
+
end
|
93
51
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
show_portrait: false,
|
98
|
-
frameborder: 0
|
99
|
-
}
|
100
|
-
|
101
|
-
|
102
|
-
frameborder = options[:frameborder] || 0
|
103
|
-
src = "//player.vimeo.com/video/#{block['remote_id']}"
|
104
|
-
|
105
|
-
params = []
|
106
|
-
|
107
|
-
params << "title=0" unless options[:show_title]
|
108
|
-
params << "byline=0" if options[:autoplay]
|
109
|
-
params << "portrait=0" if options[:hide_related]
|
52
|
+
def image_display_width(metadata, height = 620)
|
53
|
+
(metadata["w2000"]["ratio"] * height).round
|
54
|
+
end
|
110
55
|
|
111
|
-
|
56
|
+
private
|
112
57
|
|
113
|
-
|
58
|
+
def sir_trevor_video_youtube(block)
|
59
|
+
params = {
|
60
|
+
frameborder: 0,
|
61
|
+
wmode: nil,
|
62
|
+
autoplay: 1,
|
63
|
+
rel: 0, # hide related
|
64
|
+
showinfo: 0,
|
65
|
+
color: "white",
|
66
|
+
modestbranding: 1,
|
67
|
+
iv_load_policy: 3,
|
68
|
+
theme: "light",
|
69
|
+
fs: block["note"] == "yes" ? 0 : 1, # fullscreen
|
70
|
+
rel: 0
|
71
|
+
}
|
72
|
+
|
73
|
+
src = join_url_with_params("//www.youtube.com/embed/#{block['remote_id']}", params)
|
74
|
+
|
75
|
+
content_tag "div", "", {
|
76
|
+
"class" => "ratio-container youtube-block",
|
77
|
+
"data-youtube-url" => src,
|
78
|
+
"data-video-id" => block['remote_id']
|
79
|
+
}
|
80
|
+
end
|
114
81
|
|
115
|
-
|
82
|
+
def sir_trevor_video_vimeo(block)
|
83
|
+
params = {
|
84
|
+
title: 0,
|
85
|
+
byline: 0, # autoplay
|
86
|
+
portrait: 0, # hide related
|
87
|
+
}
|
116
88
|
|
117
|
-
|
89
|
+
src = join_url_with_params("//player.vimeo.com/video/#{block['remote_id']}", params)
|
118
90
|
|
119
|
-
|
91
|
+
content_tag "div", "", {
|
92
|
+
"class" => "ratio-container vimeo-block",
|
93
|
+
"data-vimeo-url" => src,
|
94
|
+
"data-video-id" => block['remote_id']
|
95
|
+
}
|
96
|
+
end
|
120
97
|
|
98
|
+
def join_url_with_params(url, params)
|
99
|
+
"#{url}?#{params.map{|k,v| "#{k}=#{v}"}.join('&')}"
|
121
100
|
end
|
122
101
|
|
123
|
-
|
102
|
+
def protocol_relative(path)
|
103
|
+
path.gsub(/\Ahttps?:/, '')
|
104
|
+
end
|
124
105
|
|
125
106
|
def parse_sir_trevor(json)
|
126
107
|
hash = JSON.parse(json)
|
127
108
|
|
128
|
-
return
|
109
|
+
return [] unless hash.has_key?("data")
|
129
110
|
digest hash["data"]
|
130
111
|
end
|
131
112
|
|
@@ -157,21 +138,9 @@ module LadyJosephine
|
|
157
138
|
|
158
139
|
end
|
159
140
|
|
160
|
-
def render_sir_trevor_block(object,
|
161
|
-
context = Class.new(ActionView::Base) do
|
162
|
-
include ActionView::RoutingUrlFor
|
163
|
-
include ApplicationHelper
|
164
|
-
include Rails.application.routes.url_helpers
|
165
|
-
include Rails.application.routes.mounted_helpers
|
166
|
-
include SirTrevorHelper
|
167
|
-
|
168
|
-
def default_url_options
|
169
|
-
{}
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
141
|
+
def render_sir_trevor_block(object, options = {})
|
173
142
|
view_name = "lady_josephine/blocks/_#{object['type'].to_s.downcase}_block"
|
174
|
-
view =
|
143
|
+
view = LadyJosephine::SirTrevorView.new(["#{Rails.root}/app/views", "#{__FILE__}/../../../views"], {})
|
175
144
|
view.render(template: view_name, locals: {
|
176
145
|
:block => object['data'],
|
177
146
|
:options => options
|
@@ -9,10 +9,12 @@ module LadyJosephine
|
|
9
9
|
include ServerUuid
|
10
10
|
include SirTrevorImages
|
11
11
|
|
12
|
+
belongs_to :lady_josephine_ping_user, class_name: LadyJosephine.user_class_name
|
13
|
+
|
12
14
|
LadyJosephine::Whitelist.instance.whitelist(self)
|
13
15
|
|
14
16
|
def content_data_hash
|
15
|
-
if self.content_data.present?
|
17
|
+
if self.content_data.present? && !(self.content_data == "{}")
|
16
18
|
JSON.parse(self.content_data)
|
17
19
|
else
|
18
20
|
{"server_uuid" => nil}
|
@@ -3,7 +3,7 @@ module LadyJosephine
|
|
3
3
|
module SirTrevorImages
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
included do
|
6
|
+
included do
|
7
7
|
|
8
8
|
def images
|
9
9
|
files = []
|
@@ -13,26 +13,24 @@ module LadyJosephine
|
|
13
13
|
files << block["data"]["file"]["medium"]
|
14
14
|
files << block["data"]["file"]["small"]
|
15
15
|
end
|
16
|
-
files.map { |f| f["url"
|
16
|
+
files.map { |f| f.try :[], "url" }.compact
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def image_blocks
|
22
|
-
|
22
|
+
return [] if sir_trevor_unwrap_column["data"].nil?
|
23
|
+
sir_trevor_unwrap_column["data"].select do |block|
|
23
24
|
block['type'] == 'extended_image'
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
|
-
end
|
28
|
-
|
29
|
-
class_methods do
|
30
|
-
|
31
28
|
def sir_trevor_unwrap_column
|
32
29
|
JSON.parse(self.content_data || "{}")
|
33
30
|
end
|
34
31
|
|
35
32
|
end
|
33
|
+
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
@@ -9,8 +9,9 @@ module LadyJosephine
|
|
9
9
|
before_save :update_file_metadata
|
10
10
|
|
11
11
|
def self.from_params(params)
|
12
|
-
uploadable_type = params["model-name"]
|
13
|
-
|
12
|
+
uploadable_type = allowed_class_name params["model-name"]
|
13
|
+
return nil if uploadable_type.nil?
|
14
|
+
|
14
15
|
uploadable_uuid = params["article-uuid"]
|
15
16
|
uploadable_attribute = params["column-name"]
|
16
17
|
uploadable_id = uploadable_type.constantize.find_by(lady_josephine_server_uuid: uploadable_uuid).try :id
|
data/config/routes.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
LadyJosephine::Engine.routes.draw do
|
2
2
|
resources :images, only: [:create]
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
controller :editor do
|
5
|
+
get 'content/:resource/:id/version' => :version
|
6
|
+
post 'content/:resource/:id/ping' => :ping, as: "ping"
|
7
|
+
end
|
8
8
|
|
9
9
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module LadyJosephine
|
2
|
+
class SirTrevorView < ActionView::Base
|
3
|
+
include ActionView::RoutingUrlFor
|
4
|
+
include ApplicationHelper
|
5
|
+
include Rails.application.routes.url_helpers
|
6
|
+
include Rails.application.routes.mounted_helpers
|
7
|
+
include SirTrevorHelper
|
8
|
+
|
9
|
+
def default_url_options
|
10
|
+
{}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/lib/lady_josephine.rb
CHANGED
@@ -12,7 +12,12 @@ module LadyJosephine
|
|
12
12
|
autoload :CustomMarkdownFormatter, 'lady_josephine/redcarpet/custom_markdown_formatter'
|
13
13
|
end
|
14
14
|
|
15
|
+
autoload :SirTrevorView, 'lady_josephine/sir_trevor_view'
|
16
|
+
|
15
17
|
mattr_accessor :mount_path
|
16
18
|
@@mount_path = "/josephine"
|
17
19
|
|
20
|
+
mattr_accessor :user_class_name
|
21
|
+
@@user_class_name = "User"
|
22
|
+
|
18
23
|
end
|
@@ -1,58 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
1
2
|
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
3
|
+
describe LadyJosephine::EditorController, type: :controller do
|
4
|
+
include Devise::TestHelpers
|
5
|
+
routes { LadyJosephine::Engine.routes }
|
6
|
+
|
7
|
+
let(:article) { Article.create title: "Local man thinks wrestling is real", content_data_hash: { "uuid" => "uuid-uuid-uuid", "version" => "1.0" } }
|
8
|
+
|
9
|
+
describe '#version' do
|
10
|
+
|
11
|
+
it 'returns 404 if article was not found' do
|
12
|
+
get :version, id: "not-found", resource: 'article'
|
13
|
+
expect(response.status).to eql 404
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns the version if article was found' do
|
17
|
+
get :version, id: article.lady_josephine_server_uuid, resource: 'article'
|
18
|
+
json = JSON.parse(response.body)
|
19
|
+
|
20
|
+
expect(response.status).to eql 200
|
21
|
+
expect(json["lady_josephine_server_version"]).to eq "1.0"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#ping' do
|
26
|
+
let(:user) { User.create first_name: "Homer", email: "homer@simpson.com", password: "springfield", password_confirmation: "springfield" }
|
27
|
+
let(:admin) { User.create first_name: "Marge", email: "marge@simpson.com", password: "springfield", password_confirmation: "springfield" }
|
28
|
+
|
29
|
+
before do
|
30
|
+
sign_in :user, user
|
31
|
+
end
|
32
|
+
|
33
|
+
after do
|
34
|
+
Timecop.return
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns 404 if article was not found' do
|
38
|
+
post :ping, id: "not-found", resource: 'article'
|
39
|
+
expect(response.status).to eql 404
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'updates the user if the time was okay' do
|
43
|
+
post :ping, id: article.lady_josephine_server_uuid, resource: 'article'
|
44
|
+
json = JSON.parse(response.body)
|
45
|
+
expect(response.status).to eql 200
|
46
|
+
expect(json["ping"]["state"]).to eq "OK"
|
47
|
+
expect(json["ping"]["user_id"]).to eq user.id
|
48
|
+
expect(json["ping"]["user_name"]).to eq user.name
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'updates the user if it was forced' do
|
52
|
+
Timecop.freeze(Time.local(2014, 10, 10, 1, 0, 15))
|
53
|
+
article.lady_josephine_ping_date = Time.local(2014, 10, 10, 1, 0, 0)
|
54
|
+
article.lady_josephine_ping_user = admin
|
55
|
+
article.save
|
56
|
+
|
57
|
+
post :ping, id: article.lady_josephine_server_uuid, update: "force", resource: 'article'
|
58
|
+
|
59
|
+
json = JSON.parse(response.body)
|
60
|
+
expect(response.status).to eql 200
|
61
|
+
expect(json["ping"]["state"]).to eq "OK"
|
62
|
+
expect(json["ping"]["user_id"]).to eq user.id
|
63
|
+
expect(json["ping"]["user_name"]).to eq user.name
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'does not update the user if another one edits the content' do
|
67
|
+
Timecop.freeze(Time.local(2014, 10, 10, 1, 0, 15))
|
68
|
+
article.lady_josephine_ping_date = Time.local(2014, 10, 10, 1, 0, 0)
|
69
|
+
article.lady_josephine_ping_user = admin
|
70
|
+
article.save
|
71
|
+
|
72
|
+
post :ping, id: article.lady_josephine_server_uuid, resource: 'article'
|
73
|
+
|
74
|
+
json = JSON.parse(response.body)
|
75
|
+
expect(response.status).to eql 200
|
76
|
+
expect(json["ping"]["state"]).to eq "CONFLICT"
|
77
|
+
expect(json["ping"]["user_id"]).to eq admin.id
|
78
|
+
expect(json["ping"]["user_name"]).to eq admin.name
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LadyJosephine::ImagesController, type: :controller do
|
4
|
+
include Devise::TestHelpers
|
5
|
+
routes { LadyJosephine::Engine.routes }
|
6
|
+
|
7
|
+
let(:article) { Article.create title: "Local man thinks wrestling is real", content_data_hash: { "uuid" => "uuid-uuid-uuid", "version" => "1.0" } }
|
8
|
+
|
9
|
+
describe '#create' do
|
10
|
+
|
11
|
+
let(:file) { fixture_file_upload('spec/dummy/app/assets/images/depressed-cat.jpg', 'image/jpeg') }
|
12
|
+
|
13
|
+
it 'should return an error if the object can´t be saved' do
|
14
|
+
expect {
|
15
|
+
post :create, attachment: { name: 'file.jpg', file: file}, "block-uuid" => "uuid-uuid-uuid", "article-uuid" => article.lady_josephine_server_uuid, "model-name" => "NotAllowed", "column-name" => "content-data"
|
16
|
+
expect(response.status).to eq 500
|
17
|
+
}.to change { LadyJosephine::Image.count }.by 0
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should save an image' do
|
21
|
+
expect {
|
22
|
+
post :create, attachment: { name: 'file.jpg', file: file}, "block-uuid" => "uuid-uuid-uuid", "article-uuid" => article.lady_josephine_server_uuid, "model-name" => "article", "column-name" => "content-data"
|
23
|
+
expect(response.status).to eq 200
|
24
|
+
}.to change { LadyJosephine::Image.count }.by 1
|
25
|
+
image = LadyJosephine::Image.last
|
26
|
+
expect(image.block_uuid).to eq "uuid-uuid-uuid"
|
27
|
+
expect(image.file.file.basename).to eq "depressed-cat"
|
28
|
+
expect(image.uploadable_type).to eq "Article"
|
29
|
+
expect(image.uploadable_id).to eq article.id
|
30
|
+
expect(image.uploadable_attribute).to eq "content-data"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
Binary file
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
# Include default devise modules. Others available are:
|
3
|
+
# :confirmable, :lockable, :timeoutable and :omniauthable
|
4
|
+
devise :database_authenticatable, :registerable,
|
5
|
+
:recoverable, :rememberable, :trackable, :validatable
|
6
|
+
|
7
|
+
def name
|
8
|
+
self.first_name
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
@@ -30,6 +30,7 @@ Rails.application.configure do
|
|
30
30
|
# The :test delivery method accumulates sent emails in the
|
31
31
|
# ActionMailer::Base.deliveries array.
|
32
32
|
config.action_mailer.delivery_method = :test
|
33
|
+
config.action_mailer.default_url_options = { :host => 'http://0.0.0.0:3000' }
|
33
34
|
|
34
35
|
# Randomize the order test cases are executed.
|
35
36
|
config.active_support.test_order = :random
|