moonrope 1.4.1 → 2.0.0
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 -0
- data/Gemfile.lock +47 -0
- data/MIT-LICENCE +20 -0
- data/README.md +24 -0
- data/bin/moonrope +28 -0
- data/docs/authentication.md +114 -0
- data/docs/controllers.md +106 -0
- data/docs/exceptions.md +27 -0
- data/docs/introduction.md +29 -0
- data/docs/structures.md +214 -0
- data/example/authentication.rb +50 -0
- data/example/controllers/meta_controller.rb +14 -0
- data/example/controllers/users_controller.rb +92 -0
- data/example/structures/pet_structure.rb +12 -0
- data/example/structures/user_structure.rb +35 -0
- data/html/assets/lock.svg +3 -0
- data/html/assets/reset.css +101 -0
- data/html/assets/style.css +348 -0
- data/html/assets/tool.svg +4 -0
- data/html/assets/try.js +151 -0
- data/html/authenticators/default.html +191 -0
- data/html/controllers/meta/version.html +144 -0
- data/html/controllers/meta.html +73 -0
- data/html/controllers/users/create.html +341 -0
- data/html/controllers/users/list.html +348 -0
- data/html/controllers/users/show.html +261 -0
- data/html/controllers/users/update.html +387 -0
- data/html/controllers/users.html +93 -0
- data/html/index.html +166 -0
- data/html/moonrope.txt +0 -0
- data/html/structures/pet.html +176 -0
- data/html/structures/user.html +338 -0
- data/lib/moonrope/action.rb +165 -37
- data/lib/moonrope/authenticator.rb +39 -0
- data/lib/moonrope/base.rb +24 -6
- data/lib/moonrope/controller.rb +4 -2
- data/lib/moonrope/doc_context.rb +94 -0
- data/lib/moonrope/doc_server.rb +123 -0
- data/lib/moonrope/dsl/action_dsl.rb +159 -9
- data/lib/moonrope/dsl/authenticator_dsl.rb +31 -0
- data/lib/moonrope/dsl/base_dsl.rb +21 -18
- data/lib/moonrope/dsl/controller_dsl.rb +60 -9
- data/lib/moonrope/dsl/filterable_dsl.rb +27 -0
- data/lib/moonrope/dsl/structure_dsl.rb +27 -2
- data/lib/moonrope/errors.rb +3 -0
- data/lib/moonrope/eval_environment.rb +82 -3
- data/lib/moonrope/eval_helpers/filter_helper.rb +82 -0
- data/lib/moonrope/eval_helpers.rb +28 -5
- data/lib/moonrope/guard.rb +35 -0
- data/lib/moonrope/html_generator.rb +65 -0
- data/lib/moonrope/param_set.rb +11 -1
- data/lib/moonrope/rack_middleware.rb +1 -1
- data/lib/moonrope/railtie.rb +31 -14
- data/lib/moonrope/request.rb +25 -14
- data/lib/moonrope/structure.rb +74 -11
- data/lib/moonrope/structure_attribute.rb +15 -0
- data/lib/moonrope/version.rb +1 -1
- data/lib/moonrope.rb +5 -4
- data/moonrope.gemspec +21 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/specs/action_spec.rb +455 -0
- data/spec/specs/base_spec.rb +29 -0
- data/spec/specs/controller_spec.rb +31 -0
- data/spec/specs/param_set_spec.rb +31 -0
- data/templates/basic/_action_form.erb +77 -0
- data/templates/basic/_errors_table.erb +32 -0
- data/templates/basic/_structure_attributes_list.erb +55 -0
- data/templates/basic/action.erb +168 -0
- data/templates/basic/assets/lock.svg +3 -0
- data/templates/basic/assets/reset.css +101 -0
- data/templates/basic/assets/style.css +348 -0
- data/templates/basic/assets/tool.svg +4 -0
- data/templates/basic/assets/try.js +151 -0
- data/templates/basic/authenticator.erb +51 -0
- data/templates/basic/controller.erb +20 -0
- data/templates/basic/index.erb +114 -0
- data/templates/basic/layout.erb +46 -0
- data/templates/basic/structure.erb +23 -0
- data/test/test_helper.rb +81 -0
- data/test/tests/action_access_test.rb +63 -0
- data/test/tests/actions_test.rb +524 -0
- data/test/tests/authenticators_test.rb +87 -0
- data/test/tests/base_test.rb +35 -0
- data/test/tests/controllers_test.rb +49 -0
- data/test/tests/eval_environment_test.rb +136 -0
- data/test/tests/evel_helpers_test.rb +60 -0
- data/test/tests/examples_test.rb +11 -0
- data/test/tests/helpers_test.rb +97 -0
- data/test/tests/param_set_test.rb +44 -0
- data/test/tests/rack_middleware_test.rb +109 -0
- data/test/tests/request_test.rb +232 -0
- data/test/tests/structures_param_extensions_test.rb +159 -0
- data/test/tests/structures_test.rb +335 -0
- metadata +82 -48
@@ -0,0 +1,159 @@
|
|
1
|
+
class StructuresParamExtensionsTest < Test::Unit::TestCase
|
2
|
+
def setup
|
3
|
+
@base = Moonrope::Base.new do
|
4
|
+
structure :animal do
|
5
|
+
basic :id
|
6
|
+
full :color
|
7
|
+
expansion :user, :structure => :user
|
8
|
+
end
|
9
|
+
structure :user do
|
10
|
+
basic :id
|
11
|
+
end
|
12
|
+
controller :users do
|
13
|
+
action :info do
|
14
|
+
action do
|
15
|
+
structure @auth_user
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
@user = User.new(:id => 456)
|
21
|
+
@animal = Animal.new(:id => 123, :user => @user, :color => 'blue')
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_no_expansions_occur_by_default_with_array
|
25
|
+
request = FakeRequest.new(:params => {'_expansions' => ['user']})
|
26
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
27
|
+
structure = environment.structure(:animal, @animal)
|
28
|
+
assert_equal nil, structure[:user]
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_default_behaviour_when_paramable_is_only_option
|
32
|
+
request = FakeRequest.new(:params => {})
|
33
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
34
|
+
# From nil
|
35
|
+
structure = environment.structure(:animal, @animal, :paramable => true)
|
36
|
+
assert_equal nil, structure[:user]
|
37
|
+
assert_equal nil, structure[:color]
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_no_expansions_occur_by_default_with_true
|
41
|
+
request = FakeRequest.new(:params => {'_expansions' => true})
|
42
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
43
|
+
structure = environment.structure(:animal, @animal)
|
44
|
+
assert_equal nil, structure[:user]
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_expansions_use_paramable_value_as_default
|
48
|
+
request = FakeRequest.new(:params => {})
|
49
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
50
|
+
# From nil
|
51
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => nil})
|
52
|
+
assert_equal nil, structure[:user]
|
53
|
+
# From true
|
54
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => true})
|
55
|
+
assert_equal Hash, structure[:user].class
|
56
|
+
# From a list
|
57
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => [:user]})
|
58
|
+
assert_equal Hash, structure[:user].class
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_all_expansions_are_provided_when_paramable_is_true
|
62
|
+
request = FakeRequest.new(:params => {"_expansions" => true})
|
63
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
64
|
+
structure = environment.structure(:animal, @animal, :paramable => true)
|
65
|
+
assert_equal Hash, structure[:user].class
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_using_array_as_expansions_param
|
69
|
+
request = FakeRequest.new(:params => {'_expansions' => ['user']})
|
70
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
71
|
+
# Works
|
72
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => [:user]})
|
73
|
+
assert_equal Hash, structure[:user].class
|
74
|
+
# Works
|
75
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => true})
|
76
|
+
assert_equal Hash, structure[:user].class
|
77
|
+
# Shouldn't ret
|
78
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => [:other]})
|
79
|
+
assert_equal nil, structure[:user]
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_surpressing_default_expansions_with_empty_array
|
83
|
+
request = FakeRequest.new(:params => {'_expansions' => []})
|
84
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
85
|
+
# Shouldn't return the user structure because we've asked for none
|
86
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => [:user]})
|
87
|
+
assert_equal nil, structure[:user]
|
88
|
+
# Shouldn't return the user structure because we've asked for none
|
89
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => true})
|
90
|
+
assert_equal nil, structure[:user]
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_surpressing_default_expansions_with_false
|
94
|
+
request = FakeRequest.new(:params => {'_expansions' => false})
|
95
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
96
|
+
# Shouldn't return the user structure because we've asked for none
|
97
|
+
structure = environment.structure(:animal, @animal, :paramable => true)
|
98
|
+
assert_equal nil, structure[:user]
|
99
|
+
# Shouldn't return the user structure because we've asked for none
|
100
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => [:user]})
|
101
|
+
assert_equal nil, structure[:user]
|
102
|
+
# Shouldn't return the user structure because we've asked for none
|
103
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => true})
|
104
|
+
assert_equal nil, structure[:user]
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def test_using_true_as_expansions_param_to_return_all_suitable_expansions
|
109
|
+
request = FakeRequest.new(:params => {'_expansions' => true})
|
110
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
111
|
+
# Requesting all with no default
|
112
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => nil})
|
113
|
+
assert_equal Hash, structure[:user].class
|
114
|
+
# Requesting all with no array default
|
115
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => [:user]})
|
116
|
+
assert_equal Hash, structure[:user].class
|
117
|
+
# Requesting all with true default
|
118
|
+
structure = environment.structure(:animal, @animal, :paramable => {:expansions => true})
|
119
|
+
assert_equal Hash, structure[:user].class
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_empty_paramable_array
|
123
|
+
request = FakeRequest.new(:params => {'_expansions' => true})
|
124
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
125
|
+
# Should not return anything because paramable doesn't specify expansions
|
126
|
+
# as a suitable option
|
127
|
+
structure = environment.structure(:animal, @animal, :paramable => {})
|
128
|
+
assert_equal nil, structure[:user]
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_returning_full_data_by_default
|
132
|
+
request = FakeRequest.new()
|
133
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
134
|
+
structure = environment.structure(:animal, @animal, :paramable => {:full => true, :expansions => false})
|
135
|
+
assert_equal String, structure[:color].class
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_full_value_provides_full_access
|
139
|
+
request = FakeRequest.new(:params => {'_full' => true})
|
140
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
141
|
+
# No full value set
|
142
|
+
structure = environment.structure(:animal, @animal, :paramable => {})
|
143
|
+
assert_equal nil, structure[:color]
|
144
|
+
# With full set as default
|
145
|
+
structure = environment.structure(:animal, @animal, :paramable => {:full => true})
|
146
|
+
assert_equal String, structure[:color].class
|
147
|
+
# With full set as hidden by default
|
148
|
+
structure = environment.structure(:animal, @animal, :paramable => {:full => false})
|
149
|
+
assert_equal String, structure[:color].class
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_supressing_default_full_data
|
153
|
+
request = FakeRequest.new(:params => {'_full' => false})
|
154
|
+
environment = Moonrope::EvalEnvironment.new(@base, request)
|
155
|
+
structure = environment.structure(:animal, @animal, :paramable => {:full => true})
|
156
|
+
assert_equal nil, structure[:color]
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,335 @@
|
|
1
|
+
class StructuresTest < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def setup
|
4
|
+
@base = Moonrope::Base.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def test_structure_creation
|
8
|
+
structure = Moonrope::Structure.new(@base, :user) do
|
9
|
+
basic { {:id => o.id} }
|
10
|
+
full { {:username => o.username} }
|
11
|
+
end
|
12
|
+
assert_equal Moonrope::Structure, structure.class
|
13
|
+
assert structure.basic.is_a?(Proc)
|
14
|
+
assert structure.full.is_a?(Proc)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_structure_hash_with_basic_data
|
18
|
+
structure = Moonrope::Structure.new(@base, :user) do
|
19
|
+
basic { {:id => o.id} }
|
20
|
+
full { {:username => o.username} }
|
21
|
+
end
|
22
|
+
|
23
|
+
user = User.new(:id => 1, :username => 'adam')
|
24
|
+
|
25
|
+
hash = structure.hash(user)
|
26
|
+
assert_equal user.id, hash[:id]
|
27
|
+
assert_equal false, hash.keys.include?(:username)
|
28
|
+
|
29
|
+
hash = structure.hash(user, :full => true)
|
30
|
+
assert_equal user.id, hash[:id]
|
31
|
+
assert_equal user.username, hash[:username]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_passing_the_version
|
35
|
+
structure = Moonrope::Structure.new(@base, :user) do
|
36
|
+
basic do
|
37
|
+
{
|
38
|
+
:id => o.id,
|
39
|
+
:username => (version == 1 ? o.username : "@#{o.username}")
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
user = User.new(:id => 1, :username => 'adam')
|
44
|
+
# check version 2
|
45
|
+
request = FakeRequest.new(:version => 2)
|
46
|
+
hash = structure.hash(user, :request => request)
|
47
|
+
assert_equal "@#{user.username}", hash[:username]
|
48
|
+
# check version 1
|
49
|
+
request = FakeRequest.new(:version => 1)
|
50
|
+
hash = structure.hash(user, :request => request)
|
51
|
+
assert_equal user.username, hash[:username]
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_structure_hash_with_expansions
|
55
|
+
user = User.new(:id => 1, :username => 'dave')
|
56
|
+
animal1 = Animal.new(:id => 1, :name => 'Fido', :color => 'Ginder', :user => user)
|
57
|
+
animal2 = Animal.new(:id => 2, :name => 'Jess', :color => 'Black & White', :user => user)
|
58
|
+
user.animals << animal1
|
59
|
+
user.animals << animal2
|
60
|
+
|
61
|
+
base = Moonrope::Base.new do
|
62
|
+
structure :user do
|
63
|
+
basic { {:id => o.id, :username => o.username } }
|
64
|
+
expansion :animals do
|
65
|
+
o.animals.map { |a| structure(:animal, a) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
structure :animal do
|
70
|
+
basic { {:id => o.id, :name => o.name} }
|
71
|
+
full { {:color => o.color, :user => structure(:user, o.user)} }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
animal_structure = base.structure(:animal)
|
76
|
+
|
77
|
+
# Test the full animal structure includes the user
|
78
|
+
hash = animal_structure.hash(animal1, :full => true)
|
79
|
+
assert_equal animal1.name, hash[:name]
|
80
|
+
assert_equal user.username, hash[:user][:username]
|
81
|
+
|
82
|
+
# Test that a user structure with expansions includes the
|
83
|
+
# animals which are included
|
84
|
+
user_structure = base.structure(:user)
|
85
|
+
hash = user_structure.hash(user, :expansions => true)
|
86
|
+
assert hash[:animals].is_a?(Array), "hash[:animals] is not an array"
|
87
|
+
assert_equal hash[:animals][0][:name], 'Fido'
|
88
|
+
assert_equal hash[:animals][1][:name], 'Jess'
|
89
|
+
|
90
|
+
# Test that when expansions was false
|
91
|
+
hash = user_structure.hash(user, :expansions => false)
|
92
|
+
assert_equal nil, hash[:animals], "hash[:animals] is present"
|
93
|
+
|
94
|
+
# Test cases when expansions are provided as an array
|
95
|
+
hash = user_structure.hash(user, :expansions => [:something, :else])
|
96
|
+
assert_equal nil, hash[:animals], "hash[:animals] is present"
|
97
|
+
hash = user_structure.hash(user, :expansions => [:animals])
|
98
|
+
assert_equal Array, hash[:animals].class, "hash[:animals] is present"
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_structured_structures
|
102
|
+
base = Moonrope::Base.new do
|
103
|
+
structure :animal do
|
104
|
+
basic :id, :description => "The ID of the aniaml object", :example => 1, :type => Integer
|
105
|
+
basic :name, :description => "The name of the animal", :example => "Boris", :type => String
|
106
|
+
full :hair_color, :description => "The color of the animal's hair", :example => "Blue", :type => String, :source_attribute => :color
|
107
|
+
expansion :user, :type => Hash, :structure => :user
|
108
|
+
|
109
|
+
group :colors do
|
110
|
+
basic :eye, :example => "Green", :type => String, :source_attribute => :color
|
111
|
+
full :hair, :example => "Blue", :type => String, :source_attribute => :color
|
112
|
+
expansion :owner, :structure => :user, :type => Hash, :source_attribute => :user
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
structure :user do
|
117
|
+
basic :id, :example => 1, :type => Integer
|
118
|
+
basic :username, :example => "adam", :type => String
|
119
|
+
expansion :animals, :type => Array, :structure => :animal, :structure_opts => {:full => true}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
user = User.new(:id => 1, :username => 'adam', :private_code => 9876)
|
124
|
+
animal = Animal.new(:id => 1, :name => 'Fido', :color => 'Ginger', :user => user)
|
125
|
+
user.animals << animal
|
126
|
+
animal2 = Animal.new(:id => 2, :name => 'Boris', :color => 'Black', :user => user)
|
127
|
+
user.animals << animal2
|
128
|
+
|
129
|
+
# a full hash with all expansions
|
130
|
+
hash = base.structure(:animal).hash(animal, :full => true, :expansions => true)
|
131
|
+
# standard attributes
|
132
|
+
assert_equal 1, hash[:id]
|
133
|
+
assert_equal 'Fido', hash[:name]
|
134
|
+
assert_equal 'Ginger', hash[:hair_color]
|
135
|
+
# expansion in a group
|
136
|
+
assert_equal Hash, hash[:colors][:owner].class
|
137
|
+
# normal expansion
|
138
|
+
assert_equal Hash, hash[:user].class
|
139
|
+
assert_equal 'adam', hash[:user][:username]
|
140
|
+
assert_equal nil, hash[:user][:animals]
|
141
|
+
# group
|
142
|
+
assert_equal Hash, hash[:colors].class
|
143
|
+
assert_equal 'Ginger', hash[:colors][:eye]
|
144
|
+
assert_equal 'Ginger', hash[:colors][:hair]
|
145
|
+
|
146
|
+
# basic hash
|
147
|
+
hash = base.structure(:animal).hash(animal)
|
148
|
+
# normal attributes
|
149
|
+
assert_equal 1, hash[:id]
|
150
|
+
assert_equal 'Fido', hash[:name]
|
151
|
+
# groups
|
152
|
+
assert_equal Hash, hash[:colors].class
|
153
|
+
assert_equal 'Ginger', hash[:colors][:eye]
|
154
|
+
assert_equal nil, hash[:colors][:hair]
|
155
|
+
|
156
|
+
# a full user hash with all expansions
|
157
|
+
hash = base.structure(:user).hash(user, :full => true, :expansions => true)
|
158
|
+
# arrays
|
159
|
+
assert_equal Array, hash[:animals].class
|
160
|
+
assert_equal 'Fido', hash[:animals][0][:name]
|
161
|
+
assert_equal 'Boris', hash[:animals][1][:name]
|
162
|
+
assert_equal 'Black', hash[:animals][1][:hair_color]
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_ifs
|
166
|
+
base = Moonrope::Base.new do
|
167
|
+
structure :animal do
|
168
|
+
condition Proc.new { true } do
|
169
|
+
basic :id1, :example => 1, :type => Integer, :source_attribute => :id
|
170
|
+
end
|
171
|
+
|
172
|
+
condition Proc.new { false } do
|
173
|
+
basic :id2, :example => 2, :type => Integer, :source_attribute => :id
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
animal = Animal.new(:id => 1, :name => 'Fido', :color => 'Ginger')
|
179
|
+
hash = base.structure(:animal).hash(animal)
|
180
|
+
assert_equal 1, hash[:id1]
|
181
|
+
assert_equal nil, hash[:id2]
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_ifs_with_expansion
|
185
|
+
base = Moonrope::Base.new do
|
186
|
+
structure :animal do
|
187
|
+
condition Proc.new { true } do
|
188
|
+
expansion :example do
|
189
|
+
{:hello => 'world'}
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
condition Proc.new { false } do
|
194
|
+
expansion :example2 do
|
195
|
+
{:hello => 'land'}
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
animal = Animal.new(:id => 1, :name => 'Fido', :color => 'Ginger')
|
202
|
+
hash = base.structure(:animal).hash(animal, :expansions => true)
|
203
|
+
assert_equal true, hash.keys.include?(:example)
|
204
|
+
assert_equal false, hash.keys.include?(:example2)
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_condition_with_description
|
208
|
+
base = Moonrope::Base.new do
|
209
|
+
structure :animal do
|
210
|
+
condition Proc.new { false }, "An example description" do
|
211
|
+
basic :id
|
212
|
+
expansion :example do
|
213
|
+
{:hello => 'land'}
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
animal = Animal.new(:id => 1, :name => 'Fido', :color => 'Ginger')
|
220
|
+
hash = base.structure(:animal).hash(animal, :expansions => true)
|
221
|
+
assert_equal false, hash.keys.include?(:example)
|
222
|
+
assert_equal false, hash.keys.include?(:id)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_condition_with_access_rule
|
226
|
+
base = Moonrope::Base.new do
|
227
|
+
authenticator :default do
|
228
|
+
lookup { true }
|
229
|
+
rule(:default, "NotPermitted") { true }
|
230
|
+
rule(:false_rule, "MustNotBeFalse") { false }
|
231
|
+
end
|
232
|
+
structure :animal do
|
233
|
+
condition :default => :false_rule do
|
234
|
+
basic :id
|
235
|
+
end
|
236
|
+
|
237
|
+
condition :default => :default do
|
238
|
+
basic :name
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
animal = Animal.new(:id => 1, :name => 'Fido', :color => 'Ginger')
|
244
|
+
hash = base.structure(:animal).hash(animal, :expansions => true)
|
245
|
+
assert_equal false, hash.keys.include?(:id)
|
246
|
+
assert_equal true, hash.keys.include?(:name)
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_condition_with_access_rule_and_default_authenticator
|
250
|
+
base = Moonrope::Base.new do
|
251
|
+
authenticator :default do
|
252
|
+
lookup { true }
|
253
|
+
rule(:default, "NotPermitted") { true }
|
254
|
+
rule(:false_rule, "MustNotBeFalse") { false }
|
255
|
+
end
|
256
|
+
structure :animal do
|
257
|
+
condition :false_rule do
|
258
|
+
basic :id
|
259
|
+
end
|
260
|
+
|
261
|
+
condition :default do
|
262
|
+
basic :name
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
animal = Animal.new(:id => 1, :name => 'Fido', :color => 'Ginger')
|
268
|
+
hash = base.structure(:animal).hash(animal, :expansions => true)
|
269
|
+
assert_equal false, hash.keys.include?(:id)
|
270
|
+
assert_equal true, hash.keys.include?(:name)
|
271
|
+
end
|
272
|
+
|
273
|
+
|
274
|
+
def test_scopes
|
275
|
+
base = Moonrope::Base.new do
|
276
|
+
structure :animal do
|
277
|
+
group :group1 do
|
278
|
+
basic :id
|
279
|
+
basic :name
|
280
|
+
group :group2 do
|
281
|
+
basic :id_g2, :source_attribute => :id
|
282
|
+
basic :name2, :source_attribute => :name
|
283
|
+
group :group3 do
|
284
|
+
basic :id_g3, :source_attribute => :id
|
285
|
+
basic :name3, :source_attribute => :name
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
condition Proc.new { false } do
|
291
|
+
basic :id2, :name => :id
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
animal = Animal.new(:id => 1, :name => 'Fido', :color => 'Ginger')
|
296
|
+
hash = base.structure(:animal).hash(animal, :full => true)
|
297
|
+
|
298
|
+
assert_equal 1, hash[:group1][:id]
|
299
|
+
assert_equal 1, hash[:group1][:group2][:id_g2]
|
300
|
+
assert_equal 1, hash[:group1][:group2][:group3][:id_g3]
|
301
|
+
|
302
|
+
assert_equal 'Fido', hash[:group1][:name]
|
303
|
+
assert_equal 'Fido', hash[:group1][:group2][:name2]
|
304
|
+
assert_equal 'Fido', hash[:group1][:group2][:group3][:name3]
|
305
|
+
|
306
|
+
# id2 shouldn't exist because it's if block returns false
|
307
|
+
assert_equal false, hash.keys.include?(:id2)
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_passing_values_from_the_definition
|
311
|
+
base = Moonrope::Base.new do
|
312
|
+
structure :animal do
|
313
|
+
basic :example, :value => 1234
|
314
|
+
basic :example_with_block, :value => Proc.new { "#{o.name}!!!" }
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
animal = Animal.new(:id => 1, :name => 'Fido', :color => 'Ginger')
|
319
|
+
hash = base.structure(:animal).hash(animal)
|
320
|
+
assert_equal 1234, hash[:example]
|
321
|
+
assert_equal "Fido!!!", hash[:example_with_block]
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_creating_a_structure_with_description
|
325
|
+
base = Moonrope::Base.new do
|
326
|
+
structure :animal do
|
327
|
+
basic :example, "Hello there!", :value => 1234
|
328
|
+
basic :example2, :description => "Bananas!"
|
329
|
+
end
|
330
|
+
end
|
331
|
+
assert_equal "Hello there!", base.structure(:animal).attributes[:basic].select { |a| a.name == :example }.first.description
|
332
|
+
assert_equal "Bananas!", base.structure(:animal).attributes[:basic].select { |a| a.name == :example2 }.first.description
|
333
|
+
end
|
334
|
+
|
335
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moonrope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -66,71 +66,70 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.3'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: test-unit
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '2.5'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '2.5'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: yard
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.8'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.8'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: rack-test
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
69
|
description: A full library allowing you to create sexy DSLs to define your RPC-like
|
112
70
|
APIs.
|
113
71
|
email:
|
114
72
|
- adam@atechmedia.com
|
115
|
-
executables:
|
73
|
+
executables:
|
74
|
+
- moonrope
|
116
75
|
extensions: []
|
117
76
|
extra_rdoc_files: []
|
118
77
|
files:
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- MIT-LICENCE
|
81
|
+
- README.md
|
119
82
|
- Rakefile
|
83
|
+
- bin/moonrope
|
84
|
+
- docs/authentication.md
|
85
|
+
- docs/controllers.md
|
86
|
+
- docs/exceptions.md
|
87
|
+
- docs/introduction.md
|
88
|
+
- docs/structures.md
|
89
|
+
- example/authentication.rb
|
90
|
+
- example/controllers/meta_controller.rb
|
91
|
+
- example/controllers/users_controller.rb
|
92
|
+
- example/structures/pet_structure.rb
|
93
|
+
- example/structures/user_structure.rb
|
94
|
+
- html/assets/lock.svg
|
95
|
+
- html/assets/reset.css
|
96
|
+
- html/assets/style.css
|
97
|
+
- html/assets/tool.svg
|
98
|
+
- html/assets/try.js
|
99
|
+
- html/authenticators/default.html
|
100
|
+
- html/controllers/meta.html
|
101
|
+
- html/controllers/meta/version.html
|
102
|
+
- html/controllers/users.html
|
103
|
+
- html/controllers/users/create.html
|
104
|
+
- html/controllers/users/list.html
|
105
|
+
- html/controllers/users/show.html
|
106
|
+
- html/controllers/users/update.html
|
107
|
+
- html/index.html
|
108
|
+
- html/moonrope.txt
|
109
|
+
- html/structures/pet.html
|
110
|
+
- html/structures/user.html
|
120
111
|
- lib/moonrope.rb
|
121
112
|
- lib/moonrope/action.rb
|
122
113
|
- lib/moonrope/action_result.rb
|
114
|
+
- lib/moonrope/authenticator.rb
|
123
115
|
- lib/moonrope/base.rb
|
124
116
|
- lib/moonrope/before_action.rb
|
125
117
|
- lib/moonrope/controller.rb
|
118
|
+
- lib/moonrope/doc_context.rb
|
119
|
+
- lib/moonrope/doc_server.rb
|
126
120
|
- lib/moonrope/dsl/action_dsl.rb
|
121
|
+
- lib/moonrope/dsl/authenticator_dsl.rb
|
127
122
|
- lib/moonrope/dsl/base_dsl.rb
|
128
123
|
- lib/moonrope/dsl/controller_dsl.rb
|
124
|
+
- lib/moonrope/dsl/filterable_dsl.rb
|
129
125
|
- lib/moonrope/dsl/structure_dsl.rb
|
130
126
|
- lib/moonrope/errors.rb
|
131
127
|
- lib/moonrope/eval_environment.rb
|
132
128
|
- lib/moonrope/eval_helpers.rb
|
129
|
+
- lib/moonrope/eval_helpers/filter_helper.rb
|
130
|
+
- lib/moonrope/guard.rb
|
133
131
|
- lib/moonrope/helper.rb
|
132
|
+
- lib/moonrope/html_generator.rb
|
134
133
|
- lib/moonrope/param_set.rb
|
135
134
|
- lib/moonrope/rack_middleware.rb
|
136
135
|
- lib/moonrope/railtie.rb
|
@@ -138,6 +137,41 @@ files:
|
|
138
137
|
- lib/moonrope/structure.rb
|
139
138
|
- lib/moonrope/structure_attribute.rb
|
140
139
|
- lib/moonrope/version.rb
|
140
|
+
- moonrope.gemspec
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
- spec/specs/action_spec.rb
|
143
|
+
- spec/specs/base_spec.rb
|
144
|
+
- spec/specs/controller_spec.rb
|
145
|
+
- spec/specs/param_set_spec.rb
|
146
|
+
- templates/basic/_action_form.erb
|
147
|
+
- templates/basic/_errors_table.erb
|
148
|
+
- templates/basic/_structure_attributes_list.erb
|
149
|
+
- templates/basic/action.erb
|
150
|
+
- templates/basic/assets/lock.svg
|
151
|
+
- templates/basic/assets/reset.css
|
152
|
+
- templates/basic/assets/style.css
|
153
|
+
- templates/basic/assets/tool.svg
|
154
|
+
- templates/basic/assets/try.js
|
155
|
+
- templates/basic/authenticator.erb
|
156
|
+
- templates/basic/controller.erb
|
157
|
+
- templates/basic/index.erb
|
158
|
+
- templates/basic/layout.erb
|
159
|
+
- templates/basic/structure.erb
|
160
|
+
- test/test_helper.rb
|
161
|
+
- test/tests/action_access_test.rb
|
162
|
+
- test/tests/actions_test.rb
|
163
|
+
- test/tests/authenticators_test.rb
|
164
|
+
- test/tests/base_test.rb
|
165
|
+
- test/tests/controllers_test.rb
|
166
|
+
- test/tests/eval_environment_test.rb
|
167
|
+
- test/tests/evel_helpers_test.rb
|
168
|
+
- test/tests/examples_test.rb
|
169
|
+
- test/tests/helpers_test.rb
|
170
|
+
- test/tests/param_set_test.rb
|
171
|
+
- test/tests/rack_middleware_test.rb
|
172
|
+
- test/tests/request_test.rb
|
173
|
+
- test/tests/structures_param_extensions_test.rb
|
174
|
+
- test/tests/structures_test.rb
|
141
175
|
homepage: http://adamcooke.io
|
142
176
|
licenses:
|
143
177
|
- MIT
|
@@ -158,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
192
|
version: '0'
|
159
193
|
requirements: []
|
160
194
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
195
|
+
rubygems_version: 2.4.5
|
162
196
|
signing_key:
|
163
197
|
specification_version: 4
|
164
198
|
summary: An API server DSL.
|