lazy_render 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +35 -0
- data/app/assets/javascripts/lazy_render.js +86 -0
- data/app/controllers/lazy_render/application_controller.rb +4 -0
- data/app/controllers/lazy_render/lazyload_controller.rb +27 -0
- data/app/helpers/lazy_render/application_helper.rb +4 -0
- data/app/helpers/lazy_render/lazyload_helper.rb +12 -0
- data/config/routes.rb +2 -0
- data/lib/lazy_render.rb +4 -0
- data/lib/lazy_render/engine.rb +17 -0
- data/lib/lazy_render/rails/routes.rb +11 -0
- data/lib/lazy_render/version.rb +3 -0
- data/lib/tasks/lazy_render_tasks.rake +4 -0
- data/spec/controllers/lazy_render/lazy_render_controller_spec.rb +7 -0
- data/spec/features/lazy_render_spec.rb +12 -0
- data/spec/helpers/lazy_render/lazy_render_helper_spec.rb +37 -0
- data/spec/rails_helper.rb +65 -0
- data/spec/spec_helper.rb +85 -0
- data/spec/test_app/README.rdoc +28 -0
- data/spec/test_app/Rakefile +6 -0
- data/spec/test_app/app/assets/javascripts/application.js +14 -0
- data/spec/test_app/app/assets/javascripts/top.js +2 -0
- data/spec/test_app/app/assets/stylesheets/application.css +15 -0
- data/spec/test_app/app/assets/stylesheets/top.css +4 -0
- data/spec/test_app/app/controllers/application_controller.rb +3 -0
- data/spec/test_app/app/controllers/lazy_render_controller.rb +20 -0
- data/spec/test_app/app/controllers/top_controller.rb +5 -0
- data/spec/test_app/app/helpers/application_helper.rb +2 -0
- data/spec/test_app/app/helpers/top_helper.rb +2 -0
- data/spec/test_app/app/views/layouts/application.html.erb +14 -0
- data/spec/test_app/app/views/lazy_render/directory/separator.html.erb +1 -0
- data/spec/test_app/app/views/lazy_render/lazy_render_message.erb +1 -0
- data/spec/test_app/app/views/lazy_render/pass_variables.html.erb +3 -0
- data/spec/test_app/app/views/lazy_render/with_cache.html.erb +1 -0
- data/spec/test_app/app/views/top/index.html.erb +10 -0
- data/spec/test_app/bin/bundle +3 -0
- data/spec/test_app/bin/rails +4 -0
- data/spec/test_app/bin/rake +4 -0
- data/spec/test_app/bin/setup +29 -0
- data/spec/test_app/config.ru +4 -0
- data/spec/test_app/config/application.rb +32 -0
- data/spec/test_app/config/boot.rb +5 -0
- data/spec/test_app/config/database.yml +25 -0
- data/spec/test_app/config/environment.rb +5 -0
- data/spec/test_app/config/environments/development.rb +41 -0
- data/spec/test_app/config/environments/production.rb +77 -0
- data/spec/test_app/config/environments/test.rb +42 -0
- data/spec/test_app/config/initializers/assets.rb +11 -0
- data/spec/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_app/config/initializers/cookies_serializer.rb +3 -0
- data/spec/test_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/test_app/config/initializers/inflections.rb +16 -0
- data/spec/test_app/config/initializers/mime_types.rb +4 -0
- data/spec/test_app/config/initializers/session_store.rb +3 -0
- data/spec/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/test_app/config/locales/en.yml +23 -0
- data/spec/test_app/config/routes.rb +6 -0
- data/spec/test_app/config/secrets.yml +22 -0
- data/spec/test_app/db/development.sqlite3 +0 -0
- data/spec/test_app/db/test.sqlite3 +0 -0
- data/spec/test_app/log/development.log +7653 -0
- data/spec/test_app/log/test.log +1016 -0
- data/spec/test_app/public/404.html +67 -0
- data/spec/test_app/public/422.html +67 -0
- data/spec/test_app/public/500.html +66 -0
- data/spec/test_app/public/favicon.ico +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/00272fd19a8b4c0b9a39530bbbab5297 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/2264adc899f96543c428cfa5ea10a56e +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/3ae6b7240df45c36072cdfc2a938d371 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/3f6588cfc4ab8be6b895ced355b68237 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/47e29de0d0b86abfd1a7a642e831b38d +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/4ae6ca0c43b13f0916cc8f713e275340 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/54c9edf6a60105ecf4f77d5474ba5b62 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/564539767c65b6dc89551fa0d318c10d +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/7dbf920d7f8be0c6b5a47013fbd7bd3f +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/a5687170edcfd6c1f958b81b98cc81f0 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/b0584c2a6fc69cfed2ac56e6d420e386 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/b15997c563f5d6fd7154a6020444fb91 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/b8c3a3f677a445f0a64c3c4571d4f8c3 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/dec6dbe6a23cb41da2ab318fa1d721c6 +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/eeba9ea8ded55ed7b2e07940510427bf +0 -0
- data/spec/test_app/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/2264adc899f96543c428cfa5ea10a56e +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/3f6588cfc4ab8be6b895ced355b68237 +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/47e29de0d0b86abfd1a7a642e831b38d +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/54c9edf6a60105ecf4f77d5474ba5b62 +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/7dbf920d7f8be0c6b5a47013fbd7bd3f +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/b15997c563f5d6fd7154a6020444fb91 +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/test_app/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/test_app/tmp/capybara/capybara-201411121831185043376786.html +18 -0
- data/spec/test_app/tmp/capybara/capybara-201411121833083203391609.html +18 -0
- data/spec/test_app/tmp/capybara/capybara-20141112183344242334446.html +18 -0
- data/spec/test_app/tmp/pids/server.pid +1 -0
- metadata +335 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 162bcd81c6d2834ceb78bcba7ac6dc01d288ae39
|
4
|
+
data.tar.gz: 5f0140f4a30735176c8d082383c61f1d09ac97a6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a50a4c9a59a3a7a276ef5715836d66715fb41ab13803297f068c963556a65efe6fd5fde8c1fff3bf06ec7fba43081d6345b461ae94901ef6283919f6ce5bbb8
|
7
|
+
data.tar.gz: 39e5dd6a341c1aafb90f974d9c1dc857c9ac7863636e7158995b67613d5cb2dccb314b6c99459184ad1e30a10187526acd1ea49174a7017caf75f01d84d1a4af
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 vexus2
|
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/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'LazyRender'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
26
|
+
|
27
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
|
32
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
33
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
34
|
+
task :default => :spec
|
35
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
//= require jquery
|
2
|
+
|
3
|
+
var LazyRender = {
|
4
|
+
load : function (context) {
|
5
|
+
var lazy_renders = [];
|
6
|
+
var lazy_render_elms = [];
|
7
|
+
$('[class^=js-lazy-render]', context).each(function () {
|
8
|
+
var param = {
|
9
|
+
name : $(this).data('lazy-render-name'),
|
10
|
+
locals : $(this).data('lazy-render-params'),
|
11
|
+
cache : $(this).data('lazy-render-cache'),
|
12
|
+
version : $(this).data('lazy-render-version'),
|
13
|
+
callback : $(this).data('lazy-render-callback')
|
14
|
+
};
|
15
|
+
if (param['cache']) {
|
16
|
+
var cache = LazyRender.cache_read(param['name'] + $(this).attr('data-lazy-render-lazy_renders'), param['version']);
|
17
|
+
if (cache) {
|
18
|
+
LazyRender.apply(this, param, cache);
|
19
|
+
return;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
lazy_render_elms[lazy_render_elms.length] = this;
|
23
|
+
lazy_renders.push(param);
|
24
|
+
});
|
25
|
+
$.ajax({
|
26
|
+
type : 'post',
|
27
|
+
url : '/lazy_render/load',
|
28
|
+
data : {
|
29
|
+
lazy_renders : lazy_renders,
|
30
|
+
referrer : document.referrer ? document.referrer : ''
|
31
|
+
},
|
32
|
+
cache : false,
|
33
|
+
dataType : 'json',
|
34
|
+
success : function (result) {
|
35
|
+
$(lazy_renders).each(function (i, lazy_render) {
|
36
|
+
LazyRender.apply(lazy_render_elms[i], lazy_render, result[i]);
|
37
|
+
if (lazy_render['cache']) {
|
38
|
+
LazyRender.cache_write(result[i], lazy_render['name'] + $(lazy_render_elms[i]).attr('data-lazy-render-lazy_renders'), lazy_render['version'], lazy_render['cache']);
|
39
|
+
}
|
40
|
+
});
|
41
|
+
}
|
42
|
+
});
|
43
|
+
},
|
44
|
+
apply : function (elm, data, html) {
|
45
|
+
if ($(elm).data('lazy-render-replace') == 'inner') {
|
46
|
+
$(elm).html(html);
|
47
|
+
} else {
|
48
|
+
$(elm).replaceWith(html);
|
49
|
+
}
|
50
|
+
if (data['callback']) {
|
51
|
+
eval(data['callback'] + '(data, elm);');
|
52
|
+
}
|
53
|
+
},
|
54
|
+
cache_storage_prefix : 'lazy_render_cache_',
|
55
|
+
cache_storage_key : function (key) {
|
56
|
+
return location.protocol + this.cache_storage_prefix + key;
|
57
|
+
},
|
58
|
+
cache_read : function (key, version) {
|
59
|
+
if (typeof sessionStorage == 'undefined' || typeof JSON == 'undefined') return false;
|
60
|
+
if (location.search.match('cacheclear=1')) return false;
|
61
|
+
try {
|
62
|
+
var cache = JSON.parse(sessionStorage[this.cache_storage_key(key)]);
|
63
|
+
if (!cache) return false;
|
64
|
+
var now = new Date / 1e3 | 0;
|
65
|
+
return cache['expire'] > now && cache['version'] == version ? cache['data'] : false;
|
66
|
+
}catch (e) {
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
},
|
70
|
+
cache_write : function (data, key, version, lifetimesec) {
|
71
|
+
if (typeof sessionStorage == 'undefined' || typeof JSON == 'undefined') return false;
|
72
|
+
sessionStorage[this.cache_storage_key(key)] = JSON.stringify({
|
73
|
+
data : data,
|
74
|
+
version : version,
|
75
|
+
expire : (new Date / 1e3 | 0) + lifetimesec
|
76
|
+
});
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
};
|
80
|
+
|
81
|
+
|
82
|
+
$(function () {
|
83
|
+
if ($('[class^=js-lazy-render]').length > 0) {
|
84
|
+
LazyRender.load(document);
|
85
|
+
}
|
86
|
+
});
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_dependency 'lazy_render/application_controller'
|
2
|
+
|
3
|
+
module LazyRender
|
4
|
+
class LazyloadController < ApplicationController
|
5
|
+
protect_from_forgery with: :null_session
|
6
|
+
|
7
|
+
def load
|
8
|
+
return unless params['lazy_renders']
|
9
|
+
result = []
|
10
|
+
@data = {}
|
11
|
+
params['lazy_renders'].values.each do |v|
|
12
|
+
next unless v['name']
|
13
|
+
data = {
|
14
|
+
name: v['name'],
|
15
|
+
locals: v['locals'] || {}
|
16
|
+
}
|
17
|
+
data[:locals].empty? ? send(data[:name]) : send(data[:name], data[:locals])
|
18
|
+
# TODO: Add Benchmark time
|
19
|
+
html = render_to_string 'lazy_render/' + data[:name].gsub('__', '/'), layout: false, locals: { data: @data || {} }
|
20
|
+
result << html
|
21
|
+
end
|
22
|
+
|
23
|
+
render json: result
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module LazyRender
|
2
|
+
module LazyloadHelper
|
3
|
+
def lazy_render(name, locals: {}, cache: false, callback: false)
|
4
|
+
data = {'lazy-render-name' => name}
|
5
|
+
data['lazy-render-params'] = locals if locals.instance_of?(Hash) && locals.presence
|
6
|
+
data['lazy-render-cache'] = cache.to_i if cache
|
7
|
+
data['lazy-render-callback'] = callback if callback
|
8
|
+
content_tag :span, nil, class: "js-lazy-render-#{name}", data: data
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
data/config/routes.rb
ADDED
data/lib/lazy_render.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'lazy_render/rails/routes'
|
2
|
+
module LazyRender
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
isolate_namespace LazyRender
|
5
|
+
|
6
|
+
initializer 'lazy_render.lazyload_controller' do |app|
|
7
|
+
ActiveSupport.on_load :lazyload_controller do
|
8
|
+
helper LazyRender::LazyloadHelper
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
config.generators do |g|
|
13
|
+
g.test_framework :rspec
|
14
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'active_support/core_ext/object/try'
|
2
|
+
require 'active_support/core_ext/hash/slice'
|
3
|
+
|
4
|
+
module ActionDispatch::Routing
|
5
|
+
class Mapper
|
6
|
+
def lazy_render_for(path, *block)
|
7
|
+
options = block.extract_options!
|
8
|
+
match "#{path}", to: "#{options[:to]}#load", via: 'post'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'LazyRender', :type => :feature, js: true do
|
4
|
+
before { visit root_path; sleep 1 }
|
5
|
+
describe 'is show lazy_render messages after secs' do
|
6
|
+
it { expect(page).to have_content('LazyRender Message') }
|
7
|
+
it { expect(page).to have_content('value1') }
|
8
|
+
it { expect(page).to have_content('value2') }
|
9
|
+
it { expect(page).to have_content('sample text') }
|
10
|
+
it { expect(page).to have_content('Separated by the directory') }
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
# Specs in this file have access to a helper object that includes
|
4
|
+
# the LazyloadHelper. For example:
|
5
|
+
#
|
6
|
+
# describe LazyloadHelper do
|
7
|
+
# describe "string concat" do
|
8
|
+
# it "concats two strings with spaces" do
|
9
|
+
# expect(helper.concat_strings("this","that")).to eq("this that")
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
module LazyRender
|
14
|
+
RSpec.describe LazyloadHelper, :type => :helper do
|
15
|
+
|
16
|
+
describe '#lazy_render' do
|
17
|
+
it 'return span tag with class and name' do
|
18
|
+
expect(helper.lazy_render('sample_class')).to eq "<span class=\"js-lazy-render-sample_class\" data-lazy-render-name=\"sample_class\"></span>"
|
19
|
+
expect(helper.lazy_render('sample_class', locals: [])).to eq "<span class=\"js-lazy-render-sample_class\" data-lazy-render-name=\"sample_class\"></span>"
|
20
|
+
expect(helper.lazy_render('sample_class', locals: 'Sample')).to eq "<span class=\"js-lazy-render-sample_class\" data-lazy-render-name=\"sample_class\"></span>"
|
21
|
+
end
|
22
|
+
it 'return span tag with class and name and locals' do
|
23
|
+
expect(helper.lazy_render('sample_class', locals: { var1: 'var3', var2: 'var4' })).to eq "<span class=\"js-lazy-render-sample_class\" data-lazy-render-name=\"sample_class\" data-lazy-render-params=\"{"var1":"var3","var2":"var4"}\"></span>"
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'return span tag with class and name and cache params' do
|
27
|
+
expect(helper.lazy_render('sample_class', cache: 200)).to eq "<span class=\"js-lazy-render-sample_class\" data-lazy-render-name=\"sample_class\" data-lazy-render-cache=\"200\"></span>"
|
28
|
+
expect(helper.lazy_render('sample_class', cache: '300')).to eq "<span class=\"js-lazy-render-sample_class\" data-lazy-render-name=\"sample_class\" data-lazy-render-cache=\"300\"></span>"
|
29
|
+
expect(helper.lazy_render('sample_class', cache: 'abc')).to eq "<span class=\"js-lazy-render-sample_class\" data-lazy-render-name=\"sample_class\" data-lazy-render-cache=\"0\"></span>"
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'return span tag with class and name and callback method' do
|
33
|
+
expect(helper.lazy_render('sample_class', callback: 'Activity.start')).to eq "<span class=\"js-lazy-render-sample_class\" data-lazy-render-name=\"sample_class\" data-lazy-render-callback=\"Activity.start\"></span>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
ENV["RAILS_ROOT"] ||= File.dirname(__FILE__) + "../../../spec/test_app"
|
4
|
+
require 'spec_helper'
|
5
|
+
require File.expand_path("../test_app/config/environment", __FILE__)
|
6
|
+
require 'rspec/rails'
|
7
|
+
require 'capybara-webkit'
|
8
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
9
|
+
|
10
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
11
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
12
|
+
# run as spec files by default. This means that files in spec/support that end
|
13
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
14
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
15
|
+
# end with _spec.rb. You can configure this pattern with the --pattern
|
16
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
17
|
+
#
|
18
|
+
# The following line is provided for convenience purposes. It has the downside
|
19
|
+
# of increasing the boot-up time by auto-requiring all files in the support
|
20
|
+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
21
|
+
# require only the support files necessary.
|
22
|
+
#
|
23
|
+
# Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
|
24
|
+
|
25
|
+
# Checks for pending migrations before tests are run.
|
26
|
+
# If you are not using ActiveRecord, you can remove this line.
|
27
|
+
ActiveRecord::Migration.maintain_test_schema!
|
28
|
+
|
29
|
+
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
30
|
+
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
|
31
|
+
|
32
|
+
RSpec.configure do |config|
|
33
|
+
config.include Rails.application.routes.url_helpers
|
34
|
+
config.mock_with :rspec
|
35
|
+
config.use_transactional_fixtures = true
|
36
|
+
config.infer_base_class_for_anonymous_controllers = false
|
37
|
+
config.order = "random"
|
38
|
+
config.include Capybara::DSL
|
39
|
+
Capybara.javascript_driver = :webkit
|
40
|
+
end
|
41
|
+
|
42
|
+
RSpec.configure do |config|
|
43
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
44
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
45
|
+
|
46
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
47
|
+
# examples within a transaction, remove the following line or assign false
|
48
|
+
# instead of true.
|
49
|
+
config.use_transactional_fixtures = true
|
50
|
+
|
51
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
52
|
+
# based on their file location, for example enabling you to call `get` and
|
53
|
+
# `post` in specs under `spec/controllers`.
|
54
|
+
#
|
55
|
+
# You can disable this behaviour by removing the line below, and instead
|
56
|
+
# explicitly tag your specs with their type, e.g.:
|
57
|
+
#
|
58
|
+
# RSpec.describe UsersController, :type => :controller do
|
59
|
+
# # ...
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# The different available types are documented in the features, such as in
|
63
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
64
|
+
config.infer_spec_type_from_file_location!
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# rspec-expectations config goes here. You can use an alternate
|
19
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
20
|
+
# assertions if you prefer.
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
23
|
+
# and `failure_message` of custom matchers include text for helper methods
|
24
|
+
# defined using `chain`, e.g.:
|
25
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
26
|
+
# # => "be bigger than 2 and smaller than 4"
|
27
|
+
# ...rather than:
|
28
|
+
# # => "be bigger than 2"
|
29
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
30
|
+
end
|
31
|
+
|
32
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
33
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
34
|
+
config.mock_with :rspec do |mocks|
|
35
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
36
|
+
# a real object. This is generally recommended, and will default to
|
37
|
+
# `true` in RSpec 4.
|
38
|
+
mocks.verify_partial_doubles = true
|
39
|
+
end
|
40
|
+
|
41
|
+
# The settings below are suggested to provide a good initial experience
|
42
|
+
# with RSpec, but feel free to customize to your heart's content.
|
43
|
+
=begin
|
44
|
+
# These two settings work together to allow you to limit a spec run
|
45
|
+
# to individual examples or groups you care about by tagging them with
|
46
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
47
|
+
# get run.
|
48
|
+
config.filter_run :focus
|
49
|
+
config.run_all_when_everything_filtered = true
|
50
|
+
|
51
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
52
|
+
# For more details, see:
|
53
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
54
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
55
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
56
|
+
config.disable_monkey_patching!
|
57
|
+
|
58
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
59
|
+
# file, and it's useful to allow more verbose output when running an
|
60
|
+
# individual spec file.
|
61
|
+
if config.files_to_run.one?
|
62
|
+
# Use the documentation formatter for detailed output,
|
63
|
+
# unless a formatter has already been configured
|
64
|
+
# (e.g. via a command-line flag).
|
65
|
+
config.default_formatter = 'doc'
|
66
|
+
end
|
67
|
+
|
68
|
+
# Print the 10 slowest examples and example groups at the
|
69
|
+
# end of the spec run, to help surface which specs are running
|
70
|
+
# particularly slow.
|
71
|
+
config.profile_examples = 10
|
72
|
+
|
73
|
+
# Run specs in random order to surface order dependencies. If you find an
|
74
|
+
# order dependency and want to debug it, you can fix the order by providing
|
75
|
+
# the seed, which is printed after each run.
|
76
|
+
# --seed 1234
|
77
|
+
config.order = :random
|
78
|
+
|
79
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
80
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
81
|
+
# test failures related to randomization by passing the same `--seed` value
|
82
|
+
# as the one that triggered the failure.
|
83
|
+
Kernel.srand config.seed
|
84
|
+
=end
|
85
|
+
end
|