neo-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ require 'active_support/concern'
2
+
1
3
  module Neo
2
4
  module Rails
3
5
  # A really simple version of exposing variables to the view.
@@ -9,13 +11,13 @@ module Neo
9
11
 
10
12
  included do
11
13
  class_attribute :exposed_vars
12
- self.exposed_vars = Set.new
14
+ self.exposed_vars ||= Set.new
13
15
  end
14
16
 
15
17
  module ClassMethods
16
18
  # Defines the variables to be exposed.
17
19
  def exposes(*names)
18
- exposures = names.map(&:to_sym).reject { |name| exposed_vars.include?(name) }
20
+ exposures = names.map(&:to_sym)
19
21
  self.exposed_vars.merge exposures
20
22
  attr_reader *exposures
21
23
  helper_method *exposures
@@ -1,3 +1,5 @@
1
+ require 'active_support/concern'
2
+
1
3
  module Neo
2
4
  module Rails
3
5
  # Enables controller actions to have scenarios, which will be applied
@@ -1,3 +1,5 @@
1
+ require 'active_support/concern'
2
+
1
3
  module Neo
2
4
  module Rails
3
5
  module Scenarios
@@ -1,5 +1,5 @@
1
1
  module Neo
2
2
  module Rails
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/neo-rails.gemspec CHANGED
@@ -17,4 +17,6 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_development_dependency "rake"
19
19
  gem.add_development_dependency "minitest"
20
+ gem.add_development_dependency "rails", "~> 3.2.7"
21
+ gem.add_development_dependency "rack-test"
20
22
  end
@@ -0,0 +1,117 @@
1
+ require 'helper'
2
+
3
+ require 'rack/test'
4
+ require 'action_controller/railtie'
5
+
6
+ require 'neo/rails/exposure'
7
+
8
+
9
+ class ExposureTestController < ActionController::Base
10
+ include Neo::Rails::Exposure
11
+
12
+ exposes :a, :b
13
+
14
+ def foo
15
+ render :text => "bar"
16
+ end
17
+
18
+ def expose_via_value
19
+ expose :a, "a"
20
+ expose :b, "b"
21
+ render :inline => %{ar=#{a},ah=<%= a %>,br=#{b},bh=<%= b %>}
22
+ end
23
+
24
+ def expose_via_block
25
+ expose(:a) { "a" }
26
+ expose(:b) { "b" }
27
+ render :inline => %{ar=#{a},ah=<%= a %>,br=#{b},bh=<%= b %>}
28
+ end
29
+
30
+ def expose_with_error
31
+ expose(:unknown) { "unknown" }
32
+ end
33
+ end
34
+
35
+ class OtherExposureTestController < ExposureTestController
36
+ include Neo::Rails::Exposure
37
+
38
+ exposes :c
39
+
40
+ def bar
41
+ expose :a, "a"
42
+ expose :b, "b"
43
+ expose :c, "c"
44
+
45
+ render :inline => "<%= a %>;<%= b %>;<%= c %>"
46
+ end
47
+
48
+ end
49
+
50
+ class ATestController < ExposureTestController
51
+ exposes :z
52
+
53
+ def baz
54
+ expose :z, "z"
55
+ render :inline => "<%= z %>"
56
+ end
57
+ end
58
+
59
+ class BTestController < ExposureTestController
60
+ exposes :z
61
+
62
+ def baz
63
+ expose :z, "z"
64
+ render :inline => "<%= z %>"
65
+ end
66
+ end
67
+
68
+ class ExposureTestApp < Rails::Application
69
+ routes.draw do
70
+ match ":action" => ExposureTestController
71
+ match "other/:action" => OtherExposureTestController
72
+ match "a/:action" => ATestController
73
+ match "b/:action" => BTestController
74
+ end
75
+
76
+ config.session_store :disabled
77
+ config.middleware.delete Rails::Rack::Logger
78
+ config.middleware.delete ActionDispatch::ShowExceptions
79
+ config.middleware.delete ActionDispatch::DebugExceptions
80
+ end
81
+
82
+ class ExposureTest < NeoRailsCase
83
+ include Rack::Test::Methods
84
+
85
+ def app
86
+ ExposureTestApp
87
+ end
88
+
89
+ test "should expose variable per value" do
90
+ get :expose_via_value
91
+ assert_equal "ar=a,ah=a,br=b,bh=b", last_response.body
92
+ end
93
+
94
+ test "should expose variable per block" do
95
+ get :expose_via_block
96
+ assert_equal "ar=a,ah=a,br=b,bh=b", last_response.body
97
+ end
98
+
99
+ test "should raise an error when exposing an undeclared variable" do
100
+ assert_raises Neo::Rails::Exposure::UndeclaredVariableError do
101
+ get :expose_with_error
102
+ end
103
+ end
104
+
105
+ test "exposes vars in subclass" do
106
+ get "other/bar"
107
+ assert_equal "a;b;c", last_response.body
108
+ end
109
+
110
+ test "exposes var in subclass parallel" do
111
+ get "a/baz"
112
+ assert_equal "z", last_response.body
113
+
114
+ get "b/baz"
115
+ assert_equal "z", last_response.body
116
+ end
117
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-06 00:00:00.000000000 Z
13
+ date: 2012-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -44,6 +44,38 @@ dependencies:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rails
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.7
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 3.2.7
63
+ - !ruby/object:Gem::Dependency
64
+ name: rack-test
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
47
79
  description: Some Rails helpers
48
80
  email:
49
81
  - jt@neopoly.de
@@ -71,6 +103,7 @@ files:
71
103
  - lib/neo/rails/scenarios/test_helper.rb
72
104
  - lib/neo/rails/version.rb
73
105
  - neo-rails.gemspec
106
+ - test/exposure_test.rb
74
107
  - test/helper.rb
75
108
  - test/mock_test.rb
76
109
  - test/presenter_test.rb
@@ -99,6 +132,8 @@ signing_key:
99
132
  specification_version: 3
100
133
  summary: Rails mocks, presenters, exposure and scenarios
101
134
  test_files:
135
+ - test/exposure_test.rb
102
136
  - test/helper.rb
103
137
  - test/mock_test.rb
104
138
  - test/presenter_test.rb
139
+ has_rdoc: