angular_sprinkles 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +9 -8
- data/Gemfile.lock +41 -13
- data/LICENSE.txt +1 -1
- data/README.md +4 -38
- data/Rakefile +20 -37
- data/VERSION +1 -1
- data/angular_sprinkles.gemspec +104 -41
- data/app/assets/javascripts/angular_sprinkles.js.erb +1 -22
- data/lib/angular_sprinkles/constructor.rb +12 -0
- data/lib/angular_sprinkles/constructor_collection.rb +20 -0
- data/lib/angular_sprinkles/content_cache.rb +15 -0
- data/lib/angular_sprinkles/content_yielder.rb +19 -0
- data/lib/angular_sprinkles/context.rb +13 -0
- data/lib/angular_sprinkles/controller.rb +38 -65
- data/lib/angular_sprinkles/counter.rb +12 -0
- data/lib/angular_sprinkles/directive/attributes.rb +16 -0
- data/lib/angular_sprinkles/directive/input.rb +19 -0
- data/lib/angular_sprinkles/directive/name.rb +19 -0
- data/lib/angular_sprinkles/directive/options.rb +13 -0
- data/lib/angular_sprinkles/helpers/directive_helper.rb +7 -20
- data/lib/angular_sprinkles/helpers/service_helper.rb +14 -0
- data/lib/angular_sprinkles/helpers.rb +2 -7
- data/lib/angular_sprinkles/java_script.rb +55 -0
- data/lib/angular_sprinkles/key_generator.rb +14 -0
- data/lib/angular_sprinkles/model_decorator.rb +16 -0
- data/lib/angular_sprinkles/object_key_wrapper.rb +12 -0
- data/lib/angular_sprinkles.rb +20 -14
- data/spec/angular_sprinkles/constructor_collection_spec.rb +22 -0
- data/spec/angular_sprinkles/constructor_spec.rb +12 -0
- data/spec/angular_sprinkles/content_cache_spec.rb +15 -0
- data/spec/angular_sprinkles/content_yielder_spec.rb +45 -0
- data/spec/angular_sprinkles/context_spec.rb +22 -0
- data/spec/angular_sprinkles/counter_spec.rb +15 -0
- data/spec/angular_sprinkles/directive/attributes_spec.rb +24 -0
- data/spec/angular_sprinkles/directive/input_spec.rb +11 -0
- data/spec/angular_sprinkles/directive/name_spec.rb +11 -0
- data/spec/angular_sprinkles/directive/options_spec.rb +11 -0
- data/spec/angular_sprinkles/key_generator_spec.rb +17 -0
- data/spec/angular_sprinkles/model_decorator_spec.rb +24 -0
- data/spec/angular_sprinkles/object_key_wrapper_spec.rb +17 -0
- data/spec/controllers/test_controller_spec.rb +20 -0
- data/spec/dummy/.rspec +3 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +30 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/test_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/test_model.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/test/new.html.erb +9 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +29 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +57 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/migrate/20140908021353_create_test_models.rb +9 -0
- data/spec/dummy/db/schema.rb +22 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/features/javascript_spec.rb +26 -0
- data/spec/rails_helper.rb +21 -0
- data/spec/spec_helper.rb +82 -21
- metadata +103 -29
- data/.document +0 -5
- data/.rspec +0 -1
- data/lib/angular_sprinkles/data/bind.rb +0 -18
- data/lib/angular_sprinkles/decorators/bind_decorator.rb +0 -61
- data/lib/angular_sprinkles/decorators.rb +0 -6
- data/lib/angular_sprinkles/helpers/bind_helper.rb +0 -56
- data/lib/angular_sprinkles/helpers/bind_service_helper.rb +0 -27
- data/lib/angular_sprinkles/mixins/cache.rb +0 -11
- data/lib/angular_sprinkles/mixins/js_transformable.rb +0 -27
- data/lib/angular_sprinkles/variable_cache.rb +0 -19
- data/spec/controller_spec.rb +0 -74
- data/spec/data/bind_spec.rb +0 -11
- data/spec/decorators/bind_decorator_spec.rb +0 -56
- data/spec/helpers/bind_helper_spec.rb +0 -94
- data/spec/helpers/directive_helper_spec.rb +0 -66
- data/spec/mixins/js_transformable_spec.rb +0 -45
- data/spec/variable_cache_spec.rb +0 -57
data/.document
DELETED
data/.rspec
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
--color
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'angular_sprinkles/mixins/js_transformable'
|
|
2
|
-
|
|
3
|
-
module AngularSprinkles
|
|
4
|
-
module Data
|
|
5
|
-
class Bind
|
|
6
|
-
include Mixins::JsTransformable
|
|
7
|
-
|
|
8
|
-
def initialize(*strs)
|
|
9
|
-
@strs = strs.flatten.compact
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def to_json
|
|
13
|
-
to_ctrl_variable(@strs.join('.'))
|
|
14
|
-
end
|
|
15
|
-
alias_method :to_s, :to_json
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
module AngularSprinkles
|
|
2
|
-
module Decorators
|
|
3
|
-
class Bind < SimpleDelegator
|
|
4
|
-
def initialize(object, key, context_proc)
|
|
5
|
-
@_sprinkles_bind_wrapper = Wrapper.new(object, key, context_proc)
|
|
6
|
-
super(object)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def bind(_method = nil)
|
|
10
|
-
@_sprinkles_bind_wrapper.bind(_method)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def bind_key
|
|
14
|
-
@_sprinkles_bind_wrapper.key
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
class Wrapper
|
|
20
|
-
# create BindWrapper so that methods and variables don't pollute
|
|
21
|
-
# the object being wrapped by Bind
|
|
22
|
-
|
|
23
|
-
attr_reader :object, :key, :context_proc
|
|
24
|
-
|
|
25
|
-
def initialize(object, key, context_proc)
|
|
26
|
-
@object, @key, @context_proc = object, key, context_proc
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def bind(_method = nil)
|
|
30
|
-
cache.yield_if_new([key, _method]) do |var|
|
|
31
|
-
set_prototype_variable_and_yield(_method) unless _method.nil?
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context.bind(key, _method)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
def context
|
|
40
|
-
context_proc.call
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def cache
|
|
44
|
-
context._sprinkles_cache
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def set_prototype_variable_and_yield(_method)
|
|
48
|
-
var = [key, _method].join('.')
|
|
49
|
-
str = context.set_prototype_variable(var, object.send(_method))
|
|
50
|
-
yield_to_sprinkles("#{str};")
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def yield_to_sprinkles(content)
|
|
54
|
-
context.content_for(:sprinkles) do
|
|
55
|
-
context.content_tag(:script, content.html_safe)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
require 'action_view/helpers'
|
|
2
|
-
require 'angular_sprinkles/mixins/js_transformable'
|
|
3
|
-
require 'angular_sprinkles/mixins/cache'
|
|
4
|
-
require 'angular_sprinkles/data/bind'
|
|
5
|
-
|
|
6
|
-
module AngularSprinkles
|
|
7
|
-
module Helpers
|
|
8
|
-
module BindHelper
|
|
9
|
-
include ::ActionView::Helpers
|
|
10
|
-
include Mixins::JsTransformable
|
|
11
|
-
include Mixins::Cache
|
|
12
|
-
|
|
13
|
-
def bind(*input)
|
|
14
|
-
input = input.flatten.compact
|
|
15
|
-
raise ArgumentError if input.empty?
|
|
16
|
-
|
|
17
|
-
build_chain(input).
|
|
18
|
-
select(&method(:is_uninitialized?)).
|
|
19
|
-
map(&method(:convert_to_empty_js_object_string)).
|
|
20
|
-
tap(&method(:yield_if_any))
|
|
21
|
-
|
|
22
|
-
AngularSprinkles::Data::Bind.new(*input)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
def build_chain(input)
|
|
28
|
-
# [:a, :b, :c, :d] => [[:a], [:a, :b], [:a, :b, :c]]
|
|
29
|
-
(1...input.count).inject([]) { |acc,i| acc << input.first(i) }
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def cache
|
|
33
|
-
self._sprinkles_cache
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def is_uninitialized?(var)
|
|
37
|
-
cache.yield_if_new(var)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def convert_to_empty_js_object_string(var)
|
|
41
|
-
set_prototype_variable(var.join('.'), {})
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def yield_if_any(chain)
|
|
45
|
-
yield_to_sprinkles(chain.join(";\n") + ';') if chain.any?
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def yield_to_sprinkles(content)
|
|
49
|
-
content_for(:sprinkles) do
|
|
50
|
-
content_tag(:script, content.html_safe)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
require 'action_view/helpers'
|
|
2
|
-
require 'angular_sprinkles/mixins/cache'
|
|
3
|
-
|
|
4
|
-
module AngularSprinkles
|
|
5
|
-
module Helpers
|
|
6
|
-
module BindServiceHelper
|
|
7
|
-
include ::ActionView::Helpers
|
|
8
|
-
include Mixins::Cache
|
|
9
|
-
|
|
10
|
-
def bind_service(service, *input)
|
|
11
|
-
raise TypeError unless service.is_a?(Symbol) || service.is_a?(String)
|
|
12
|
-
|
|
13
|
-
cache.yield_if_new(service) do |s|
|
|
14
|
-
content_for(:sprinkles, content_tag(:script, "#{SERVICE_QUEUE}.push('#{s}')".html_safe))
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
"#{CONTROLLER_NAME}.#{service}(#{input.join(',')})".html_safe
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
def cache
|
|
23
|
-
self._sprinkles_cache
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module AngularSprinkles
|
|
2
|
-
module Mixins
|
|
3
|
-
module JsTransformable
|
|
4
|
-
def to_ctrl_variable(str)
|
|
5
|
-
"#{AngularSprinkles::CONTROLLER_NAME}.#{str}"
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def set_prototype_variable(key, value)
|
|
9
|
-
or_equals_js(to_ctrl_prototype_variable(key), value)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def set_constructor_variable(key, value)
|
|
13
|
-
"this.#{key} = #{value.to_json}"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
def or_equals_js(key, value)
|
|
19
|
-
"#{key} = #{key} || #{value.to_json}";
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def to_ctrl_prototype_variable(str)
|
|
23
|
-
"#{AngularSprinkles::CONTROLLER_FN}.prototype.#{str}"
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module AngularSprinkles
|
|
2
|
-
class VariableCache
|
|
3
|
-
def initialize
|
|
4
|
-
@cache = {}
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def yield_if_new(var)
|
|
8
|
-
var = var.split('.') if var.is_a?(String)
|
|
9
|
-
var = [var].flatten.compact.map(&:to_sym)
|
|
10
|
-
|
|
11
|
-
unless @cache[var]
|
|
12
|
-
yield(var.join('.')) if block_given?
|
|
13
|
-
@cache[var] = true
|
|
14
|
-
else
|
|
15
|
-
false
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
data/spec/controller_spec.rb
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe AngularSprinkles::Controller do
|
|
4
|
-
class StubController
|
|
5
|
-
include AngularSprinkles::Controller
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
let(:controller) { StubController.new }
|
|
9
|
-
|
|
10
|
-
describe '#add_to_constructor' do
|
|
11
|
-
let(:key) { 'key' }
|
|
12
|
-
let(:value) { 'value' }
|
|
13
|
-
context 'when given a hash' do
|
|
14
|
-
# TODO: Fix me
|
|
15
|
-
# context 'and it is not empty' do
|
|
16
|
-
# let(:params) { { key => value } }
|
|
17
|
-
|
|
18
|
-
# it 'preloads the input data' do
|
|
19
|
-
# result = [
|
|
20
|
-
# %{#{AngularSprinkles::CONTROLLER_FN}.prototype.#{key} = #{AngularSprinkles::CONTROLLER_FN}.prototype.#{key} || "#{value}"}
|
|
21
|
-
# ]
|
|
22
|
-
|
|
23
|
-
# expect(controller.add_to_constructor(params)).to eq(result)
|
|
24
|
-
# end
|
|
25
|
-
# end
|
|
26
|
-
|
|
27
|
-
context 'and it is an empty hash' do
|
|
28
|
-
let(:params) { {} }
|
|
29
|
-
|
|
30
|
-
it 'returns nothing' do
|
|
31
|
-
expect(controller.add_to_constructor(params)).to eq([])
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'when given anything else' do
|
|
37
|
-
let(:params) { value }
|
|
38
|
-
|
|
39
|
-
it 'raises an exception' do
|
|
40
|
-
expect { controller.add_to_constructor(params) }.to raise_error(TypeError)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe '#bindable' do
|
|
46
|
-
before do
|
|
47
|
-
expect(controller).to receive(:add_to_constructor)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'returns a decorated object that responds to #bind' do
|
|
51
|
-
object = controller.bindable(Object.new)
|
|
52
|
-
|
|
53
|
-
expect(object.respond_to?(:bind)).to eq(true)
|
|
54
|
-
expect(object.class).to eq(AngularSprinkles::Decorators::Bind)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# removed for now
|
|
59
|
-
# describe '#bindable_collection' do
|
|
60
|
-
# let(:times) { 5 }
|
|
61
|
-
|
|
62
|
-
# before do
|
|
63
|
-
# expect(controller).to receive(:add_to_constructor).once
|
|
64
|
-
# end
|
|
65
|
-
|
|
66
|
-
# it 'returns a collection of objects that respond to #bind' do
|
|
67
|
-
# collection = (1..times).map { Object.new }
|
|
68
|
-
# objects = controller.bindable_collection(collection)
|
|
69
|
-
|
|
70
|
-
# expect(objects.all? { |o| o.respond_to?(:bind) }).to eq(true)
|
|
71
|
-
# expect(objects.all? { |o| o.class == AngularSprinkles::Decorators::Bind }).to eq(true)
|
|
72
|
-
# end
|
|
73
|
-
# end
|
|
74
|
-
end
|
data/spec/data/bind_spec.rb
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe AngularSprinkles::Data::Bind do
|
|
4
|
-
let(:keys) { [:brewhouse, :software] }
|
|
5
|
-
let(:object) { AngularSprinkles::Data::Bind.new(*keys) }
|
|
6
|
-
|
|
7
|
-
it 'returns the concatenation of the two keys' do
|
|
8
|
-
expect(object.to_json).to eq("#{AngularSprinkles::CONTROLLER_NAME}.#{keys.join('.')}")
|
|
9
|
-
expect(object.to_s).to eq("#{AngularSprinkles::CONTROLLER_NAME}.#{keys.join('.')}")
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe AngularSprinkles::Decorators::Bind do
|
|
4
|
-
class StubObject
|
|
5
|
-
attr_reader :some_attr
|
|
6
|
-
|
|
7
|
-
def initialize(some_attr)
|
|
8
|
-
@some_attr = some_attr
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
class StubContext
|
|
13
|
-
include AngularSprinkles::Mixins::Cache
|
|
14
|
-
|
|
15
|
-
def bind(*args)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def set_prototype_variable(*args)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def content_for(*args)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
let(:context) { StubContext.new }
|
|
26
|
-
let(:context_proc) { ->{ context } }
|
|
27
|
-
|
|
28
|
-
let(:attr) { :brewhouse }
|
|
29
|
-
let(:key) { 'software' }
|
|
30
|
-
let(:object) { StubObject.new(attr) }
|
|
31
|
-
|
|
32
|
-
subject { AngularSprinkles::Decorators::Bind.new(object, key, context_proc) }
|
|
33
|
-
|
|
34
|
-
describe '#bind' do
|
|
35
|
-
context 'when no arguments are passed' do
|
|
36
|
-
it 'creates the necessary object binding' do
|
|
37
|
-
expect(context).to receive(:bind)
|
|
38
|
-
subject.bind
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context 'when more than one argument is passed' do
|
|
43
|
-
it 'creates the necessary object binding' do
|
|
44
|
-
expect(context).to receive(:bind).with(key, nil)
|
|
45
|
-
subject.bind
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'creates additional bindings' do
|
|
49
|
-
expect(context).to receive(:bind).with(key, :some_attr)
|
|
50
|
-
subject.bind(:some_attr)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
end
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe AngularSprinkles::Helpers::BindHelper do
|
|
4
|
-
class StubClass
|
|
5
|
-
include AngularSprinkles::Helpers::BindHelper
|
|
6
|
-
include AngularSprinkles::Mixins::Cache
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
let(:stub) { StubClass.new }
|
|
10
|
-
|
|
11
|
-
describe '#bind' do
|
|
12
|
-
before { allow(stub).to receive(:content_for).and_return(true) }
|
|
13
|
-
|
|
14
|
-
context 'when 0 arguments' do
|
|
15
|
-
it 'raises an argument error' do
|
|
16
|
-
expect { stub.bind }.to raise_error(ArgumentError)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
context 'when 1 argument' do
|
|
21
|
-
let(:var) { :brewhouse }
|
|
22
|
-
|
|
23
|
-
it 'returns the variable name given as a js string' do
|
|
24
|
-
expect(stub.bind(var).to_json).
|
|
25
|
-
to(eq("#{AngularSprinkles::CONTROLLER_NAME}.#{var}"))
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context 'when 2 arguments' do
|
|
30
|
-
let(:vars) { [:brewhouse, :software] }
|
|
31
|
-
|
|
32
|
-
it 'returns the variables chained together as a js string' do
|
|
33
|
-
expect(stub.bind(*vars).to_json).
|
|
34
|
-
to(eq("#{AngularSprinkles::CONTROLLER_NAME}.#{vars.join('.')}"))
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it 'yields the contructor definition and the first variable to the function to prototype' do
|
|
38
|
-
expect(stub).to receive(:yield_to_sprinkles).
|
|
39
|
-
with("#{AngularSprinkles::CONTROLLER_FN}.prototype.#{vars.first} = #{AngularSprinkles::CONTROLLER_FN}.prototype.#{vars.first} || {};")
|
|
40
|
-
|
|
41
|
-
stub.bind(*vars)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
context 'when 3 arguments' do
|
|
46
|
-
let(:vars) { [:brewhouse, :software, :is_neat] }
|
|
47
|
-
|
|
48
|
-
it 'returns the variables chained together as a js string' do
|
|
49
|
-
expect(stub.bind(*vars).to_json).
|
|
50
|
-
to(eq("#{AngularSprinkles::CONTROLLER_NAME}.#{vars.join('.')}"))
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it 'yields the constructor definition and the first variable to the function to prototype' do
|
|
54
|
-
expect(stub).to receive(:yield_to_sprinkles).
|
|
55
|
-
with(%{#{AngularSprinkles::CONTROLLER_FN}.prototype.#{vars.first} = #{AngularSprinkles::CONTROLLER_FN}.prototype.#{vars.first} || {};
|
|
56
|
-
#{AngularSprinkles::CONTROLLER_FN}.prototype.#{vars.first(2).join('.')} = #{AngularSprinkles::CONTROLLER_FN}.prototype.#{vars.first(2).join('.')} || {};})
|
|
57
|
-
|
|
58
|
-
stub.bind(*vars)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
context 'when bind is called more than once' do
|
|
63
|
-
let(:vars) { [:brewhouse, :software, :is_neat] }
|
|
64
|
-
|
|
65
|
-
context 'and it is with the same variables' do
|
|
66
|
-
it 'yields the constructor definition and the first variable to the function to prototype' do
|
|
67
|
-
expect(stub).to receive(:content_for).once
|
|
68
|
-
5.times { stub.bind(*vars) }
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
context 'and it is called with different sets of variables' do
|
|
73
|
-
it 'yields the constructor definition, first variable, and a chain of the first two variables' do
|
|
74
|
-
expect(stub).to receive(:content_for).exactly(2).times
|
|
75
|
-
|
|
76
|
-
stub.bind(vars.first) # yields the constructor
|
|
77
|
-
stub.bind(vars.first) # yields nothing
|
|
78
|
-
stub.bind(*vars.first(2)) # yields declaration for :brewhouse
|
|
79
|
-
stub.bind(*vars) # yields declaration for [:brewhouse, :software]
|
|
80
|
-
stub.bind(*vars) # yields nothing
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
context 'when the constructor has already been yielded' do
|
|
86
|
-
let(:var) { :brewhouse }
|
|
87
|
-
|
|
88
|
-
it 'does not yield anything with only one argument' do
|
|
89
|
-
expect(stub).not_to receive(:content_for)
|
|
90
|
-
stub.bind(var)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|