rid 0.5.2 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/LICENSE +1 -1
  2. data/README +14 -0
  3. data/Rakefile +18 -33
  4. data/VERSION +1 -0
  5. data/bin/rid +3 -6
  6. data/lib/rid/app.rb +49 -0
  7. data/lib/rid/attachments.rb +6 -2
  8. data/lib/rid/commands.rb +61 -39
  9. data/lib/rid/core_ext/hash.rb +1 -1
  10. data/lib/rid/database.rb +69 -0
  11. data/lib/rid/document.rb +99 -0
  12. data/lib/rid.rb +14 -41
  13. data/rid.gemspec +49 -78
  14. data/spec/mock_app/_database +1 -0
  15. data/spec/rid/app_spec.rb +59 -0
  16. data/spec/rid/attachments_spec.rb +2 -2
  17. data/spec/rid/commands_spec.rb +14 -0
  18. data/spec/rid/database_spec.rb +25 -0
  19. data/spec/rid/document_spec.rb +36 -0
  20. data/spec/spec_helper.rb +6 -0
  21. metadata +127 -86
  22. data/.gitmodules +0 -3
  23. data/README.rdoc +0 -92
  24. data/lib/rid/actions/base.rb +0 -15
  25. data/lib/rid/actions/pull.rb +0 -28
  26. data/lib/rid/actions/push.rb +0 -53
  27. data/lib/rid/actions/routes.rb +0 -44
  28. data/lib/rid/commands/destroy.rb +0 -9
  29. data/lib/rid/commands/generate.rb +0 -9
  30. data/lib/rid/commands/pull.rb +0 -4
  31. data/lib/rid/commands/push.rb +0 -4
  32. data/lib/rid/commands/routes.rb +0 -4
  33. data/lib/rid/design_document.rb +0 -149
  34. data/lib/rid/generators/application/USAGE +0 -10
  35. data/lib/rid/generators/application/application_generator.rb +0 -56
  36. data/lib/rid/generators/application/templates/README +0 -1
  37. data/lib/rid/generators/application/templates/_attachments/index.html +0 -11
  38. data/lib/rid/generators/application/templates/_attachments/stylesheets/application.css +0 -25
  39. data/lib/rid/generators/application/templates/_id +0 -1
  40. data/lib/rid/generators/application/templates/gitignore +0 -0
  41. data/lib/rid/generators/application/templates/lib/mustache.js +0 -305
  42. data/lib/rid/generators/application/templates/lib/path.js +0 -5
  43. data/lib/rid/generators/application/templates/lib/templates/layout.mustache +0 -14
  44. data/lib/rid/generators/application/templates/ridrc +0 -1
  45. data/lib/rid/generators/application/templates/validate_doc_update.js +0 -3
  46. data/lib/rid/generators/base.rb +0 -66
  47. data/lib/rid/generators/list/USAGE +0 -8
  48. data/lib/rid/generators/list/list_generator.rb +0 -10
  49. data/lib/rid/generators/list/templates/index.mustache +0 -23
  50. data/lib/rid/generators/list/templates/list.js +0 -34
  51. data/lib/rid/generators/named_base.rb +0 -22
  52. data/lib/rid/generators/scaffold/USAGE +0 -10
  53. data/lib/rid/generators/scaffold/scaffold_generator.rb +0 -32
  54. data/lib/rid/generators/show/USAGE +0 -8
  55. data/lib/rid/generators/show/show_generator.rb +0 -13
  56. data/lib/rid/generators/show/templates/delete.mustache +0 -20
  57. data/lib/rid/generators/show/templates/deleted.mustache +0 -3
  58. data/lib/rid/generators/show/templates/form.mustache +0 -22
  59. data/lib/rid/generators/show/templates/show.js +0 -48
  60. data/lib/rid/generators/show/templates/show.mustache +0 -13
  61. data/lib/rid/generators/update/USAGE +0 -8
  62. data/lib/rid/generators/update/templates/update.js +0 -48
  63. data/lib/rid/generators/update/update_generator.rb +0 -9
  64. data/lib/rid/generators/validation/USAGE +0 -9
  65. data/lib/rid/generators/validation/templates/validate_doc_update.js +0 -3
  66. data/lib/rid/generators/validation/validation_generator.rb +0 -34
  67. data/lib/rid/generators/view/USAGE +0 -8
  68. data/lib/rid/generators/view/templates/map.js +0 -5
  69. data/lib/rid/generators/view/view_generator.rb +0 -17
  70. data/lib/rid/generators.rb +0 -63
  71. data/lib/rid/makros.rb +0 -114
  72. data/lib/rid/version.rb +0 -3
  73. data/spec/rid/design_document_spec.rb +0 -220
  74. data/spec/rid/makros_spec.rb +0 -94
  75. data/spec/rid_spec.rb +0 -7
@@ -1,13 +0,0 @@
1
- <p>
2
- <a href="{{path}}/_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a> |
3
- <a href="{{path}}/_show/<%= model_name %>/{{id}}?edit">Edit <%= model_name.humanize %></a> |
4
- <a href="{{path}}/_show/<%= model_name %>/{{id}}?delete">Delete <%= model_name.humanize %></a>
5
- </p>
6
- <dl>
7
- <dt>ID</dt>
8
- <dd>{{id}}</dd>
9
- <% attributes.each do |attribute| -%>
10
- <dt><%= attribute.humanize %></dt>
11
- <dd>{{<%= attribute %>}}</dd>
12
- <% end -%>
13
- </dl>
@@ -1,8 +0,0 @@
1
- Description:
2
- The 'update' generator creates a scaffold update function
3
- for the name and attributes you specify
4
-
5
- Example:
6
- rid generate update post title body
7
-
8
- This generates a skeletal post update function
@@ -1,48 +0,0 @@
1
- function(doc, req) {
2
- // !code path.js
3
- // !code mustache.js
4
- // !json templates/layout.mustache
5
- // !json templates/<%= pluralized_model_name %>/show.mustache
6
- // !json templates/<%= pluralized_model_name %>/deleted.mustache
7
-
8
- var doc = {
9
- type: '<%= model_name %>',
10
- <% attributes.each do |attribute| -%>
11
- '<%= attribute %>': req.form['<%= attribute %>'],
12
- <% end -%>
13
- _id: req.form.id,
14
- _rev: req.form.rev
15
- };
16
-
17
- if (req.form['delete'] == 'true') {
18
- doc._deleted = true;
19
- };
20
-
21
- var view = {
22
- path: path(),
23
- body: {
24
- path: path(),
25
- <% attributes.each do |attribute| -%>
26
- '<%= attribute %>': doc['<%= attribute %>'],
27
- <% end -%>
28
- id: doc._id
29
- }
30
- };
31
- var partial;
32
-
33
- if (doc._deleted) {
34
- view.title = "Deleted <%= model_name.humanize %>";
35
- view.notice = "<%= model_name.humanize %> has been deleted.";
36
- partial = 'deleted';
37
- } else {
38
- view.title = "Showing <%= model_name.humanize %>";
39
- if (doc._rev) {
40
- view.notice = "<%= model_name.humanize %> has been updated.";
41
- } else {
42
- view.notice = "<%= model_name.humanize %> has been created.";
43
- };
44
- partial = 'show';
45
- }
46
-
47
- return [doc, Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>[partial] })];
48
- }
@@ -1,9 +0,0 @@
1
- require 'rid/generators/named_base'
2
-
3
- module Rid::Generators
4
- class UpdateGenerator < NamedBase
5
- def create_update_function
6
- template "update.js", "updates/#{pluralized_model_name}.js"
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- Description:
2
- The 'validation' generator creates a validation function
3
- for the model name and attributes you specify
4
-
5
- Example:
6
- rid generate validation post title body
7
-
8
- This generates a skeletal model validation for post
9
- with validations of presence for title and body
@@ -1,3 +0,0 @@
1
- function (newDoc, oldDoc, userCtx) {
2
- // your validation code goes here
3
- }
@@ -1,34 +0,0 @@
1
- require 'rid/generators/named_base'
2
-
3
- module Rid::Generators
4
- class ValidationGenerator < NamedBase
5
- def create_validate_doc_update
6
- return if File.exists?(File.join(destination_root, "validate_doc_update.js"))
7
- template "validate_doc_update.js"
8
- end
9
-
10
- def inject_validations
11
- inject_into_file "validate_doc_update.js", model_validations, :after => "function (newDoc, oldDoc, userCtx) {\n"
12
- end
13
-
14
- protected
15
-
16
- def model_validations
17
- str = <<-STR
18
- if(newDoc.type == '#{model_name}') {
19
- // validations for #{model_name}
20
- STR
21
-
22
- attributes.each do |attribute|
23
- str << <<-STR
24
- if (typeof(newDoc['#{attribute}']) === 'undefined') {
25
- throw({ forbidden: '#{attribute} is required' });
26
- }
27
- STR
28
- end
29
-
30
- str << " }\n"
31
- str
32
- end
33
- end
34
- end
@@ -1,8 +0,0 @@
1
- Description:
2
- The 'view' generator creates a scaffold view function
3
- for the name you specify
4
-
5
- Example:
6
- rid generate view post
7
-
8
- This generates a skeletal posts list function
@@ -1,5 +0,0 @@
1
- function(doc) {
2
- if(doc.type && doc.type == '<%= model_name %>') {
3
- emit(doc._id, <%= mydoc %>);
4
- }
5
- }
@@ -1,17 +0,0 @@
1
- require 'rid/generators/named_base'
2
-
3
- module Rid::Generators
4
- class ViewGenerator < NamedBase
5
- def create_view_function
6
- path = "views/#{pluralized_model_name}"
7
- empty_directory path
8
- template "map.js", "#{path}/map.js"
9
- end
10
-
11
- protected
12
-
13
- def mydoc
14
- "{ %s }" % attributes.map { |a| '"%s": doc["%s"]' % [a,a] }.join(", ")
15
- end
16
- end
17
- end
@@ -1,63 +0,0 @@
1
- require 'rid'
2
- require 'rid/generators/base'
3
-
4
- module Rid
5
- module Generators
6
- # Receives a name, arguments and the behavior to invoke the generator.
7
- # It's used as the default entry point for generate and destroy commands.
8
- def self.invoke(name, args = ARGV, config = {})
9
- if klass = lookup(name.to_s)
10
- args << "--help" if args.empty? && klass.arguments.any? { |a| a.required? }
11
- klass.start(args, config)
12
- else
13
- puts "Could not find generator #{name}."
14
- end
15
- end
16
-
17
- # Show help message with available generators.
18
- def self.help(command = 'generate')
19
- path = File.expand_path("../generators/*/*_generator.rb", __FILE__)
20
- generators = Dir.glob(path)
21
- generators.sort!
22
- generators.map! { |f| File.basename(f) }
23
- generators.map! { |n| n.sub!(/_generator\.rb$/, '') }
24
- longest_name_size = generators.map { |g| g.size }.sort.last
25
- generators.map! { |g| "%s # %s" % [g.ljust(longest_name_size), lookup(g).info] }
26
-
27
- puts "Usage: rid #{command} GENERATOR [args] [options]"
28
- puts
29
- puts "General options:"
30
- puts " -h, [--help] # Print generators options and usage"
31
- puts " -p, [--pretend] # Run but do not make any changes"
32
- puts " -f, [--force] # Overwrite files that already exist"
33
- puts " -s, [--skip] # Skip files that already exist"
34
- puts " -q, [--quiet] # Supress status output"
35
- puts
36
- puts "Please choose a generator below:"
37
- puts
38
- puts generators
39
- end
40
-
41
- protected
42
-
43
- def self.lookup(name)
44
- # real path
45
- path = File.expand_path("../generators/#{name}/#{name}_generator.rb", __FILE__)
46
- # no matches?
47
- unless File.exists?(path)
48
- # try to find by prefix
49
- found = Dir.glob(File.expand_path("../generators/#{name}*/#{name}*_generator.rb", __FILE__))
50
- if found.size == 1
51
- path = found.first
52
- name = File.basename(path).sub(/_generator\.rb$/, '')
53
- end
54
- end
55
- require path
56
- const_get "#{name.classify}Generator"
57
- rescue LoadError => e
58
- raise unless e.message =~ /#{Regexp.escape(path)}$/
59
- rescue Exception => e
60
- warn "[WARNING] Could not load generator #{path.inspect}. Error: #{e.message}.\n#{e.backtrace.join("\n")}"
61
- end
62
- end
63
- end
data/lib/rid/makros.rb DELETED
@@ -1,114 +0,0 @@
1
- module Rid
2
- module Makros
3
- # inject makros, that is:
4
- # replace makro with content from libs
5
- #
6
- def inject_makros!
7
- inject_makro! "code" do |filename|
8
- value = libs.at(filename)
9
- raise "code makro injection failed!\nNo lib available for %s" % filename unless value
10
-
11
- value
12
- end
13
-
14
- inject_makro! "json" do |filename|
15
- value = libs.at(filename)
16
- raise "json makro injection failed!\nNo lib available for %s" % filename unless value
17
-
18
- expand_json_makro filename, value
19
- end
20
- end
21
-
22
- # reject makros, that is:
23
- # replace makro generated content with makro
24
- #
25
- def reject_makros!
26
- return if injections.empty?
27
-
28
- injections.reverse.each do |inj|
29
- makro, target, lib, start, size = inj["makro"], inj["target"], inj["lib"], inj["start"], inj["size"]
30
-
31
- value = hash.at(target)
32
- value[start, size] = "// !#{makro} #{lib}"
33
- end
34
- end
35
-
36
-
37
- private
38
-
39
- # provide access to lib hash
40
- #
41
- def libs
42
- hash["lib"] || {}
43
- end
44
-
45
- # provide access to injections array
46
- #
47
- def injections
48
- hash["injections"] || []
49
- end
50
-
51
-
52
- # builds a javascript variable assignment line for filename with value
53
- # 'var %s = %s;' % [filename.split(/[\.\/]/).join('_'), value.to_json]
54
- def expand_json_makro(filename, value)
55
- name = filename.sub(/\..*$/, '')
56
- parts = name.split('/')
57
-
58
- if parts.size > 1
59
- var = "var #{parts.first};"
60
- 0.upto(parts.size - 2) do |i|
61
- v = parts[0..i].join('.')
62
- var << " if (!#{v}) #{v} = {};"
63
- end
64
- var << "\n"
65
- var << "#{parts.join('.')} = %s;"
66
- else
67
- var = "var #{name} = %s;"
68
- end
69
-
70
- var % value.to_json
71
- end
72
-
73
- # injects a makro and yields block with the filenames for found makros
74
- #
75
- def inject_makro!(makro, &block)
76
- matcher = /\/\/\s*!#{makro}\s+[\S]+$/
77
-
78
- hash.flatten.each do |key, value|
79
- next unless value.is_a?(String)
80
-
81
- # do not try to inject makros in attachments, libs and injections array
82
- next if key =~ /^_attachments|libs|injections/
83
-
84
- while value =~ matcher do
85
- value = value.sub(matcher) do |match|
86
- start = Regexp.last_match.begin(0)
87
- filename = match.sub(/^.*!#{makro}\s*(\S+).*$/, '\1')
88
-
89
- value = block.call(filename)
90
-
91
- store_injection makro, key, filename, start, value.size
92
-
93
- value
94
- end
95
- end
96
-
97
- self.hash.update_at key, value
98
- end
99
- end
100
-
101
- # Store injection values in injections array
102
- #
103
- def store_injection(makro, target, lib, start, size)
104
- hash["injections"] ||= []
105
- hash["injections"] << {
106
- "makro" => makro,
107
- "target" => target,
108
- "lib" => lib,
109
- "start" => start,
110
- "size" => size
111
- }
112
- end
113
- end
114
- end
data/lib/rid/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Rid
2
- VERSION = "0.5.2"
3
- end
@@ -1,220 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'rid/design_document'
3
-
4
- describe "DesignDocument" do
5
- before do
6
- @doc = Rid::DesignDocument.new
7
- end
8
-
9
-
10
- describe "read" do
11
- it "should assign key-value pair" do
12
- @doc.read("key") do |filename|
13
- "value"
14
- end
15
- @doc.hash.should == { "key" => "value" }
16
- end
17
-
18
- it "should assign two key-value pairs" do
19
- @doc.read("key1", "key2") do |filename|
20
- "value"
21
- end
22
- @doc.hash.should == { "key1" => "value", "key2" => "value" }
23
- end
24
-
25
- it "should assign an array of two key-value pairs" do
26
- @doc.read(["key1", "key2"]) do |filename|
27
- "value"
28
- end
29
- @doc.hash.should == { "key1" => "value", "key2" => "value" }
30
- end
31
-
32
- it "should assign nested hash" do
33
- @doc.read("hash/key") do |filename|
34
- "value"
35
- end
36
- @doc.hash.should == { "hash" => { "key" => "value" } }
37
- end
38
-
39
- it "should assign deep nested hash" do
40
- @doc.read("hash/hash/key") do |filename|
41
- "value"
42
- end
43
- @doc.hash.should == { "hash" => { "hash" => { "key" => "value" } } }
44
- end
45
-
46
-
47
- describe "exclude files should not be mapped" do
48
- it "should not map README" do
49
- @doc.read("README") do |filename|
50
- "value"
51
- end
52
- @doc.hash.should == {}
53
- end
54
- end
55
-
56
- describe "javascript files should be stripped off extension" do
57
- it "should strip validate_doc_update extension" do
58
- @doc.read("validate_doc_update.js") do |filename|
59
- "value"
60
- end
61
- @doc.hash.should == { "validate_doc_update" => "value" }
62
- end
63
-
64
- it "should strip lists/my_list.js" do
65
- @doc.read("lists/my_list.js") do |filename|
66
- "value"
67
- end
68
- @doc.hash.should == { "lists" => { "my_list" => "value" } }
69
- end
70
-
71
- it "should strip views/my_view/map.js" do
72
- @doc.read("views/my_view/map.js") do |filename|
73
- "value"
74
- end
75
- @doc.hash.should == { "views" => { "my_view" => { "map" => "value" } } }
76
- end
77
- end
78
- end
79
-
80
-
81
- describe "write" do
82
- it "should return key-value pair" do
83
- @doc.hash = { "key" => "value" }
84
- @doc.write do |key, value|
85
- key.should == "key"
86
- value.should == "value"
87
- end
88
- end
89
-
90
- it "should return subdirectory for nested hash" do
91
- @doc.hash = { "hash" => { "key" => "value" } }
92
- @doc.write do |key, value|
93
- key.should == "hash/key"
94
- value.should == "value"
95
- end
96
- end
97
-
98
- it "should return subdirectory for nested hash" do
99
- @doc.hash = { "hash" => { "hash" => { "key" => "value" } } }
100
- @doc.write do |key, value|
101
- key.should == "hash/hash/key"
102
- value.should == "value"
103
- end
104
- end
105
-
106
- describe "javascript extensions" do
107
- it "should append validate_doc_update" do
108
- @doc.hash = { "validate_doc_update" => "value" }
109
- @doc.write do |key, value|
110
- key.should == "validate_doc_update.js"
111
- end
112
- end
113
-
114
- it "should append lists/my_list" do
115
- @doc.hash = { "lists" => { "my_list" => "value" } }
116
- @doc.write do |key, value|
117
- key.should == "lists/my_list.js"
118
- end
119
- end
120
-
121
- it "should append views/my_view/map" do
122
- @doc.hash = { "views" => { "my_view" => { "map" => "value" } } }
123
- @doc.write do |key, value|
124
- key.should == "views/my_view/map.js"
125
- end
126
- end
127
- end
128
- end
129
-
130
-
131
- describe "json" do
132
- it "should convert key-value pair" do
133
- @doc.hash = { "key" => "value" }
134
- @doc.json.should == '{"key":"value"}'
135
- end
136
-
137
- it "should convert nested hash" do
138
- @doc.hash = { "hash" => { "key" => "value" } }
139
- @doc.json.should == '{"hash":{"key":"value"}}'
140
- end
141
- end
142
-
143
- describe "json=" do
144
- it "should read key-value pair" do
145
- @doc.json = '{"key":"value"}'
146
- @doc.hash.should == { "key" => "value" }
147
- end
148
-
149
- it "should read nested hash" do
150
- @doc.json = '{"hash":{"key":"value"}}'
151
- @doc.hash.should == { "hash" => { "key" => "value" } }
152
- end
153
- end
154
-
155
-
156
- describe "id accessor" do
157
- it "should return id from hash" do
158
- @doc.hash = { "_id" => "my_id" }
159
- @doc.id.should == "my_id"
160
- end
161
-
162
- it "should return id from rid" do
163
- Rid.stub!(:id).and_return("my_id")
164
- @doc.hash = {}
165
- @doc.id.should == "my_id"
166
- end
167
- end
168
-
169
- describe "rev accessor" do
170
- it "should return rev from hash" do
171
- @doc.hash = { "_rev" => "my_rev" }
172
- @doc.rev.should == "my_rev"
173
- end
174
-
175
- it "should return rev from rid" do
176
- Rid.stub!(:rev).and_return("my_rev")
177
- @doc.hash = {}
178
- @doc.rev.should == "my_rev"
179
- end
180
-
181
- it "should update rev in hash" do
182
- @doc.hash = {}
183
- @doc.rev = "my_rev"
184
- @doc.hash.should == { "_rev" => "my_rev" }
185
- end
186
- end
187
-
188
- describe "database accessor" do
189
- it "should return database rid" do
190
- Rid.stub!(:database).and_return("my_db")
191
- @doc.database.should == "my_db"
192
- end
193
- end
194
-
195
-
196
- describe "base url" do
197
- it "should combine database and id" do
198
- @doc.should_receive(:id).and_return("my_id")
199
- @doc.should_receive(:database).and_return("my_db")
200
- @doc.base_url.should == "my_db/my_id"
201
- end
202
- end
203
-
204
- describe "url" do
205
- it "should return base_url without options" do
206
- @doc.should_receive(:base_url).and_return("my_base_url")
207
- @doc.url.should == "my_base_url"
208
- end
209
-
210
- it "should return base_url with options string" do
211
- @doc.should_receive(:base_url).and_return("my_base_url")
212
- @doc.url(:key => :value).should == "my_base_url?key=value"
213
- end
214
-
215
- it "should return base_url with properly escaped options string" do
216
- @doc.should_receive(:base_url).and_return("my_base_url")
217
- @doc.url(:key => "value value").should == "my_base_url?key=value%20value"
218
- end
219
- end
220
- end
@@ -1,94 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
- require 'rid/design_document'
3
-
4
- describe "Makros" do
5
- before do
6
- @doc = Rid::DesignDocument.new
7
- end
8
-
9
- describe "inject" do
10
- describe "code makro" do
11
- it "should expand code" do
12
- @doc.hash = { "hash" => { "key" => "// !code code.js" }, "lib" => { "code.js" => "value" } }
13
- @doc.inject_makros!
14
- @doc.hash["hash"]["key"].should == "value"
15
- end
16
-
17
- it "should not remove code that follows" do
18
- @doc.hash = { "hash" => { "key" => "// !code code.js\nvalue" }, "lib" => { "code.js" => "value" } }
19
- @doc.inject_makros!
20
- @doc.hash["hash"]["key"].should == "value\nvalue"
21
- end
22
-
23
- it "should store injection" do
24
- @doc.hash = { "hash" => { "key" => "// !code code.js" }, "lib" => { "code.js" => "value" } }
25
- @doc.inject_makros!
26
- @doc.hash["injections"].should == [{ "makro" => "code", "target" => "hash/key", "lib" => "code.js", "start" => 0, "size" => 5 }]
27
- end
28
- end
29
-
30
- describe "json makro" do
31
- it "should expand json" do
32
- @doc.hash = { "hash" => { "key" => "// !json json.json" }, "lib" => { "json.json" => "value" } }
33
- @doc.inject_makros!
34
- @doc.hash["hash"]["key"].should == 'var json = "value";'
35
- end
36
-
37
- it "should not remove code that follows" do
38
- @doc.hash = { "hash" => { "key" => "// !json json.json\nvalue" }, "lib" => { "json.json" => "value" } }
39
- @doc.inject_makros!
40
- @doc.hash["hash"]["key"].should == "var json = \"value\";\nvalue"
41
- end
42
-
43
- it "should store injection" do
44
- @doc.hash = { "hash" => { "key" => "// !json json.json" }, "lib" => { "json.json" => "value" } }
45
- @doc.inject_makros!
46
- @doc.hash["injections"].should == [{ "makro" => "json", "target" => "hash/key", "lib" => "json.json", "start" => 0, "size" => 19 }]
47
- end
48
- end
49
- end
50
-
51
- describe "reject" do
52
- describe "code makro" do
53
- it "should reject code" do
54
- @doc.hash = { "lib" => { "code.js" => "value" }, "key" => "// !code code.js" }
55
- @doc.inject_makros!
56
- @doc.reject_makros!
57
- @doc.hash["key"].should == "// !code code.js"
58
- end
59
-
60
- it "should reject nested code" do
61
- @doc.hash = { "lib" => { "hash" => { "code.js" => "value" } }, "key" => "// !code hash/code.js" }
62
- @doc.inject_makros!
63
- @doc.reject_makros!
64
- @doc.hash["key"].should == "// !code hash/code.js"
65
- end
66
- end
67
-
68
- describe "json makro" do
69
- it "should reject json" do
70
- @doc.hash = { "lib" => { "json.json" => "value" }, "key" => "// !json json.json" }
71
- @doc.inject_makros!
72
- @doc.reject_makros!
73
- @doc.hash["key"].should == "// !json json.json"
74
- end
75
-
76
- it "should reject nested json" do
77
- @doc.hash = { "lib" => { "hash" => { "json.json" => "value" } }, "key" => "// !json hash/json.json" }
78
- @doc.inject_makros!
79
- @doc.reject_makros!
80
- @doc.hash["key"].should == "// !json hash/json.json"
81
- end
82
- end
83
-
84
- describe "many makros" do
85
- it "should reject properly" do
86
- @doc.hash = { "lib" => { "code.js" => "value", "other.js" => "value" }, "key" => "// !code code.js\n// !code other.js" }
87
- @doc.inject_makros!
88
- @doc.hash["injections"].should == [{"makro"=>"code", "size"=>5, "lib"=>"code.js", "start"=>0, "target"=>"key"}, {"makro"=>"code", "size"=>5, "lib"=>"other.js", "start"=>6, "target"=>"key"}]
89
- @doc.reject_makros!
90
- @doc.hash["key"].should == "// !code code.js\n// !code other.js"
91
- end
92
- end
93
- end
94
- end
data/spec/rid_spec.rb DELETED
@@ -1,7 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Rid" do
4
- it "should return .ridrc as config filename" do
5
- Rid::CONFIG_FILENAME.should == '.ridrc'
6
- end
7
- end