afterburner 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +6 -0
- data/.travis.yml +22 -0
- data/Gemfile +8 -0
- data/Rakefile +1 -0
- data/afterburner.gemspec +19 -0
- data/lib/afterburner.rb +2 -0
- data/lib/afterburner/adapters.rb +4 -0
- data/lib/afterburner/adapters/paginator.rb +6 -0
- data/lib/afterburner/adapters/paginator/kaminari.rb +17 -0
- data/lib/afterburner/adapters/paginator/will_paginate.rb +16 -0
- data/lib/afterburner/adapters/persistence.rb +7 -0
- data/lib/afterburner/adapters/persistence/hyperion.rb +36 -0
- data/lib/afterburner/framework.rb +4 -0
- data/lib/afterburner/framework/base_conductor.rb +65 -0
- data/lib/afterburner/framework/base_interactor.rb +19 -0
- data/lib/afterburner/package.rb +10 -0
- data/lib/afterburner/protocols.rb +4 -0
- data/lib/afterburner/protocols/paginator.rb +37 -0
- data/lib/afterburner/protocols/searcher.rb +38 -0
- data/license.md +19 -0
- data/readme.md +13 -0
- data/spec/afterburner/adapters/paginator/kaminari_spec.rb +23 -0
- data/spec/afterburner/adapters/paginator/will_paginate_spec.rb +23 -0
- data/spec/afterburner/adapters/persistence/hyperion_spec.rb +29 -0
- data/spec/afterburner/framework/base_conductor_spec.rb +11 -0
- data/spec/afterburner/framework/base_interactor_spec.rb +12 -0
- data/spec/afterburner/protocols/pagination_spec.rb +24 -0
- data/spec/afterburner/protocols/searching_spec.rb +24 -0
- data/spec/shared/afterburner/adapters/paginator.rb +17 -0
- data/spec/shared/afterburner/adapters/persistence.rb +31 -0
- data/spec/shared/callable.rb +24 -0
- data/spec/shared/protocols.rb +71 -0
- data/spec/spec_helper.rb +7 -0
- metadata +57 -10
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
install:
|
3
|
+
- bundle install --without development
|
4
|
+
script:
|
5
|
+
- bundle exec rspec spec
|
6
|
+
notifications:
|
7
|
+
email: false
|
8
|
+
irc:
|
9
|
+
use_notice: true
|
10
|
+
skip_join: true
|
11
|
+
channels:
|
12
|
+
- "irc.freenode.org#afterburner"
|
13
|
+
campfire:
|
14
|
+
on_success: always
|
15
|
+
on_failure: always
|
16
|
+
rooms:
|
17
|
+
- secure: "X5X39BTgXacSdc32F8mIjJKPqm5dZzmgZfJ14qYpJeMETTdA5JfByt2uCfU8\njJkkxT+XGWta0bSSlRIHQJO6pK26U94A95VYDX0jNuneKEnsoAsqJ6U0VY6v\nH5oxXMAZ2perP/FH9ZsPNR+ulyFfbMQCeGPJw5AXKZQqzf6qPOI="
|
18
|
+
rvm:
|
19
|
+
- 2.0.0
|
20
|
+
- 1.9.3
|
21
|
+
- rbx-19mode
|
22
|
+
- jruby-19mode
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/afterburner.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('lib/afterburner/package', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "afterburner"
|
6
|
+
s.version = Afterburner::VERSION
|
7
|
+
s.authors = Afterburner::AUTHORS
|
8
|
+
s.email = Afterburner::EMAILS
|
9
|
+
s.homepage = Afterburner::HOMEPAGE
|
10
|
+
s.summary = Afterburner::SUMMARY
|
11
|
+
s.description = Afterburner::DESCRIPTION
|
12
|
+
|
13
|
+
s.required_ruby_version = Afterburner::REQUIRED_RUBY_VERSION
|
14
|
+
s.require_paths = ["lib"]
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split($/)
|
17
|
+
s.test_files = s.files.grep(%r{^(spec)/})
|
18
|
+
|
19
|
+
end
|
data/lib/afterburner.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Afterburner
|
2
|
+
module Adapters
|
3
|
+
module Persistence
|
4
|
+
module Hyperion
|
5
|
+
# Persist a hash to the datastore.
|
6
|
+
#
|
7
|
+
# @param values [Hash] The values to persist.
|
8
|
+
# @return [Hash] The values persisted plus the resource identifier (key).
|
9
|
+
def store(values)
|
10
|
+
::Hyperion.save({:kind => entity_kind}.merge(values))
|
11
|
+
end
|
12
|
+
|
13
|
+
# Find an entity's attributes by its key.
|
14
|
+
#
|
15
|
+
# @param key [String] The resource's identifier.
|
16
|
+
# @return [Hash] The entity's attributes.
|
17
|
+
def find(key)
|
18
|
+
::Hyperion.find_by_key(key)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Search for one or more entities.
|
22
|
+
#
|
23
|
+
# @param options [Hash] A series of options to be passed to the adapter.
|
24
|
+
# @return [Array] A collection of entity attribute hashes.
|
25
|
+
def search(options = {})
|
26
|
+
::Hyperion.find_by_kind(entity_kind, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
def entity_kind
|
31
|
+
raise "entity_kind was not specified by this repository."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Afterburner
|
2
|
+
module Framework
|
3
|
+
class ResponseNotSpecifiedError < StandardError; end
|
4
|
+
class DataNotSpecifiedError < StandardError; end
|
5
|
+
# The Base Conductor is the conductor that all other conductors inherit from.
|
6
|
+
# Its primary role is to decipher the parameters, retrieve or save data to
|
7
|
+
# or from data-facing APIs like a database or a third-party API, and to
|
8
|
+
# optionally wrap what it plans to return in an object that provides methods
|
9
|
+
# for access (in some cases, abstracting complex logic away from the view).
|
10
|
+
#
|
11
|
+
# The Conductor is not responsible, however, for validating or wrapping the
|
12
|
+
# data it retrieves. That task is delegated down to the application.
|
13
|
+
class BaseConductor
|
14
|
+
class << self
|
15
|
+
# Runs the conductor and returns a hash of objects (presenter or
|
16
|
+
# otherwise) that are passed to the view.
|
17
|
+
#
|
18
|
+
# @param params [HashWithIndifferentAccess] The request parameters.
|
19
|
+
# @param options [Hash] A series of options that override default values.
|
20
|
+
# @return [Hash] An associative array of presenter objects to be passed to the view.
|
21
|
+
def call(params, options = {})
|
22
|
+
new(params, options).to_response
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Transforms the data returned by the #data method into an acceptable format
|
27
|
+
# to return to the controller. Primarily used to wrap data in presenters, but
|
28
|
+
# can pass entities back, too.
|
29
|
+
#
|
30
|
+
# @return [Hash] An associative array of presenter or entity objects to be passed to the view.
|
31
|
+
def to_response
|
32
|
+
raise ResponseNotSpecifiedError, "#to_response must be overridden when subclassing BaseConductor"
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
attr_accessor :params, :options
|
37
|
+
|
38
|
+
def initialize(params, options = {})
|
39
|
+
self.params = params
|
40
|
+
self.options = defaults.merge(options)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Passes data retrieved from somewhere down to Interactors and returns something
|
44
|
+
# to be wrapped by #to_response -- by convention, an associative array.
|
45
|
+
#
|
46
|
+
# This method can also assume responsibility for retrieving objects, but it may
|
47
|
+
# choose to delegate that to other methods of this class.
|
48
|
+
#
|
49
|
+
# @return [Object] Data to be wrapped to send in response to the request.
|
50
|
+
def data
|
51
|
+
raise DataNotSpecifiedError, "#data must be overridden when subclassing BaseConductor."
|
52
|
+
end
|
53
|
+
|
54
|
+
# Provides a frozen hash of sane defaults that can be overridden to change class
|
55
|
+
# behaviour. Highly useful for dependency injection to simplify testing. For
|
56
|
+
# instance, instead of hard-coding a repository object, specify a default for it
|
57
|
+
# so that you can pass in a mock when testing.
|
58
|
+
#
|
59
|
+
# @return [Hash] An associative array of defaults.
|
60
|
+
def defaults
|
61
|
+
Hash.new.freeze
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Afterburner
|
2
|
+
module Framework
|
3
|
+
class BaseInteractor
|
4
|
+
class << self
|
5
|
+
def call(data, options = {})
|
6
|
+
new(data, options).to_response
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_response
|
11
|
+
raise "#to_response must be specified!"
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
def initialize(data, options = {})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Afterburner
|
2
|
+
VERSION = '0.0.3'
|
3
|
+
AUTHORS = ["The Afterburner Team"]
|
4
|
+
EMAILS = ["info@afterburnercms.com"]
|
5
|
+
HOMEPAGE = "https://github.com/grounded/"
|
6
|
+
SUMMARY = "A framework for delivery-independent applications and hot-swappability."
|
7
|
+
DESCRIPTION = SUMMARY
|
8
|
+
|
9
|
+
REQUIRED_RUBY_VERSION = '>= 1.9.3'
|
10
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Afterburner
|
2
|
+
module Protocols
|
3
|
+
# Wraps pagination so that users can swap out pagination models with the use
|
4
|
+
# of any one pagination plugin. At present, it only supports a single
|
5
|
+
# pagination method, but it will pass along any arguments given to that
|
6
|
+
# method.
|
7
|
+
#
|
8
|
+
# Simply set Afterburner::Pagination.paginating_method equal to the symbol
|
9
|
+
# name of your paginating method, and then use the as_pages method on queries.
|
10
|
+
# For example, if you are wrapping will_paginate, the pagination method there
|
11
|
+
# is called 'paginate'. Thus:
|
12
|
+
#
|
13
|
+
# Afterburner::Paginator.paginating_method = :paginate
|
14
|
+
# MyModel.where('field' => true).as_pages(:per_page => 10, :blah => false)
|
15
|
+
#
|
16
|
+
# You can also set paginating_method on the model itself to use a different
|
17
|
+
# paginator for just that model. For example:
|
18
|
+
#
|
19
|
+
# MyModel.paginating_method = :page
|
20
|
+
# MyModel.where(:field => true).as_pages("cats") # uses 'local' page method
|
21
|
+
#
|
22
|
+
# This won't interrupt other models' ability to use the default paginator.
|
23
|
+
module Paginator
|
24
|
+
class << self
|
25
|
+
attr_accessor :paginating_method
|
26
|
+
end
|
27
|
+
attr_accessor :paginating_method
|
28
|
+
def paginating_method
|
29
|
+
@paginating_method || Paginator.paginating_method
|
30
|
+
end
|
31
|
+
|
32
|
+
def as_pages(*args)
|
33
|
+
send paginating_method, *args
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Afterburner
|
2
|
+
module Protocols
|
3
|
+
# Wraps searching so that users can swap out searching models with the use
|
4
|
+
# of any one searching plugin. At present, it only supports a single
|
5
|
+
# searching method, but it will pass along any arguments given to that
|
6
|
+
# method.
|
7
|
+
#
|
8
|
+
# Simply set Afterburner::Searcher.searching_method equal to the symbol name
|
9
|
+
# of your searching method, and then use the :as_search_results method for
|
10
|
+
# queries. For example, if you are wrapping acts_as_indexed, the searching
|
11
|
+
# method there is called 'with_query'. Thus:
|
12
|
+
#
|
13
|
+
# Afterburner::Searcher.searching_method = :with_query
|
14
|
+
# MyModel.where(:field => true).as_search_results("cats") # uses with_query
|
15
|
+
#
|
16
|
+
# You can also set searching_method on the model itself to use a different
|
17
|
+
# as_search_results for just that model. For example:
|
18
|
+
#
|
19
|
+
# MyModel.searching_method = :local_query
|
20
|
+
# MyModel.where(:field => true).as_search_results("cats") # uses local_query
|
21
|
+
#
|
22
|
+
# This won't interrupt other models' ability to use the default as_search_results.
|
23
|
+
module Searcher
|
24
|
+
class << self
|
25
|
+
attr_accessor :searching_method
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_accessor :searching_method
|
29
|
+
def searching_method
|
30
|
+
@searching_method || Searcher.searching_method
|
31
|
+
end
|
32
|
+
|
33
|
+
def as_search_results(*args)
|
34
|
+
send searching_method, *args
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/license.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
MIT License
|
2
|
+
Copyright (c) 2005-2012 Philip Arndt, Uģis Ozols, and Rob Yurkowski
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
this software and associated documentation files (the "Software"), to deal in
|
6
|
+
the Software without restriction, including without limitation the rights to
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
12
|
+
copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/readme.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Afterburner Framework
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/grounded/afterburner)
|
4
|
+
|
5
|
+
The building blocks for the Rails Engine universe. All the stuff that all of
|
6
|
+
our projects do over and over and in slightly different ways.
|
7
|
+
|
8
|
+
Plug and play.
|
9
|
+
|
10
|
+
## Development
|
11
|
+
To run the tests:
|
12
|
+
|
13
|
+
rspec spec
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'afterburner/adapters/paginator/kaminari'
|
3
|
+
require 'shared/afterburner/adapters/paginator'
|
4
|
+
|
5
|
+
module Afterburner
|
6
|
+
module Adapters
|
7
|
+
module Paginator
|
8
|
+
describe Kaminari do
|
9
|
+
|
10
|
+
it_should_behave_like "adapters/paginator" do
|
11
|
+
let(:dummy_class) do
|
12
|
+
class Dummy
|
13
|
+
extend Kaminari
|
14
|
+
end
|
15
|
+
end
|
16
|
+
let(:per_page_alias) { :per }
|
17
|
+
let(:total_pages_alias) { :num_pages }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'afterburner/adapters/paginator/will_paginate'
|
3
|
+
require 'shared/afterburner/adapters/paginator'
|
4
|
+
|
5
|
+
module Afterburner
|
6
|
+
module Adapters
|
7
|
+
module Paginator
|
8
|
+
describe WillPaginate do
|
9
|
+
|
10
|
+
it_should_behave_like "adapters/paginator" do
|
11
|
+
let(:dummy_class) do
|
12
|
+
class Dummy
|
13
|
+
extend WillPaginate
|
14
|
+
end
|
15
|
+
end
|
16
|
+
let(:per_page_alias) { :per_page }
|
17
|
+
let(:total_pages_alias) { :total_pages }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'afterburner/adapters/persistence/hyperion'
|
3
|
+
require 'shared/afterburner/adapters/persistence'
|
4
|
+
|
5
|
+
class Hyperion; end
|
6
|
+
class Dummy
|
7
|
+
include Afterburner::Adapters::Persistence::Hyperion
|
8
|
+
|
9
|
+
protected
|
10
|
+
def entity_kind; self.class.to_s.downcase end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Afterburner
|
14
|
+
module Adapters
|
15
|
+
module Persistence
|
16
|
+
describe Hyperion do
|
17
|
+
|
18
|
+
it_should_behave_like "adapters/persistence" do
|
19
|
+
let(:dummy_class) { Dummy }
|
20
|
+
let(:receiving_class) { ::Hyperion }
|
21
|
+
let(:store_alias) { :save }
|
22
|
+
let(:find_alias) { :find_by_key }
|
23
|
+
let(:search_alias) { :find_by_kind }
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'afterburner/protocols/paginator'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Afterburner
|
5
|
+
module Protocols
|
6
|
+
describe Paginator do
|
7
|
+
it_should_behave_like "protocols" do
|
8
|
+
let(:dummy_class) {
|
9
|
+
class DummyClass
|
10
|
+
extend Paginator
|
11
|
+
end
|
12
|
+
}
|
13
|
+
let(:other_dummy_class) {
|
14
|
+
class AnotherDummyClass
|
15
|
+
extend Paginator
|
16
|
+
end
|
17
|
+
}
|
18
|
+
let(:protocol) { Paginator }
|
19
|
+
let(:protocol_method) { :paginating_method }
|
20
|
+
let(:protocol_action_method) { :as_pages }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'afterburner/protocols/searcher'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
module Afterburner
|
5
|
+
module Protocols
|
6
|
+
describe Searcher do
|
7
|
+
it_should_behave_like "protocols" do
|
8
|
+
let(:dummy_class) {
|
9
|
+
class DummyClass
|
10
|
+
extend Searcher
|
11
|
+
end
|
12
|
+
}
|
13
|
+
let(:other_dummy_class) {
|
14
|
+
class AnotherDummyClass
|
15
|
+
extend Searcher
|
16
|
+
end
|
17
|
+
}
|
18
|
+
let(:protocol) { Searcher }
|
19
|
+
let(:protocol_method) { :searching_method }
|
20
|
+
let(:protocol_action_method) { :as_search_results }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
shared_examples_for "adapters/paginator" do
|
2
|
+
|
3
|
+
let(:dummy_class) { nil }
|
4
|
+
let(:per_page_alias) { nil }
|
5
|
+
let(:total_pages_alias) { nil }
|
6
|
+
|
7
|
+
it 'redirects with_items_per_page properly' do
|
8
|
+
dummy_class.should_receive(per_page_alias).once.with(1).and_return true
|
9
|
+
dummy_class.with_items_per_page(1).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'redirects with_total_pages properly' do
|
13
|
+
dummy_class.should_receive(total_pages_alias).once.with(5).and_return true
|
14
|
+
dummy_class.with_total_pages(5).should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
shared_examples_for "adapters/persistence" do
|
2
|
+
|
3
|
+
let(:dummy_class) { nil }
|
4
|
+
let(:receiving_class) { nil }
|
5
|
+
let(:store_alias) { nil }
|
6
|
+
let(:find_alias) { nil }
|
7
|
+
let(:search_alias) { nil }
|
8
|
+
let(:kind) { dummy_class.to_s.downcase }
|
9
|
+
|
10
|
+
context 'delegates' do
|
11
|
+
specify '#store' do
|
12
|
+
receiving_class.should_receive(store_alias).once.
|
13
|
+
with(:kind => kind, :foo => :bar).
|
14
|
+
and_return Hash.new
|
15
|
+
|
16
|
+
dummy_class.new.store(:foo => :bar).should be_kind_of(Hash)
|
17
|
+
end
|
18
|
+
|
19
|
+
specify '#find' do
|
20
|
+
receiving_class.should_receive(find_alias).once.with(:key).and_return Hash.new
|
21
|
+
dummy_class.new.find(:key).should be_kind_of(Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
specify '#search' do
|
25
|
+
receiving_class.should_receive(search_alias).once.
|
26
|
+
with(kind, :for => :this).and_return []
|
27
|
+
dummy_class.new.search(:for => :this).should be_kind_of(Array)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
shared_examples "a callable" do
|
2
|
+
it "is not publicly instantiable" do
|
3
|
+
subject.new({}).should raise_error NoMethodError
|
4
|
+
end
|
5
|
+
|
6
|
+
describe "::call" do
|
7
|
+
it "returns with #to_response" do
|
8
|
+
mock = double "object"
|
9
|
+
mock.should_receive(:to_response)
|
10
|
+
subject.stub!(:new).and_return(mock)
|
11
|
+
subject.call({:stub => 'abc'})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#new" do
|
16
|
+
it "receives the data passed to call" do
|
17
|
+
args = %w(andaone andatwo)
|
18
|
+
instance = subject.send(:new, args)
|
19
|
+
instance.stub!(:to_response).and_return(nil)
|
20
|
+
subject.should_receive(:new).with(*args).and_return(instance)
|
21
|
+
subject.call(*args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
shared_examples_for "protocols" do
|
2
|
+
let(:dummy_class) { nil }
|
3
|
+
let(:other_dummy_class) { nil }
|
4
|
+
let(:protocol) { nil }
|
5
|
+
let(:protocol_method) { nil }
|
6
|
+
let(:protocol_action_method) { nil }
|
7
|
+
|
8
|
+
describe "interface" do
|
9
|
+
let(:dummy) { 'dummy' }
|
10
|
+
context "at Afterburner level" do
|
11
|
+
let(:rummy) { 'rummy' }
|
12
|
+
|
13
|
+
it "stores a reference to the default_protocol_action method" do
|
14
|
+
protocol.send "#{protocol_method}=", dummy
|
15
|
+
protocol.send(protocol_method).should == dummy
|
16
|
+
dummy_class.send(protocol_method).should == dummy
|
17
|
+
end
|
18
|
+
|
19
|
+
it "doesn't override the default protocol when set locally" do
|
20
|
+
protocol.send("#{protocol_method}=", dummy)
|
21
|
+
dummy_class.send("#{protocol_method}=", rummy)
|
22
|
+
|
23
|
+
protocol.send(protocol_method).should == dummy
|
24
|
+
dummy_class.send(protocol_method).should == rummy
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "at model level" do
|
29
|
+
it "stores a reference to the protocol method" do
|
30
|
+
dummy_class.send "#{protocol_method}=", dummy
|
31
|
+
dummy_class.send(protocol_method).should == dummy
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with stub' do
|
35
|
+
let(:dummy_method) { :some_scope }
|
36
|
+
before do
|
37
|
+
dummy_class.stub! dummy_method
|
38
|
+
dummy_class.send "#{protocol_method}=", dummy_method
|
39
|
+
end
|
40
|
+
|
41
|
+
it "wraps a protocol method" do
|
42
|
+
dummy_class.should_receive dummy_method
|
43
|
+
dummy_class.send protocol_action_method
|
44
|
+
end
|
45
|
+
|
46
|
+
it "passes on all arguments to the protocol method" do
|
47
|
+
dummy_class.should_receive(dummy_method).with 1, [], {}
|
48
|
+
dummy_class.send(protocol_action_method, 1, [], {})
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with local override" do
|
52
|
+
let(:new_default) { :some_random_method }
|
53
|
+
before { protocol.send "#{protocol_method}=", new_default }
|
54
|
+
|
55
|
+
it "uses local protocol" do
|
56
|
+
dummy_class.should_receive protocol_method
|
57
|
+
dummy_class.should_not_receive new_default
|
58
|
+
protocol.should_not_receive new_default
|
59
|
+
|
60
|
+
dummy_class.send protocol_method, 'cats'
|
61
|
+
end
|
62
|
+
|
63
|
+
it "doesn't override other model's protocols" do
|
64
|
+
other_dummy_class.should_receive(protocol_method).with 'cats'
|
65
|
+
other_dummy_class.send protocol_method, 'cats'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,23 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: afterburner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- The Afterburner Team
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
15
|
-
email:
|
14
|
+
description: A framework for delivery-independent applications and hot-swappability.
|
15
|
+
email:
|
16
|
+
- info@afterburnercms.com
|
16
17
|
executables: []
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
|
-
files:
|
20
|
-
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .travis.yml
|
23
|
+
- Gemfile
|
24
|
+
- Rakefile
|
25
|
+
- afterburner.gemspec
|
26
|
+
- lib/afterburner.rb
|
27
|
+
- lib/afterburner/adapters.rb
|
28
|
+
- lib/afterburner/adapters/paginator.rb
|
29
|
+
- lib/afterburner/adapters/paginator/kaminari.rb
|
30
|
+
- lib/afterburner/adapters/paginator/will_paginate.rb
|
31
|
+
- lib/afterburner/adapters/persistence.rb
|
32
|
+
- lib/afterburner/adapters/persistence/hyperion.rb
|
33
|
+
- lib/afterburner/framework.rb
|
34
|
+
- lib/afterburner/framework/base_conductor.rb
|
35
|
+
- lib/afterburner/framework/base_interactor.rb
|
36
|
+
- lib/afterburner/package.rb
|
37
|
+
- lib/afterburner/protocols.rb
|
38
|
+
- lib/afterburner/protocols/paginator.rb
|
39
|
+
- lib/afterburner/protocols/searcher.rb
|
40
|
+
- license.md
|
41
|
+
- readme.md
|
42
|
+
- spec/afterburner/adapters/paginator/kaminari_spec.rb
|
43
|
+
- spec/afterburner/adapters/paginator/will_paginate_spec.rb
|
44
|
+
- spec/afterburner/adapters/persistence/hyperion_spec.rb
|
45
|
+
- spec/afterburner/framework/base_conductor_spec.rb
|
46
|
+
- spec/afterburner/framework/base_interactor_spec.rb
|
47
|
+
- spec/afterburner/protocols/pagination_spec.rb
|
48
|
+
- spec/afterburner/protocols/searching_spec.rb
|
49
|
+
- spec/shared/afterburner/adapters/paginator.rb
|
50
|
+
- spec/shared/afterburner/adapters/persistence.rb
|
51
|
+
- spec/shared/callable.rb
|
52
|
+
- spec/shared/protocols.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: https://github.com/grounded/
|
21
55
|
licenses: []
|
22
56
|
post_install_message:
|
23
57
|
rdoc_options: []
|
@@ -28,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
28
62
|
requirements:
|
29
63
|
- - ! '>='
|
30
64
|
- !ruby/object:Gem::Version
|
31
|
-
version:
|
65
|
+
version: 1.9.3
|
32
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
67
|
none: false
|
34
68
|
requirements:
|
@@ -40,5 +74,18 @@ rubyforge_project:
|
|
40
74
|
rubygems_version: 1.8.24
|
41
75
|
signing_key:
|
42
76
|
specification_version: 3
|
43
|
-
summary:
|
44
|
-
test_files:
|
77
|
+
summary: A framework for delivery-independent applications and hot-swappability.
|
78
|
+
test_files:
|
79
|
+
- spec/afterburner/adapters/paginator/kaminari_spec.rb
|
80
|
+
- spec/afterburner/adapters/paginator/will_paginate_spec.rb
|
81
|
+
- spec/afterburner/adapters/persistence/hyperion_spec.rb
|
82
|
+
- spec/afterburner/framework/base_conductor_spec.rb
|
83
|
+
- spec/afterburner/framework/base_interactor_spec.rb
|
84
|
+
- spec/afterburner/protocols/pagination_spec.rb
|
85
|
+
- spec/afterburner/protocols/searching_spec.rb
|
86
|
+
- spec/shared/afterburner/adapters/paginator.rb
|
87
|
+
- spec/shared/afterburner/adapters/persistence.rb
|
88
|
+
- spec/shared/callable.rb
|
89
|
+
- spec/shared/protocols.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
has_rdoc:
|