archangel 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE.md +7 -15
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -5
- data/.gitignore +1 -0
- data/.hound.yml +2 -2
- data/.jshintignore +5 -0
- data/.jshintrc +28 -0
- data/.nvmrc +1 -0
- data/CONTRIBUTING.md +13 -114
- data/Gemfile +3 -3
- data/README.md +12 -37
- data/Rakefile +11 -0
- data/app/controllers/archangel/application_controller.rb +1 -2
- data/archangel.gemspec +3 -1
- data/bin/archangel +15 -0
- data/docs/Developers.md +122 -1
- data/docs/Extension/Controllers.md +139 -0
- data/docs/Extension/Developers.md +27 -0
- data/docs/Extension/Helpers.md +17 -0
- data/docs/Extension/Ideas.md +131 -0
- data/docs/Extension/Models.md +32 -0
- data/docs/Extension/Policies.md +42 -0
- data/docs/Extension/Routes.md +26 -0
- data/docs/Extension/Uploaders.md +3 -0
- data/docs/Extension/Views.md +3 -0
- data/docs/Release.md +9 -3
- data/docs/Theme/Developers.md +7 -0
- data/lib/archangel/command/extension.rb +97 -0
- data/lib/archangel/command/templates/extension/.editorconfig +19 -0
- data/lib/archangel/command/templates/extension/.gitignore +11 -0
- data/lib/archangel/command/templates/extension/.rspec +2 -0
- data/lib/archangel/command/templates/extension/.rubocop.yml +32 -0
- data/lib/archangel/command/templates/extension/Gemfile +29 -0
- data/lib/archangel/command/templates/extension/MIT-LICENSE +21 -0
- data/lib/archangel/command/templates/extension/README.md +79 -0
- data/lib/archangel/command/templates/extension/Rakefile +25 -0
- data/lib/archangel/command/templates/extension/app/assets/javascripts/archangel/auth/%extension_name%.js.tt +3 -0
- data/lib/archangel/command/templates/extension/app/assets/javascripts/archangel/backend/%extension_name%.js.tt +3 -0
- data/lib/archangel/command/templates/extension/app/assets/javascripts/archangel/frontend/%extension_name%.js.tt +3 -0
- data/lib/archangel/command/templates/extension/app/assets/stylesheets/archangel/auth/%extension_name%.css.tt +5 -0
- data/lib/archangel/command/templates/extension/app/assets/stylesheets/archangel/backend/%extension_name%.css.tt +5 -0
- data/lib/archangel/command/templates/extension/app/assets/stylesheets/archangel/frontend/%extension_name%.css.tt +5 -0
- data/lib/archangel/command/templates/extension/bin/rails.tt +11 -0
- data/lib/archangel/command/templates/extension/config/locales/en.yml.tt +4 -0
- data/lib/archangel/command/templates/extension/config/routes.rb +5 -0
- data/lib/archangel/command/templates/extension/extension.gemspec +25 -0
- data/lib/archangel/command/templates/extension/lib/%extension_name%/engine.rb.tt +29 -0
- data/lib/archangel/command/templates/extension/lib/%extension_name%/factories.rb.tt +13 -0
- data/lib/archangel/command/templates/extension/lib/%extension_name%/version.rb.tt +5 -0
- data/lib/archangel/command/templates/extension/lib/%extension_name%.rb.tt +9 -0
- data/lib/archangel/command/templates/extension/lib/generators/%extension_name%/install/install_generator.rb.tt +42 -0
- data/lib/archangel/command/templates/extension/spec/rails_helper.rb.tt +41 -0
- data/lib/archangel/command/templates/extension/spec/spec_helper.rb +22 -0
- data/lib/archangel/command/templates/extension/spec/support/.keep +0 -0
- data/lib/archangel/liquid/drop.rb +21 -11
- data/lib/archangel/liquid_view.rb +7 -31
- data/lib/archangel/version.rb +1 -1
- data/lib/generators/archangel/dummy/dummy_generator.rb +1 -0
- data/package.json +8 -3
- data/spec/lib/archangel/command/extension_spec.rb +100 -0
- data/spec/lib/archangel/liquid/drop_spec.rb +10 -0
- data/spec/lib/archangel/liquid/drops/page_drop_spec.rb +77 -0
- data/spec/lib/archangel/liquid/drops/site_drop_spec.rb +78 -0
- data/spec/lib/archangel/liquid/filters/link_to_filter_spec.rb +0 -4
- data/spec/lib/archangel/liquid/tags/collection_tag_spec.rb +0 -1
- data/spec/lib/archangel/liquid/tags/collectionfor_tag_spec.rb +0 -1
- data/spec/lib/archangel/liquid/tags/theme_javascript_tag_spec.rb +4 -3
- data/spec/lib/archangel/liquid/tags/theme_stylesheet_tag_spec.rb +4 -3
- metadata +64 -6
- data/docs/ExtensionDevelopers.md +0 -3
- data/docs/ExtensionIdeas.md +0 -132
- data/docs/ThemeDevelopers.md +0 -3
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ENGINE_ROOT = File.expand_path("../..", __FILE__)
|
4
|
+
ENGINE_PATH = File.expand_path("../../lib/<%= extension_name %>/engine", __FILE__)
|
5
|
+
|
6
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
|
7
|
+
|
8
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
9
|
+
|
10
|
+
require "rails/all"
|
11
|
+
require "rails/engine/commands"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
4
|
+
|
5
|
+
require "<%= extension_name %>/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.name = "<%= extension_name %>"
|
10
|
+
s.version = <%= class_name %>::VERSION
|
11
|
+
s.authors = ["Your Name"]
|
12
|
+
s.homepage = "https://github.com/USERNAME/<%= extension_name %>"
|
13
|
+
s.summary = "TODO: Summary of <%= class_name %>."
|
14
|
+
s.description = "TODO: Description of <%= class_name %>."
|
15
|
+
s.license = "MIT"
|
16
|
+
|
17
|
+
s.files = Dir[
|
18
|
+
"{app,config,db,lib}/**/*",
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"Rakefile",
|
21
|
+
"README.md"
|
22
|
+
]
|
23
|
+
|
24
|
+
s.add_dependency "archangel", "< 1.0"
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module <%= class_name %>
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
require "archangel"
|
6
|
+
|
7
|
+
isolate_namespace Archangel
|
8
|
+
engine_name "<%= extension_name %>"
|
9
|
+
|
10
|
+
config.generators do |gen|
|
11
|
+
gen.test_framework :rspec,
|
12
|
+
fixtures: false,
|
13
|
+
view_specs: false,
|
14
|
+
helper_specs: true,
|
15
|
+
routing_specs: false,
|
16
|
+
controller_specs: true,
|
17
|
+
request_specs: true
|
18
|
+
gen.fixture_replacement :factory_bot, dir: "spec/factories"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.activate
|
22
|
+
Dir[File.join(__dir__, "../../app/**/*_decorator*.rb")].each do |klass|
|
23
|
+
Rails.application.config.cache_classes ? require(klass) : load(klass)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
config.to_prepare(&method(:activate).to_proc)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Define your extensions Factories within this file to enable applications and
|
4
|
+
# other extensions to use and override them.
|
5
|
+
#
|
6
|
+
# Example adding this to your spec_helper will load these Factories for use:
|
7
|
+
# require "<%= extension_name %>/factories"
|
8
|
+
|
9
|
+
FactoryBot.define do
|
10
|
+
end
|
11
|
+
|
12
|
+
FactoryBot.modify do
|
13
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module <%= class_name %>
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
7
|
+
|
8
|
+
def add_javascripts
|
9
|
+
%w[auth backend frontend].each do |section|
|
10
|
+
append_file "vendor/assets/javascripts/archangel/#{section}.js",
|
11
|
+
"//= require archangel/#{section}/<%= extension_name %>\n"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_stylesheets
|
16
|
+
%w[auth backend frontend].each do |section|
|
17
|
+
inject_into_file "vendor/assets/stylesheets/archangel/#{section}.css",
|
18
|
+
"*= require archangel/#{section}/<%= extension_name %>\n ",
|
19
|
+
before: %r{\*/},
|
20
|
+
verbose: true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_migrations
|
25
|
+
run "bundle exec rails railties:install:migrations FROM=<%= extension_name %>"
|
26
|
+
end
|
27
|
+
|
28
|
+
def run_migrations
|
29
|
+
migration_message = "Would you like to run the migrations now? [Y/n]"
|
30
|
+
|
31
|
+
run_migrations = options[:auto_run_migrations] || ["", "y", "Y"]
|
32
|
+
.include?(ask(migration_message))
|
33
|
+
|
34
|
+
if run_migrations
|
35
|
+
run "bundle exec rails db:migrate"
|
36
|
+
else
|
37
|
+
puts "Skipping `rails db:migrate`, don't forget to run it!"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "simplecov"
|
4
|
+
|
5
|
+
SimpleCov.start :rails
|
6
|
+
|
7
|
+
ENV["RAILS_ENV"] ||= "test"
|
8
|
+
|
9
|
+
begin
|
10
|
+
require File.expand_path("dummy/config/environment", __dir__)
|
11
|
+
rescue LoadError
|
12
|
+
puts "Could not load test application. Run `bundle exec rake dummy_app` first"
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
if Rails.env.production?
|
17
|
+
abort("The Rails environment is running in production mode!")
|
18
|
+
end
|
19
|
+
|
20
|
+
require "spec_helper"
|
21
|
+
|
22
|
+
require "pry-byebug"
|
23
|
+
require "rspec/rails"
|
24
|
+
|
25
|
+
# Archangel support files
|
26
|
+
require "archangel/testing_support/support"
|
27
|
+
|
28
|
+
# Require factories defined in lib/<%= extension_name %>/factories.rb
|
29
|
+
require "<%= extension_name %>/factories"
|
30
|
+
|
31
|
+
# Local support files
|
32
|
+
Dir[Rails.root.join("../support/**/*.rb")].each { |f| require f }
|
33
|
+
|
34
|
+
RSpec.configure do |config|
|
35
|
+
config.color = true
|
36
|
+
config.mock_with :rspec
|
37
|
+
|
38
|
+
config.raise_errors_for_deprecations!
|
39
|
+
config.filter_rails_from_backtrace!
|
40
|
+
config.infer_spec_type_from_file_location!
|
41
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |expectations|
|
5
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
6
|
+
end
|
7
|
+
|
8
|
+
config.mock_with :rspec do |mocks|
|
9
|
+
mocks.verify_partial_doubles = true
|
10
|
+
end
|
11
|
+
|
12
|
+
config.filter_run :focus
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
|
15
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
16
|
+
|
17
|
+
config.disable_monkey_patching!
|
18
|
+
|
19
|
+
config.profile_examples = 10
|
20
|
+
|
21
|
+
config.order = :random
|
22
|
+
end
|
File without changes
|
@@ -60,26 +60,36 @@ module Archangel
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.associate(type, attrs)
|
63
|
-
options = attrs.extract_options!
|
64
63
|
self._associations = _associations.dup
|
65
64
|
|
65
|
+
associate_attributes(type, attrs)
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.associate_attributes(type, attrs)
|
69
|
+
options = attrs.extract_options!
|
70
|
+
|
66
71
|
attrs.each do |attr|
|
67
72
|
next if method_defined?(attr)
|
68
73
|
|
69
|
-
|
70
|
-
value = instance_variable_get("@_#{attr}")
|
71
|
-
return value if value
|
74
|
+
define_method_attribute(attr)
|
72
75
|
|
73
|
-
|
74
|
-
|
76
|
+
_associations[attr] = { type: type, options: options }
|
77
|
+
end
|
78
|
+
end
|
75
79
|
|
76
|
-
|
77
|
-
|
80
|
+
def self.define_method_attribute(attr)
|
81
|
+
options = attrs.extract_options!
|
78
82
|
|
79
|
-
|
80
|
-
|
83
|
+
define_method attr do
|
84
|
+
value = instance_variable_get("@_#{attr}")
|
85
|
+
return value if value
|
86
|
+
|
87
|
+
association = object.send(attr)
|
88
|
+
return nil if association.blank?
|
89
|
+
|
90
|
+
drop_instance = Archangel::Liquid::Drop.dropify(association, options)
|
81
91
|
|
82
|
-
|
92
|
+
instance_variable_set("@_#{attr}", drop_instance)
|
83
93
|
end
|
84
94
|
end
|
85
95
|
|
@@ -33,16 +33,20 @@ module Archangel
|
|
33
33
|
# @return [String] the rendered content
|
34
34
|
#
|
35
35
|
def render(template, local_assigns = {})
|
36
|
-
|
36
|
+
default_controller.headers["Content-Type"] ||= "text/html; charset=utf-8"
|
37
37
|
|
38
38
|
assigns = default_assigns(local_assigns)
|
39
|
-
options = {
|
39
|
+
options = { registers: default_registers }
|
40
40
|
|
41
41
|
Archangel::RenderService.call(template, assigns, options)
|
42
42
|
end
|
43
43
|
|
44
44
|
protected
|
45
45
|
|
46
|
+
def default_controller
|
47
|
+
@view.controller
|
48
|
+
end
|
49
|
+
|
46
50
|
def default_assigns(local_assigns)
|
47
51
|
assigns = @view.assigns
|
48
52
|
|
@@ -53,40 +57,12 @@ module Archangel
|
|
53
57
|
assigns.merge(local_assigns.stringify_keys)
|
54
58
|
end
|
55
59
|
|
56
|
-
def default_controller
|
57
|
-
@view.controller
|
58
|
-
end
|
59
|
-
|
60
|
-
def default_filters
|
61
|
-
extra_filters = []
|
62
|
-
|
63
|
-
controller_class = default_controller.class
|
64
|
-
|
65
|
-
if controller_class.respond_to?(:liquid_filters)
|
66
|
-
controller_class.liquid_filters.each do |method|
|
67
|
-
extra_filters.merge! default_controller.send(method)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
extra_filters
|
72
|
-
end
|
73
|
-
|
74
60
|
def default_registers
|
75
|
-
extra_registers = {}
|
76
|
-
|
77
|
-
controller_class = default_controller.class
|
78
|
-
|
79
|
-
if controller_class.respond_to?(:liquid_registers)
|
80
|
-
controller_class.liquid_registers.each do |method|
|
81
|
-
extra_registers.merge! default_controller.send(method)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
61
|
{
|
86
62
|
view: @view,
|
87
63
|
controller: default_controller,
|
88
64
|
helper: ActionController::Base.helpers
|
89
|
-
}
|
65
|
+
}
|
90
66
|
end
|
91
67
|
end
|
92
68
|
end
|
data/lib/archangel/version.rb
CHANGED
data/package.json
CHANGED
@@ -12,6 +12,10 @@
|
|
12
12
|
"ruby"
|
13
13
|
],
|
14
14
|
"license": "MIT",
|
15
|
+
"engines": {
|
16
|
+
"node": "8.11.1",
|
17
|
+
"yarn": "1.6.0"
|
18
|
+
},
|
15
19
|
"repository": {
|
16
20
|
"type": "git",
|
17
21
|
"url": "archangel/archangel"
|
@@ -26,8 +30,9 @@
|
|
26
30
|
"scripts": {
|
27
31
|
"test": "test"
|
28
32
|
},
|
33
|
+
"dependencies": {},
|
29
34
|
"devDependencies": {
|
30
|
-
"eslint": "^4.18.2"
|
31
|
-
|
32
|
-
|
35
|
+
"eslint": "^4.18.2",
|
36
|
+
"jshint": "^2.9.5"
|
37
|
+
}
|
33
38
|
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_helper"
|
4
|
+
require "archangel/command/extension"
|
5
|
+
|
6
|
+
module Archangel
|
7
|
+
module Command
|
8
|
+
RSpec.describe Extension do
|
9
|
+
describe "#extension" do
|
10
|
+
before { allow(STDOUT).to receive(:puts) }
|
11
|
+
|
12
|
+
let(:dummy_path) { "spec/dummy" }
|
13
|
+
|
14
|
+
context "when given an extension name" do
|
15
|
+
let(:extension_name) { "example" }
|
16
|
+
let(:extension_full_name) { "archangel_#{extension_name}" }
|
17
|
+
let(:extension_path) { "#{dummy_path}/#{extension_full_name}" }
|
18
|
+
|
19
|
+
before { before_generation(extension_name) }
|
20
|
+
|
21
|
+
after { after_generation(extension_path) }
|
22
|
+
|
23
|
+
it "should write common directories" do
|
24
|
+
%w[app bin config lib spec].each do |dir|
|
25
|
+
expect(glob_directories_in(extension_path)).to include(dir)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should write common files" do
|
30
|
+
%w[.editorconfig .gitignore .rspec .rubocop.yml Gemfile
|
31
|
+
MIT-LICENSE Rakefile README.md].each do |file|
|
32
|
+
expect(glob_files_in(extension_path)).to include(file)
|
33
|
+
end
|
34
|
+
|
35
|
+
expect(glob_files_in(extension_path))
|
36
|
+
.to include("#{extension_full_name}.gemspec")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when not given an extension name" do
|
41
|
+
let(:extension_name) { nil }
|
42
|
+
let(:extension_full_name) { "archangel_sample" }
|
43
|
+
let(:extension_path) { "#{dummy_path}/#{extension_full_name}" }
|
44
|
+
|
45
|
+
before { before_generation(extension_name) }
|
46
|
+
|
47
|
+
after { after_generation(extension_path) }
|
48
|
+
|
49
|
+
it "should write common files for `sample`" do
|
50
|
+
expect(glob_files_in(extension_path))
|
51
|
+
.to include("#{extension_full_name}.gemspec")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def before_generation(extension_name)
|
57
|
+
silence_output
|
58
|
+
|
59
|
+
Dir.chdir("spec/dummy") do
|
60
|
+
subject = Archangel::Command::Extension.new([extension_name])
|
61
|
+
subject.invoke_all
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def after_generation(extension_path)
|
66
|
+
enable_output
|
67
|
+
|
68
|
+
FileUtils.rm_rf("#{extension_path}/")
|
69
|
+
end
|
70
|
+
|
71
|
+
def glob_directories_in(extension_path)
|
72
|
+
Dir.glob("#{extension_path}/*")
|
73
|
+
.reject { |file| File.file?(file) }
|
74
|
+
.map { |file| File.basename(file) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def glob_files_in(extension_path)
|
78
|
+
Dir.glob("#{extension_path}/{.[^\.]*,*}")
|
79
|
+
.select { |file| File.file?(file) }
|
80
|
+
.map { |file| File.basename(file) }
|
81
|
+
end
|
82
|
+
|
83
|
+
def silence_output
|
84
|
+
@orig_stderr = $stderr
|
85
|
+
@orig_stdout = $stdout
|
86
|
+
|
87
|
+
$stderr = File.new("/dev/null", "w")
|
88
|
+
$stdout = File.new("/dev/null", "w")
|
89
|
+
end
|
90
|
+
|
91
|
+
def enable_output
|
92
|
+
$stderr = @orig_stderr
|
93
|
+
$stdout = @orig_stdout
|
94
|
+
|
95
|
+
@orig_stderr = nil
|
96
|
+
@orig_stdout = nil
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_helper"
|
4
|
+
|
5
|
+
module Archangel
|
6
|
+
module Liquid
|
7
|
+
module Drops
|
8
|
+
RSpec.describe PageDrop, type: :liquid_drop do
|
9
|
+
let(:resource) do
|
10
|
+
create(:page, title: "Test Page",
|
11
|
+
slug: "path-for-page",
|
12
|
+
meta_keywords: "keywords,for,page",
|
13
|
+
meta_description: "Description of page",
|
14
|
+
published_at: "2018-04-20 14:20:18")
|
15
|
+
end
|
16
|
+
let(:resource_drop) { described_class.new(resource) }
|
17
|
+
|
18
|
+
context "attributes" do
|
19
|
+
it "_attributes" do
|
20
|
+
expect(resource_drop.class._attributes)
|
21
|
+
.to eq(%i[meta_description meta_keywords published_at title])
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns correct attribute values" do
|
25
|
+
expect(resource_drop.meta_description).to eq("Description of page")
|
26
|
+
expect(resource_drop.meta_keywords).to eq("keywords,for,page")
|
27
|
+
expect(resource_drop.published_at).to eq("2018-04-20 14:20:18")
|
28
|
+
expect(resource_drop.title).to eq("Test Page")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns correct #id value" do
|
32
|
+
expect(resource_drop.id).to eq(resource.id.to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns correct #path value" do
|
36
|
+
expect(resource_drop.path).to eq("/path-for-page")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "#as_json" do
|
41
|
+
it "returns hash of attributes" do
|
42
|
+
json_object = {
|
43
|
+
meta_description: "Description of page",
|
44
|
+
meta_keywords: "keywords,for,page",
|
45
|
+
published_at: "2018-04-20T14:20:18.000Z",
|
46
|
+
title: "Test Page"
|
47
|
+
}
|
48
|
+
|
49
|
+
expect(resource_drop.as_json).to eq(json_object.as_json)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "#to_json" do
|
54
|
+
it "returns hash of attributes" do
|
55
|
+
json_object = {
|
56
|
+
meta_description: "Description of page",
|
57
|
+
meta_keywords: "keywords,for,page",
|
58
|
+
published_at: "2018-04-20T14:20:18.000Z",
|
59
|
+
title: "Test Page"
|
60
|
+
}
|
61
|
+
|
62
|
+
expect(resource_drop.to_json).to eq(json_object.to_json)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "#inspect" do
|
67
|
+
it "returns inspect string" do
|
68
|
+
expect(resource_drop.inspect)
|
69
|
+
.to include("#<Archangel::Liquid::Drops::PageDrop")
|
70
|
+
expect(resource_drop.inspect)
|
71
|
+
.to include("#<Archangel::Page")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_helper"
|
4
|
+
|
5
|
+
module Archangel
|
6
|
+
module Liquid
|
7
|
+
module Drops
|
8
|
+
RSpec.describe SiteDrop, type: :liquid_drop do
|
9
|
+
let(:resource) do
|
10
|
+
create(:site, name: "Test Site",
|
11
|
+
locale: "en",
|
12
|
+
meta_keywords: "keywords,for,site",
|
13
|
+
meta_description: "Description of site")
|
14
|
+
end
|
15
|
+
let(:resource_drop) { described_class.new(resource) }
|
16
|
+
|
17
|
+
context "attributes" do
|
18
|
+
it "_attributes" do
|
19
|
+
expect(resource_drop.class._attributes)
|
20
|
+
.to eq(%i[locale meta_description meta_keywords name])
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns correct attribute values" do
|
24
|
+
expect(resource_drop.locale).to eq("en")
|
25
|
+
expect(resource_drop.meta_description).to eq("Description of site")
|
26
|
+
expect(resource_drop.meta_keywords).to eq("keywords,for,site")
|
27
|
+
expect(resource_drop.name).to eq("Test Site")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns correct #favicon value" do
|
31
|
+
expect(resource_drop.favicon)
|
32
|
+
.to match(%r{/assets/archangel/fallback/favicon(.+).ico})
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns correct #logo value" do
|
36
|
+
expect(resource_drop.logo)
|
37
|
+
.to match(%r{/assets/archangel/fallback/logo(.+).png})
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "#as_json" do
|
42
|
+
it "returns hash of attributes" do
|
43
|
+
json_object = {
|
44
|
+
locale: "en",
|
45
|
+
meta_description: "Description of site",
|
46
|
+
meta_keywords: "keywords,for,site",
|
47
|
+
name: "Test Site"
|
48
|
+
}
|
49
|
+
|
50
|
+
expect(resource_drop.as_json).to eq(json_object.as_json)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "#to_json" do
|
55
|
+
it "returns hash of attributes" do
|
56
|
+
json_object = {
|
57
|
+
locale: "en",
|
58
|
+
meta_description: "Description of site",
|
59
|
+
meta_keywords: "keywords,for,site",
|
60
|
+
name: "Test Site"
|
61
|
+
}
|
62
|
+
|
63
|
+
expect(resource_drop.to_json).to eq(json_object.to_json)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "#inspect" do
|
68
|
+
it "returns inspect string" do
|
69
|
+
expect(resource_drop.inspect)
|
70
|
+
.to include("#<Archangel::Liquid::Drops::SiteDrop")
|
71
|
+
expect(resource_drop.inspect)
|
72
|
+
.to include("#<Archangel::Site")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|