embark-journey 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/ROADMAP.md +0 -0
- data/Rakefile +1 -0
- data/journey.gemspec +30 -0
- data/lib/active_resource/active_resource.rb +2 -0
- data/lib/active_resource/associations.rb +174 -0
- data/lib/journey.rb +8 -0
- data/lib/journey/configurable.rb +31 -0
- data/lib/journey/configuration.rb +21 -0
- data/lib/journey/resource.rb +19 -0
- data/lib/journey/resource/api.rb +13 -0
- data/lib/journey/resource/attribute_loading.rb +18 -0
- data/lib/journey/resource/enums.rb +34 -0
- data/lib/journey/resource/queries.rb +14 -0
- data/lib/journey/version.rb +9 -0
- data/spec/models/journey/configurable_spec.rb +48 -0
- data/spec/models/journey/configuration_spec.rb +39 -0
- data/spec/models/journey/resource_spec.rb +66 -0
- data/spec/spec_helper.rb +19 -0
- data/spec/support/configuration_cache.rb +10 -0
- data/spec/support/test_configuration.rb +10 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e479a384c70a25dae3045201d6aa4ca7bdbc2cbc
|
4
|
+
data.tar.gz: c41a09cfab41b72a5cde48002be0e73afedee615
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15e5882c91e38f6b5289bd0b4ca7ef021d8811eee5a55293d4c7142856b62e2a120727814c0a2a791d1fbe3bc7e0da69486398b016aec4698b64de8859a5388a
|
7
|
+
data.tar.gz: 735730f502bb4c33c653c70f0f5ef22cae41f7b8e3d8ae7f3280aafd8919bcd37347064bd2390b9e58f4e61689950e1a3997247555ffa93ea3e6e3a19ce1fef6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Dan Davey
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Journey
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'journey'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install journey
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/ROADMAP.md
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/journey.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'journey/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "embark-journey"
|
8
|
+
spec.version = Journey::VERSION::STRING
|
9
|
+
spec.authors = ["Dan Davey"]
|
10
|
+
spec.email = ["dan@recombinary.com"]
|
11
|
+
spec.description = %q{Extends ActiveResource to provide a base for Journey resources, supporting all attribute types}
|
12
|
+
spec.summary = %q{Journey API wrapper for Ruby}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'active_attr', '~> 0.8.2'
|
22
|
+
spec.add_runtime_dependency 'activeresource', '~> 4.0.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.1.1'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0.beta1'
|
27
|
+
spec.add_development_dependency 'dotenv', '~> 0.9.0'
|
28
|
+
spec.add_development_dependency 'pry', '~> 0.9.12.4'
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
module ActiveResource::Associations
|
2
|
+
|
3
|
+
module Builder
|
4
|
+
autoload :Association, 'active_resource/associations/builder/association'
|
5
|
+
autoload :HasMany, 'active_resource/associations/builder/has_many'
|
6
|
+
autoload :HasOne, 'active_resource/associations/builder/has_one'
|
7
|
+
autoload :BelongsTo, 'active_resource/associations/builder/belongs_to'
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
# Specifies a one-to-many association.
|
13
|
+
#
|
14
|
+
# === Options
|
15
|
+
# [:class_name]
|
16
|
+
# Specify the class name of the association. This class name would
|
17
|
+
# be used for resolving the association class.
|
18
|
+
#
|
19
|
+
# ==== Example for [:class_name] - option
|
20
|
+
# GET /posts/123.json delivers following response body:
|
21
|
+
# {
|
22
|
+
# title: "ActiveResource now has associations",
|
23
|
+
# body: "Lorem Ipsum"
|
24
|
+
# comments: [
|
25
|
+
# {
|
26
|
+
# content: "..."
|
27
|
+
# },
|
28
|
+
# {
|
29
|
+
# content: "..."
|
30
|
+
# }
|
31
|
+
# ]
|
32
|
+
# }
|
33
|
+
# ====
|
34
|
+
#
|
35
|
+
# <tt>has_many :comments, :class_name => 'myblog/comment'</tt>
|
36
|
+
# Would resolve those comments into the <tt>Myblog::Comment</tt> class.
|
37
|
+
#
|
38
|
+
# If the response body does not contain an attribute matching the association name
|
39
|
+
# a request sent to the index action under the current resource.
|
40
|
+
# For the example above, if the comments are not present the requested path would be:
|
41
|
+
# GET /posts/123/comments.xml
|
42
|
+
def has_many(name, options = {})
|
43
|
+
Builder::HasMany.build(self, name, options)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Specifies a one-to-one association.
|
47
|
+
#
|
48
|
+
# === Options
|
49
|
+
# [:class_name]
|
50
|
+
# Specify the class name of the association. This class name would
|
51
|
+
# be used for resolving the association class.
|
52
|
+
#
|
53
|
+
# ==== Example for [:class_name] - option
|
54
|
+
# GET /posts/1.json delivers following response body:
|
55
|
+
# {
|
56
|
+
# title: "ActiveResource now has associations",
|
57
|
+
# body: "Lorem Ipsum",
|
58
|
+
# author: {
|
59
|
+
# name: "Gabby Blogger",
|
60
|
+
# }
|
61
|
+
# }
|
62
|
+
# ====
|
63
|
+
#
|
64
|
+
# <tt>has_one :author, :class_name => 'myblog/author'</tt>
|
65
|
+
# Would resolve this author into the <tt>Myblog::Author</tt> class.
|
66
|
+
#
|
67
|
+
# If the response body does not contain an attribute matching the association name
|
68
|
+
# a request is sent to a singelton path under the current resource.
|
69
|
+
# For example, if a Product class <tt>has_one :inventory</tt> calling <tt>Product#inventory</tt>
|
70
|
+
# will generate a request on /product/:product_id/inventory.json.
|
71
|
+
#
|
72
|
+
def has_one(name, options = {})
|
73
|
+
Builder::HasOne.build(self, name, options)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Specifies a one-to-one association with another class. This class should only be used
|
77
|
+
# if this class contains the foreign key.
|
78
|
+
#
|
79
|
+
# Methods will be added for retrieval and query for a single associated object, for which
|
80
|
+
# this object holds an id:
|
81
|
+
#
|
82
|
+
# [association(force_reload = false)]
|
83
|
+
# Returns the associated object. +nil+ is returned if the foreign key is +nil+.
|
84
|
+
# Throws a ActiveResource::ResourceNotFound exception if the foreign key is not +nil+
|
85
|
+
# and the resource is not found.
|
86
|
+
#
|
87
|
+
# (+association+ is replaced with the symbol passed as the first argument, so
|
88
|
+
# <tt>belongs_to :post</tt> would add among others <tt>post.nil?</tt>.
|
89
|
+
#
|
90
|
+
# === Example
|
91
|
+
#
|
92
|
+
# A Comment class declaress <tt>belongs_to :post</tt>, which will add:
|
93
|
+
# * <tt>Comment#post</tt> (similar to <tt>Post.find(post_id)</tt>)
|
94
|
+
# The declaration can also include an options hash to specialize the behavior of the association.
|
95
|
+
#
|
96
|
+
# === Options
|
97
|
+
# [:class_name]
|
98
|
+
# Specify the class name for the association. Use it only if that name canÄt be inferred from association name.
|
99
|
+
# So <tt>belongs_to :post</tt> will by default be linked to the Post class, but if the real class name is Article,
|
100
|
+
# you'll have to specify it with whis option.
|
101
|
+
# [:foreign_key]
|
102
|
+
# Specify the foreign key used for the association. By default this is guessed to be the name
|
103
|
+
# of the association with an "_id" suffix. So a class that defines a <tt>belongs_to :post</tt>
|
104
|
+
# association will use "post_id" as the default <tt>:foreign_key</tt>. Similarly,
|
105
|
+
# <tt>belongs_to :article, :class_name => "Post"</tt> will use a foreign key
|
106
|
+
# of "article_id".
|
107
|
+
#
|
108
|
+
# Option examples:
|
109
|
+
# <tt>belongs_to :customer, :class_name => 'User'</tt>
|
110
|
+
# Creates a belongs_to association called customer which is represented through the <tt>User</tt> class.
|
111
|
+
#
|
112
|
+
# <tt>belongs_to :customer, :foreign_key => 'user_id'</tt>
|
113
|
+
# Creates a belongs_to association called customer which would be resolved by the foreign_key <tt>user_id</tt> instead of <tt>customer_id</tt>
|
114
|
+
#
|
115
|
+
def belongs_to(name, options={})
|
116
|
+
Builder::BelongsTo.build(self, name, options)
|
117
|
+
end
|
118
|
+
|
119
|
+
# Defines the belongs_to association finder method
|
120
|
+
def defines_belongs_to_finder_method(method_name, association_model, finder_key)
|
121
|
+
ivar_name = :"@#{method_name}"
|
122
|
+
|
123
|
+
if method_defined?(method_name)
|
124
|
+
instance_variable_set(ivar_name, nil)
|
125
|
+
remove_method(method_name)
|
126
|
+
end
|
127
|
+
|
128
|
+
define_method(method_name) do
|
129
|
+
if instance_variable_defined?(ivar_name)
|
130
|
+
instance_variable_get(ivar_name)
|
131
|
+
elsif attributes.include?(method_name)
|
132
|
+
attributes[method_name]
|
133
|
+
elsif association_id = send(finder_key)
|
134
|
+
return nil if finder_key.blank?
|
135
|
+
instance_variable_set(ivar_name, association_model.find(association_id))
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
define_method("#{method_name}=") do |obj|
|
140
|
+
instance_variable_set(ivar_name, obj)
|
141
|
+
attributes["#{method_name}_id"] = obj.try(:id)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def defines_has_many_finder_method(method_name, association_model)
|
146
|
+
ivar_name = :"@#{method_name}"
|
147
|
+
|
148
|
+
define_method(method_name) do
|
149
|
+
if instance_variable_defined?(ivar_name)
|
150
|
+
instance_variable_get(ivar_name)
|
151
|
+
elsif attributes.include?(method_name)
|
152
|
+
attributes[method_name]
|
153
|
+
else
|
154
|
+
instance_variable_set(ivar_name, association_model.find(:all, :params => { :q => {:"#{self.class.element_name}_id" => self.id} }))
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Defines the has_one association
|
160
|
+
def defines_has_one_finder_method(method_name, association_model)
|
161
|
+
ivar_name = :"@#{method_name}"
|
162
|
+
|
163
|
+
define_method(method_name) do
|
164
|
+
if instance_variable_defined?(ivar_name)
|
165
|
+
instance_variable_get(ivar_name)
|
166
|
+
elsif attributes.include?(method_name)
|
167
|
+
attributes[method_name]
|
168
|
+
else
|
169
|
+
instance_variable_set(ivar_name, association_model.find(:params => { :q => { :"#{self.class.element_name}_id" => self.id} }))
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
data/lib/journey.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'journey/configuration'
|
2
|
+
require 'logger'
|
3
|
+
|
4
|
+
module Journey
|
5
|
+
def self.configuration
|
6
|
+
@@configuration ||= Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configuration=(configuration)
|
10
|
+
@@configuration = configuration
|
11
|
+
@@configuration.propagate!
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure(attributes = {})
|
15
|
+
configuration = Configuration.new(attributes)
|
16
|
+
yield(configuration) if block_given?
|
17
|
+
self.configuration = configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.logger=(logger)
|
21
|
+
@@logger = logger
|
22
|
+
ActiveResource::Base.logger = logger
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.logger
|
26
|
+
@@logger
|
27
|
+
end
|
28
|
+
|
29
|
+
self.logger = Logger.new(STDOUT)
|
30
|
+
self.logger.level = Logger::WARN
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_attr'
|
2
|
+
require 'journey/resource'
|
3
|
+
|
4
|
+
module Journey
|
5
|
+
class Configuration
|
6
|
+
include ActiveAttr::Attributes
|
7
|
+
include ActiveAttr::MassAssignment
|
8
|
+
|
9
|
+
attribute :api_site
|
10
|
+
attribute :api_user
|
11
|
+
attribute :api_password
|
12
|
+
|
13
|
+
def propagate!
|
14
|
+
(Resource.descendants << Resource).each do |r|
|
15
|
+
r.site = api_site
|
16
|
+
r.user = api_user
|
17
|
+
r.password = api_password
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_resource/active_resource'
|
2
|
+
module Journey
|
3
|
+
class Resource < ActiveResource::Base
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'journey/resource/api'
|
8
|
+
require 'journey/resource/attribute_loading'
|
9
|
+
require 'journey/resource/enums'
|
10
|
+
require 'journey/resource/queries'
|
11
|
+
|
12
|
+
class Journey::Resource
|
13
|
+
include API
|
14
|
+
include Queries
|
15
|
+
include Enums
|
16
|
+
include AttributeLoading
|
17
|
+
end
|
18
|
+
|
19
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Journey::Resource::API
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
self.format = :json
|
8
|
+
self.include_root_in_json = true
|
9
|
+
# self.site = ENV['JOURNEY_API_ENDPOINT']
|
10
|
+
# self.user = ENV['JOURNEY_API_USERNAME']
|
11
|
+
# self.password = ENV['JOURNEY_API_KEY']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Journey::Resource::AttributeLoading
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
# uses defined setters in place of attributes[key] where possible,
|
8
|
+
# for the purpose of enums
|
9
|
+
def load(attributes, remove_root = false, persisted = false)
|
10
|
+
super(attributes, remove_root, persisted).tap do
|
11
|
+
attributes.each do |key, value|
|
12
|
+
send("#{key}=", value) if respond_to?("#{key}=")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Journey::Resource::Enums
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
def self.enum(attr, collection=[])
|
8
|
+
collection_const_name = attr.to_s.pluralize.upcase.to_sym
|
9
|
+
const_set collection_const_name, collection.freeze
|
10
|
+
define_method "#{attr}_values" do
|
11
|
+
self.class.const_get(collection_const_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
instance_eval do
|
15
|
+
attr_accessor :"#{attr}_index"
|
16
|
+
end
|
17
|
+
|
18
|
+
define_method attr do
|
19
|
+
value = attributes[attr.to_s].presence
|
20
|
+
if value.is_a?(Fixnum)
|
21
|
+
send("#{attr}_values")[value]
|
22
|
+
else
|
23
|
+
value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method "#{attr}=" do |value|
|
28
|
+
attributes[attr.to_s] = value.presence
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Journey::Resource::Queries
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
def self.where(clauses = {})
|
8
|
+
sort = clauses.delete(:sort)
|
9
|
+
params = { q: clauses }
|
10
|
+
params[:sort] = sort if sort
|
11
|
+
super(params)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Journey
|
4
|
+
describe "configurable" do
|
5
|
+
let(:api_site) { 'https://mysite.dev/' }
|
6
|
+
|
7
|
+
describe '.configure' do
|
8
|
+
it 'configures with a block' do
|
9
|
+
expect(Journey.configuration.api_site).not_to equal api_site
|
10
|
+
Journey.configure { |c| c.api_site = api_site }
|
11
|
+
expect(Journey.configuration.api_site).to equal api_site
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'configures with a hash' do
|
15
|
+
expect(Journey.configuration.api_site).not_to equal api_site
|
16
|
+
Journey.configure({ api_site: api_site })
|
17
|
+
expect(Journey.configuration.api_site).to equal api_site
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.configuration=' do
|
22
|
+
it 'configures with a configuration object' do
|
23
|
+
expect(Journey.configuration.api_site).not_to equal api_site
|
24
|
+
|
25
|
+
configuration = Configuration.new(api_site: api_site)
|
26
|
+
Journey.configuration=(configuration)
|
27
|
+
|
28
|
+
expect(Journey.configuration.api_site).to equal api_site
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.logger=' do
|
33
|
+
it 'sets the logger for ActiveResource' do
|
34
|
+
logger = Logger.new(STDOUT)
|
35
|
+
Journey.logger = logger
|
36
|
+
expect(ActiveResource::Base.logger).to equal logger
|
37
|
+
expect(Journey.logger).to equal(logger)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '.logger' do
|
42
|
+
it 'returns a default logger if one isnt set' do
|
43
|
+
expect(Journey.logger).to_not be_nil
|
44
|
+
expect(Journey.logger).to respond_to(:info)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Journey
|
4
|
+
class PrefixedResource < Resource
|
5
|
+
self.prefix = '/admin/'
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Configuration do
|
9
|
+
let(:configuration) { Configuration.new }
|
10
|
+
|
11
|
+
it 'has nil defaults' do
|
12
|
+
expect(configuration.api_site).to be_nil
|
13
|
+
expect(configuration.api_user).to be_nil
|
14
|
+
expect(configuration.api_password).to be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#propagate!' do
|
18
|
+
it 'updates all descended records' do
|
19
|
+
configuration.api_site = 'https://custom.journeyapps.com/api/v1'
|
20
|
+
configuration.api_user = 'dan'
|
21
|
+
configuration.api_password = 'mellon'
|
22
|
+
|
23
|
+
[Resource, PrefixedResource].each do |klass|
|
24
|
+
expect(klass.site.to_s).not_to eq configuration.api_site
|
25
|
+
expect(klass.user).not_to eq configuration.api_user
|
26
|
+
expect(klass.password).not_to eq configuration.api_password
|
27
|
+
end
|
28
|
+
|
29
|
+
configuration.propagate!
|
30
|
+
|
31
|
+
[Resource, PrefixedResource].each do |klass|
|
32
|
+
expect(klass.site.to_s).to eq configuration.api_site
|
33
|
+
expect(klass.user).to eq configuration.api_user
|
34
|
+
expect(klass.password).to eq configuration.api_password
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Journey::Resource do
|
4
|
+
let(:klass) do
|
5
|
+
Class.new(Journey::Resource) do
|
6
|
+
self.element_name = 'technician'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '::Enums' do
|
11
|
+
describe '.enum' do
|
12
|
+
let(:statuses) { %w(Active Inactive) }
|
13
|
+
before do
|
14
|
+
klass.enum :status, statuses
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'stores the collection' do
|
18
|
+
expect(klass::STATUSES).to eq(statuses)
|
19
|
+
expect(klass.new.status_values).to eq(statuses)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'gets and sets enumerated attributes' do
|
23
|
+
r = klass.create(name: 'X', status: 'Inactive')
|
24
|
+
expect(r).to be_persisted
|
25
|
+
r.status = 'Active'
|
26
|
+
r.save
|
27
|
+
r.reload
|
28
|
+
expect(r.status).to eq('Active')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'sets nil attribute when receiving a blank value' do
|
32
|
+
r = klass.create(name: 'X', status: 'Inactive')
|
33
|
+
expect(r).to be_persisted
|
34
|
+
r.status = ''
|
35
|
+
r.save
|
36
|
+
r.reload
|
37
|
+
expect(r.status).to be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'gets and sets enumerated attributes as a hash' do
|
41
|
+
r = klass.create(name: 'X', status: 'Inactive')
|
42
|
+
expect(r).to be_persisted
|
43
|
+
r.update_attributes(status: '')
|
44
|
+
r.save
|
45
|
+
r.reload
|
46
|
+
expect(r.status).to be_nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '::Queries' do
|
52
|
+
describe '.where' do
|
53
|
+
|
54
|
+
it 'returns matching objects, sorted by attribute' do
|
55
|
+
klass.all.each(&:destroy)
|
56
|
+
|
57
|
+
klass.create(name: 'Z', status: 'Active')
|
58
|
+
klass.create(name: 'M', status: 'Inactive')
|
59
|
+
klass.create(name: 'A', status: 'Active')
|
60
|
+
|
61
|
+
collection = klass.where(status: 'Active', sort: { name: :asc })
|
62
|
+
expect(collection.map(&:name)).to eq %w[A Z]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'journey'
|
3
|
+
|
4
|
+
require 'dotenv'
|
5
|
+
Dotenv.load
|
6
|
+
|
7
|
+
Dir["spec/support/**/*.rb"].each { |f| require "./#{f}" }
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.filter_run :focus
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.order = 'random'
|
13
|
+
|
14
|
+
config.before(:suite){ TestConfiguration.configure_for_test }
|
15
|
+
|
16
|
+
config.before(:each){ ConfigurationCache.pull }
|
17
|
+
config.after(:each){ ConfigurationCache.push }
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embark-journey
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Davey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: active_attr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activeresource
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 10.1.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 10.1.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.0.0.beta1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.0.0.beta1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.9.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.9.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.9.12.4
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.9.12.4
|
111
|
+
description: Extends ActiveResource to provide a base for Journey resources, supporting
|
112
|
+
all attribute types
|
113
|
+
email:
|
114
|
+
- dan@recombinary.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .rspec
|
121
|
+
- .ruby-version
|
122
|
+
- CHANGELOG.md
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- ROADMAP.md
|
127
|
+
- Rakefile
|
128
|
+
- journey.gemspec
|
129
|
+
- lib/active_resource/active_resource.rb
|
130
|
+
- lib/active_resource/associations.rb
|
131
|
+
- lib/journey.rb
|
132
|
+
- lib/journey/configurable.rb
|
133
|
+
- lib/journey/configuration.rb
|
134
|
+
- lib/journey/resource.rb
|
135
|
+
- lib/journey/resource/api.rb
|
136
|
+
- lib/journey/resource/attribute_loading.rb
|
137
|
+
- lib/journey/resource/enums.rb
|
138
|
+
- lib/journey/resource/queries.rb
|
139
|
+
- lib/journey/version.rb
|
140
|
+
- spec/models/journey/configurable_spec.rb
|
141
|
+
- spec/models/journey/configuration_spec.rb
|
142
|
+
- spec/models/journey/resource_spec.rb
|
143
|
+
- spec/spec_helper.rb
|
144
|
+
- spec/support/configuration_cache.rb
|
145
|
+
- spec/support/test_configuration.rb
|
146
|
+
homepage: ''
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
metadata: {}
|
150
|
+
post_install_message:
|
151
|
+
rdoc_options: []
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - '>='
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
requirements: []
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 2.0.3
|
167
|
+
signing_key:
|
168
|
+
specification_version: 4
|
169
|
+
summary: Journey API wrapper for Ruby
|
170
|
+
test_files:
|
171
|
+
- spec/models/journey/configurable_spec.rb
|
172
|
+
- spec/models/journey/configuration_spec.rb
|
173
|
+
- spec/models/journey/resource_spec.rb
|
174
|
+
- spec/spec_helper.rb
|
175
|
+
- spec/support/configuration_cache.rb
|
176
|
+
- spec/support/test_configuration.rb
|