context_exposer 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +13 -1
- data/README.md +186 -16
- data/lib/context_exposer.rb +15 -0
- data/lib/context_exposer/base_controller.rb +67 -47
- data/lib/context_exposer/cached_resource_controller.rb +10 -0
- data/lib/context_exposer/integrations.rb +8 -0
- data/lib/context_exposer/integrations/base.rb +15 -0
- data/lib/context_exposer/integrations/key_filter.rb +30 -0
- data/lib/context_exposer/integrations/with_decent_exposure.rb +19 -0
- data/lib/context_exposer/integrations/with_decorates_before.rb +31 -0
- data/lib/context_exposer/integrations/with_instance_vars.rb +19 -0
- data/lib/context_exposer/macros.rb +17 -0
- data/lib/context_exposer/patch/decorates_before_rendering.rb +179 -0
- data/lib/context_exposer/rails_config.rb +3 -0
- data/lib/context_exposer/resource_controller.rb +30 -8
- data/lib/context_exposer/version.rb +1 -1
- data/lib/context_exposer/view_context.rb +1 -1
- data/spec/app/items_spec.rb +36 -0
- data/spec/app/posts_spec.rb +29 -1
- data/spec/context_exposer/expose_resource_spec.rb +51 -38
- data/spec/context_exposer/expose_spec.rb +11 -10
- data/spec/dummy/app/controllers/items_controller.rb +12 -0
- data/spec/dummy/app/controllers/posts_controller.rb +3 -4
- data/spec/dummy/app/views/items/index.html.erb +2 -0
- data/spec/dummy/app/views/items/show.html.erb +2 -0
- data/spec/dummy/app/views/posts/index.html.erb +2 -1
- data/spec/dummy/app/views/posts/show.html.erb +2 -1
- data/spec/dummy/config/initializers/context_exposer.rb +1 -0
- data/spec/dummy/config/routes.rb +1 -57
- data/spec/dummy/log/test.log +483 -0
- data/spec/dummy_spec_helper.rb +82 -0
- data/spec/spec_helper.rb +13 -1
- data/spec/support/decorators/base_decorator.rb +22 -0
- data/spec/support/decorators/item_decorator.rb +11 -0
- data/spec/support/decorators/post_decorator.rb +5 -0
- data/spec/support/models/base.rb +18 -0
- data/spec/support/models/base/clazz_methods.rb +29 -0
- data/spec/support/models/item.rb +9 -0
- data/spec/support/models/post.rb +5 -0
- metadata +38 -2
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spork'
|
3
|
+
|
4
|
+
#uncomment the following line to use spork with the debugger
|
5
|
+
#require 'spork/ext/ruby-debug'
|
6
|
+
|
7
|
+
Spork.prefork do
|
8
|
+
# Loading more in this block will cause your tests to run faster. However,
|
9
|
+
# if you change any configuration or code from libraries loaded here, you'll
|
10
|
+
# need to restart spork for it take effect.
|
11
|
+
|
12
|
+
ENV["RAILS_ENV"] ||= 'test'
|
13
|
+
require 'rails'
|
14
|
+
require 'spork'
|
15
|
+
|
16
|
+
require "rspec"
|
17
|
+
|
18
|
+
require 'decent_exposure'
|
19
|
+
require 'decorates_before_rendering'
|
20
|
+
|
21
|
+
# require 'factory_girl'
|
22
|
+
|
23
|
+
# Configure Rails Envinronment
|
24
|
+
ENV["RAILS_ENV"] = "test"
|
25
|
+
|
26
|
+
# Load support files
|
27
|
+
Dir["#{File.dirname(__FILE__)}/support/models/**/*.rb"].each { |f| require f }
|
28
|
+
Dir["#{File.dirname(__FILE__)}/support/models/*.rb"].each { |f| require f }
|
29
|
+
Dir["#{File.dirname(__FILE__)}/support/decorators/*.rb"].each { |f| require f }
|
30
|
+
|
31
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
32
|
+
|
33
|
+
require "rails/test_help"
|
34
|
+
require "rspec/rails"
|
35
|
+
|
36
|
+
ActionMailer::Base.delivery_method = :test
|
37
|
+
ActionMailer::Base.perform_deliveries = true
|
38
|
+
ActionMailer::Base.default_url_options[:host] = "test.com"
|
39
|
+
|
40
|
+
Rails.backtrace_cleaner.remove_silencers!
|
41
|
+
|
42
|
+
# Configure capybara for integration testing
|
43
|
+
require "capybara/rails"
|
44
|
+
Capybara.default_driver = :rack_test
|
45
|
+
|
46
|
+
include Rails.application.routes.url_helpers
|
47
|
+
|
48
|
+
# Load support files
|
49
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
50
|
+
|
51
|
+
RSpec.configure do |config|
|
52
|
+
# Remove this line if you don't want RSpec's should and should_not
|
53
|
+
# methods or matchers
|
54
|
+
require 'rspec/expectations'
|
55
|
+
config.include RSpec::Matchers
|
56
|
+
|
57
|
+
config.include RSpec::Rails::RequestExampleGroup, type: :feature
|
58
|
+
|
59
|
+
# config.include FactoryGirl::Syntax::Methods
|
60
|
+
|
61
|
+
# == Mock Framework
|
62
|
+
config.mock_with :rspec
|
63
|
+
|
64
|
+
# config.include Mongoid::Matchers
|
65
|
+
|
66
|
+
# Clean up the database
|
67
|
+
|
68
|
+
# require 'database_cleaner'
|
69
|
+
# config.before(:suite) do
|
70
|
+
# DatabaseCleaner[:mongoid].strategy = :truncation
|
71
|
+
# end
|
72
|
+
|
73
|
+
# config.before(:each) do
|
74
|
+
# DatabaseCleaner.clean
|
75
|
+
# end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
Spork.each_run do
|
80
|
+
# This code will be run each time you run your specs.
|
81
|
+
# FactoryGirl.reload
|
82
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
|
4
|
-
require
|
4
|
+
require "rspec"
|
5
|
+
|
6
|
+
require 'decent_exposure'
|
7
|
+
require 'decorates_before_rendering'
|
8
|
+
|
9
|
+
require 'context_exposer'
|
10
|
+
|
11
|
+
require 'action_controller'
|
12
|
+
|
13
|
+
# Load support files
|
14
|
+
Dir["#{File.dirname(__FILE__)}/support/models/**/*.rb"].each { |f| require f }
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/models/*.rb"].each { |f| require f }
|
16
|
+
Dir["#{File.dirname(__FILE__)}/support/decorators/*.rb"].each { |f| require f }
|
5
17
|
|
6
18
|
RSpec.configure do |config|
|
7
19
|
# some (optional) config here
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class BaseDecorator
|
2
|
+
attr_reader :obj
|
3
|
+
|
4
|
+
def initialize obj = nil
|
5
|
+
@obj = nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.decorate obj
|
9
|
+
self.new obj
|
10
|
+
end
|
11
|
+
|
12
|
+
def decorate obj
|
13
|
+
@obj = obj
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def == other
|
18
|
+
other == obj || other == self
|
19
|
+
end
|
20
|
+
|
21
|
+
delegate :name, :to_s, to: :obj
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Base
|
2
|
+
module ClazzMethods
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def model_name
|
7
|
+
self.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def find id
|
11
|
+
list.first
|
12
|
+
end
|
13
|
+
|
14
|
+
def all
|
15
|
+
list
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def add obj
|
21
|
+
list << obj
|
22
|
+
end
|
23
|
+
|
24
|
+
def list
|
25
|
+
@list ||= []
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: context_exposer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristian Mandrup
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,9 +55,20 @@ files:
|
|
55
55
|
- context_exposer.gemspec
|
56
56
|
- lib/context_exposer.rb
|
57
57
|
- lib/context_exposer/base_controller.rb
|
58
|
+
- lib/context_exposer/cached_resource_controller.rb
|
59
|
+
- lib/context_exposer/integrations.rb
|
60
|
+
- lib/context_exposer/integrations/base.rb
|
61
|
+
- lib/context_exposer/integrations/key_filter.rb
|
62
|
+
- lib/context_exposer/integrations/with_decent_exposure.rb
|
63
|
+
- lib/context_exposer/integrations/with_decorates_before.rb
|
64
|
+
- lib/context_exposer/integrations/with_instance_vars.rb
|
65
|
+
- lib/context_exposer/macros.rb
|
66
|
+
- lib/context_exposer/patch/decorates_before_rendering.rb
|
67
|
+
- lib/context_exposer/rails_config.rb
|
58
68
|
- lib/context_exposer/resource_controller.rb
|
59
69
|
- lib/context_exposer/version.rb
|
60
70
|
- lib/context_exposer/view_context.rb
|
71
|
+
- spec/app/items_spec.rb
|
61
72
|
- spec/app/posts_spec.rb
|
62
73
|
- spec/context_exposer/expose_resource_spec.rb
|
63
74
|
- spec/context_exposer/expose_spec.rb
|
@@ -66,10 +77,13 @@ files:
|
|
66
77
|
- spec/dummy/app/assets/javascripts/application.js
|
67
78
|
- spec/dummy/app/assets/stylesheets/application.css
|
68
79
|
- spec/dummy/app/controllers/application_controller.rb
|
80
|
+
- spec/dummy/app/controllers/items_controller.rb
|
69
81
|
- spec/dummy/app/controllers/posts_controller.rb
|
70
82
|
- spec/dummy/app/helpers/application_helper.rb
|
71
83
|
- spec/dummy/app/mailers/.gitkeep
|
72
84
|
- spec/dummy/app/models/.gitkeep
|
85
|
+
- spec/dummy/app/views/items/index.html.erb
|
86
|
+
- spec/dummy/app/views/items/show.html.erb
|
73
87
|
- spec/dummy/app/views/layouts/application.html.erb
|
74
88
|
- spec/dummy/app/views/posts/index.html.erb
|
75
89
|
- spec/dummy/app/views/posts/show.html.erb
|
@@ -81,6 +95,7 @@ files:
|
|
81
95
|
- spec/dummy/config/environments/production.rb
|
82
96
|
- spec/dummy/config/environments/test.rb
|
83
97
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
98
|
+
- spec/dummy/config/initializers/context_exposer.rb
|
84
99
|
- spec/dummy/config/initializers/inflections.rb
|
85
100
|
- spec/dummy/config/initializers/mime_types.rb
|
86
101
|
- spec/dummy/config/initializers/secret_token.rb
|
@@ -96,7 +111,15 @@ files:
|
|
96
111
|
- spec/dummy/public/500.html
|
97
112
|
- spec/dummy/public/favicon.ico
|
98
113
|
- spec/dummy/script/rails
|
114
|
+
- spec/dummy_spec_helper.rb
|
99
115
|
- spec/spec_helper.rb
|
116
|
+
- spec/support/decorators/base_decorator.rb
|
117
|
+
- spec/support/decorators/item_decorator.rb
|
118
|
+
- spec/support/decorators/post_decorator.rb
|
119
|
+
- spec/support/models/base.rb
|
120
|
+
- spec/support/models/base/clazz_methods.rb
|
121
|
+
- spec/support/models/item.rb
|
122
|
+
- spec/support/models/post.rb
|
100
123
|
homepage: https://github.com/kristianmandrup/context_exposer
|
101
124
|
licenses:
|
102
125
|
- MIT
|
@@ -123,6 +146,7 @@ specification_version: 4
|
|
123
146
|
summary: The Context object becomes the single communication point between View and
|
124
147
|
Controller
|
125
148
|
test_files:
|
149
|
+
- spec/app/items_spec.rb
|
126
150
|
- spec/app/posts_spec.rb
|
127
151
|
- spec/context_exposer/expose_resource_spec.rb
|
128
152
|
- spec/context_exposer/expose_spec.rb
|
@@ -131,10 +155,13 @@ test_files:
|
|
131
155
|
- spec/dummy/app/assets/javascripts/application.js
|
132
156
|
- spec/dummy/app/assets/stylesheets/application.css
|
133
157
|
- spec/dummy/app/controllers/application_controller.rb
|
158
|
+
- spec/dummy/app/controllers/items_controller.rb
|
134
159
|
- spec/dummy/app/controllers/posts_controller.rb
|
135
160
|
- spec/dummy/app/helpers/application_helper.rb
|
136
161
|
- spec/dummy/app/mailers/.gitkeep
|
137
162
|
- spec/dummy/app/models/.gitkeep
|
163
|
+
- spec/dummy/app/views/items/index.html.erb
|
164
|
+
- spec/dummy/app/views/items/show.html.erb
|
138
165
|
- spec/dummy/app/views/layouts/application.html.erb
|
139
166
|
- spec/dummy/app/views/posts/index.html.erb
|
140
167
|
- spec/dummy/app/views/posts/show.html.erb
|
@@ -146,6 +173,7 @@ test_files:
|
|
146
173
|
- spec/dummy/config/environments/production.rb
|
147
174
|
- spec/dummy/config/environments/test.rb
|
148
175
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
176
|
+
- spec/dummy/config/initializers/context_exposer.rb
|
149
177
|
- spec/dummy/config/initializers/inflections.rb
|
150
178
|
- spec/dummy/config/initializers/mime_types.rb
|
151
179
|
- spec/dummy/config/initializers/secret_token.rb
|
@@ -161,5 +189,13 @@ test_files:
|
|
161
189
|
- spec/dummy/public/500.html
|
162
190
|
- spec/dummy/public/favicon.ico
|
163
191
|
- spec/dummy/script/rails
|
192
|
+
- spec/dummy_spec_helper.rb
|
164
193
|
- spec/spec_helper.rb
|
194
|
+
- spec/support/decorators/base_decorator.rb
|
195
|
+
- spec/support/decorators/item_decorator.rb
|
196
|
+
- spec/support/decorators/post_decorator.rb
|
197
|
+
- spec/support/models/base.rb
|
198
|
+
- spec/support/models/base/clazz_methods.rb
|
199
|
+
- spec/support/models/item.rb
|
200
|
+
- spec/support/models/post.rb
|
165
201
|
has_rdoc:
|