mjs 0.0.6 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -3
- data/lib/mjs.rb +5 -85
- data/lib/mjs/helper.rb +33 -16
- data/lib/mjs/java_script_context.rb +1 -1
- data/lib/mjs/merb.rb +86 -0
- data/lib/mjs/sinatra.rb +11 -0
- data/spec/helper_spec.rb +127 -0
- data/spec/its_helper.rb +15 -0
- data/spec/mjs_spec.rb +3 -19
- data/spec/provide_helper.rb +36 -0
- data/spec/spec_helper.rb +12 -50
- metadata +29 -16
- data/spec/requests/main_spec.rb +0 -30
- data/stubs/app/controllers/application.rb +0 -2
- data/stubs/app/controllers/main.rb +0 -2
data/Rakefile
CHANGED
@@ -8,8 +8,8 @@ GEM_NAME = "mjs"
|
|
8
8
|
AUTHOR = "maiha"
|
9
9
|
EMAIL = "maiha@wota.jp"
|
10
10
|
HOMEPAGE = "http://github.com/maiha/mjs"
|
11
|
-
SUMMARY = "A
|
12
|
-
GEM_VERSION = "0.
|
11
|
+
SUMMARY = "A ruby library that offers Ajax actions like RJS with jQuery"
|
12
|
+
GEM_VERSION = "0.1.1"
|
13
13
|
|
14
14
|
spec = Gem::Specification.new do |s|
|
15
15
|
s.rubyforge_project = 'merb'
|
@@ -23,7 +23,8 @@ spec = Gem::Specification.new do |s|
|
|
23
23
|
s.author = AUTHOR
|
24
24
|
s.email = EMAIL
|
25
25
|
s.homepage = HOMEPAGE
|
26
|
-
s.add_dependency('merb-slices', '>= 1.0.7.1')
|
26
|
+
# s.add_dependency('merb-slices', '>= 1.0.7.1')
|
27
|
+
s.add_dependency('extlib', '>= 0.9.14')
|
27
28
|
s.require_path = 'lib'
|
28
29
|
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec,app,public,stubs}/**/*")
|
29
30
|
end
|
data/lib/mjs.rb
CHANGED
@@ -1,86 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
$:.unshift File.dirname(__FILE__)
|
4
|
-
|
5
|
-
dependency 'merb-slices', :immediate => true
|
6
|
-
Merb::Plugins.add_rakefiles "mjs/merbtasks", "mjs/slicetasks", "mjs/spectasks"
|
7
|
-
|
8
|
-
# Register the Slice for the current host application
|
9
|
-
Merb::Slices::register(__FILE__)
|
10
|
-
|
11
|
-
# Slice configuration - set this in a before_app_loads callback.
|
12
|
-
# By default a Slice uses its own layout, so you can swicht to
|
13
|
-
# the main application layout or no layout at all if needed.
|
14
|
-
#
|
15
|
-
# Configuration options:
|
16
|
-
# :layout - the layout to use; defaults to :mjs
|
17
|
-
# :mirror - which path component types to use on copy operations; defaults to all
|
18
|
-
Merb::Slices::config[:mjs][:layout] ||= :mjs
|
19
|
-
|
20
|
-
# All Slice code is expected to be namespaced inside a module
|
21
|
-
module Mjs
|
22
|
-
|
23
|
-
# Slice metadata
|
24
|
-
self.description = "A slice for the Merb framework that offers Ajax actions like RJS with jQuery"
|
25
|
-
self.version = "0.0.1"
|
26
|
-
self.author = "maiha"
|
27
|
-
|
28
|
-
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
29
|
-
# right after a slice's classes have been loaded internally.
|
30
|
-
def self.loaded
|
31
|
-
require 'mjs/helper'
|
32
|
-
end
|
33
|
-
|
34
|
-
# Initialization hook - runs before AfterAppLoads BootLoader
|
35
|
-
def self.init
|
36
|
-
Merb::Controller.send(:include, ::Mjs::Helper)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Activation hook - runs after AfterAppLoads BootLoader
|
40
|
-
def self.activate
|
41
|
-
end
|
42
|
-
|
43
|
-
# Deactivation hook - triggered by Merb::Slices.deactivate(Mjs)
|
44
|
-
def self.deactivate
|
45
|
-
end
|
46
|
-
|
47
|
-
# Setup routes inside the host application
|
48
|
-
#
|
49
|
-
# @param scope<Merb::Router::Behaviour>
|
50
|
-
# Routes will be added within this scope (namespace). In fact, any
|
51
|
-
# router behaviour is a valid namespace, so you can attach
|
52
|
-
# routes at any level of your router setup.
|
53
|
-
#
|
54
|
-
# @note prefix your named routes with :mjs_
|
55
|
-
# to avoid potential conflicts with global named routes.
|
56
|
-
def self.setup_router(scope)
|
57
|
-
# example of a named route
|
58
|
-
scope.match('/index(.:format)').to(:controller => 'main', :action => 'index').name(:index)
|
59
|
-
# the slice is mounted at /mjs - note that it comes before default_routes
|
60
|
-
scope.match('/').to(:controller => 'main', :action => 'index').name(:home)
|
61
|
-
# enable slice-level default routes by default
|
62
|
-
scope.default_routes
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
# Setup the slice layout for Mjs
|
68
|
-
#
|
69
|
-
# Use Mjs.push_path and Mjs.push_app_path
|
70
|
-
# to set paths to mjs-level and app-level paths. Example:
|
71
|
-
#
|
72
|
-
# Mjs.push_path(:application, Mjs.root)
|
73
|
-
# Mjs.push_app_path(:application, Merb.root / 'slices' / 'mjs')
|
74
|
-
# ...
|
75
|
-
#
|
76
|
-
# Any component path that hasn't been set will default to Mjs.root
|
77
|
-
#
|
78
|
-
# Or just call setup_default_structure! to setup a basic Merb MVC structure.
|
79
|
-
Mjs.setup_default_structure!
|
80
|
-
|
81
|
-
# Add dependencies for other Mjs classes below. Example:
|
82
|
-
# dependency "mjs/other"
|
83
|
-
|
84
|
-
|
85
|
-
|
1
|
+
module Mjs
|
86
2
|
end
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/mjs/helper'
|
5
|
+
require File.dirname(__FILE__) + '/mjs/merb'
|
6
|
+
require File.dirname(__FILE__) + '/mjs/sinatra'
|
data/lib/mjs/helper.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'extlib'
|
2
|
+
require File.dirname(__FILE__) + '/java_script_context'
|
2
3
|
|
3
4
|
module Mjs
|
4
5
|
module Helper
|
@@ -10,7 +11,6 @@ module Mjs
|
|
10
11
|
build_href(opts)
|
11
12
|
unless opts[:submit]
|
12
13
|
opts[:url] ||= opts[:href]
|
13
|
-
opts[:dataType] = "script"
|
14
14
|
end
|
15
15
|
function = "jQuery.ajax(%s);" % options_for_ajax(opts)
|
16
16
|
confirm = opts.delete(:confirm)
|
@@ -20,11 +20,10 @@ module Mjs
|
|
20
20
|
|
21
21
|
# experimental: not tested yet
|
22
22
|
def button_to(name, url='', opts={})
|
23
|
-
ajax = remote_function(opts)
|
24
23
|
opts[:type] = 'button'
|
25
24
|
opts[:value] = name
|
26
|
-
|
27
|
-
if opts.delete(:remote)
|
25
|
+
|
26
|
+
if opts.delete(:remote) || opts[:submit] || opts[:update]
|
28
27
|
ajax = remote_function(opts)
|
29
28
|
opts[:onclick] = "#{opts.delete(:onclick)}; #{ajax}; return false;"
|
30
29
|
end
|
@@ -33,13 +32,16 @@ module Mjs
|
|
33
32
|
|
34
33
|
# override! :link_to # for Ajax
|
35
34
|
def link_to(name, url='', opts={})
|
36
|
-
opts[:href]
|
37
|
-
|
38
|
-
|
35
|
+
opts[:href] ||= url
|
36
|
+
|
37
|
+
if opts.delete(:remote) || opts[:submit] || opts[:update]
|
38
|
+
ajax = remote_function(opts)
|
39
|
+
opts[:onclick] = "#{opts.delete(:onclick)}; #{ajax}; return false;"
|
40
|
+
opts[:href] = '#'
|
41
|
+
else
|
42
|
+
opts[:href] ||= url
|
43
|
+
end
|
39
44
|
|
40
|
-
ajax = remote_function(opts)
|
41
|
-
opts[:onclick] = "#{opts.delete(:onclick)}; #{ajax}; return false;"
|
42
|
-
opts[:href] = '#'
|
43
45
|
%{<a #{ opts.to_xml_attributes }>#{name}</a>}
|
44
46
|
end
|
45
47
|
|
@@ -64,7 +66,7 @@ module Mjs
|
|
64
66
|
|
65
67
|
private
|
66
68
|
def build_href(opts)
|
67
|
-
if opts[:href].is_a?(DataMapper::Resource)
|
69
|
+
if defined?(DataMapper) and opts[:href].is_a?(DataMapper::Resource)
|
68
70
|
record = opts[:href]
|
69
71
|
if record.new_record?
|
70
72
|
opts[:href] = resource(record.class.name.downcase.pluralize.intern, :new)
|
@@ -100,14 +102,20 @@ module Mjs
|
|
100
102
|
else
|
101
103
|
raise ArgumentError, "link_to :submit expects Symbol or String, but got #{submit.class.name}"
|
102
104
|
end
|
105
|
+
|
103
106
|
build_href(options)
|
104
107
|
|
105
108
|
if target
|
106
109
|
js_options[:type] = "'POST'"
|
107
110
|
js_options[:data] = "#{target}.serialize()"
|
108
111
|
end
|
112
|
+
|
113
|
+
if options[:type]
|
114
|
+
js_options[:type] = "'%s'" % options.delete(:type).to_s.upcase
|
115
|
+
end
|
116
|
+
|
109
117
|
js_options[:url] = "'#{options[:url] || options[:href]}'"
|
110
|
-
js_options[:dataType]
|
118
|
+
js_options[:dataType] ||= "'script'"
|
111
119
|
|
112
120
|
if js_options[:url].blank?
|
113
121
|
raise "Cannot build ajax options because url is blank. (#{options.inspect})"
|
@@ -136,8 +144,9 @@ module Mjs
|
|
136
144
|
# this method affects "options"
|
137
145
|
def build_callbacks!(options)
|
138
146
|
callbacks = {}
|
147
|
+
events = [:before, :success, :complete]
|
139
148
|
|
140
|
-
|
149
|
+
events.each do |event|
|
141
150
|
options[event] = Array(options[event])
|
142
151
|
end
|
143
152
|
|
@@ -148,13 +157,21 @@ module Mjs
|
|
148
157
|
options[:complete] << "#{target}.hide()"
|
149
158
|
end
|
150
159
|
|
151
|
-
|
160
|
+
# dom updator
|
161
|
+
update = options.delete(:update)
|
162
|
+
if update
|
163
|
+
callbacks[:dataType] = "'html'"
|
164
|
+
callbacks[:type] ||= "'POST'"
|
165
|
+
options[:success] << "%s.html(request)" % jquery_selector(update)
|
166
|
+
end
|
167
|
+
|
168
|
+
events.each do |event|
|
152
169
|
options[event] = options[event].compact * ';'
|
153
170
|
end
|
154
171
|
|
155
172
|
options.each do |callback, code|
|
156
173
|
if (name = AJAX_FUNCTIONS[callback])
|
157
|
-
callbacks[name.to_s] = "function(request){#{code}}"
|
174
|
+
callbacks[name.to_s] = "function(request){#{code}}" unless code.to_s.empty?
|
158
175
|
options.delete(callback)
|
159
176
|
end
|
160
177
|
end
|
@@ -42,7 +42,7 @@ module Mjs
|
|
42
42
|
JavaScriptElementProxy.new(self, id)
|
43
43
|
else
|
44
44
|
raise NotImplementedError, "[MJS] RecordIdentifier.dom_id(id)"
|
45
|
-
JavaScriptElementProxy.new(self, ActionController::RecordIdentifier.dom_id(id))
|
45
|
+
# JavaScriptElementProxy.new(self, ActionController::RecordIdentifier.dom_id(id))
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
data/lib/mjs/merb.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
if defined?(Merb::Plugins)
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)
|
4
|
+
|
5
|
+
dependency 'merb-slices', :immediate => true
|
6
|
+
Merb::Plugins.add_rakefiles "mjs/merbtasks", "mjs/slicetasks", "mjs/spectasks"
|
7
|
+
|
8
|
+
# Register the Slice for the current host application
|
9
|
+
Merb::Slices::register(__FILE__)
|
10
|
+
|
11
|
+
# Slice configuration - set this in a before_app_loads callback.
|
12
|
+
# By default a Slice uses its own layout, so you can swicht to
|
13
|
+
# the main application layout or no layout at all if needed.
|
14
|
+
#
|
15
|
+
# Configuration options:
|
16
|
+
# :layout - the layout to use; defaults to :mjs
|
17
|
+
# :mirror - which path component types to use on copy operations; defaults to all
|
18
|
+
Merb::Slices::config[:mjs][:layout] ||= :mjs
|
19
|
+
|
20
|
+
# All Slice code is expected to be namespaced inside a module
|
21
|
+
module Mjs
|
22
|
+
|
23
|
+
# Slice metadata
|
24
|
+
self.description = "A slice for the Merb framework that offers Ajax actions like RJS with jQuery"
|
25
|
+
self.version = "0.0.1"
|
26
|
+
self.author = "maiha"
|
27
|
+
|
28
|
+
# Stub classes loaded hook - runs before LoadClasses BootLoader
|
29
|
+
# right after a slice's classes have been loaded internally.
|
30
|
+
def self.loaded
|
31
|
+
require 'mjs/helper'
|
32
|
+
end
|
33
|
+
|
34
|
+
# Initialization hook - runs before AfterAppLoads BootLoader
|
35
|
+
def self.init
|
36
|
+
Merb::Controller.send(:include, ::Mjs::Helper)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Activation hook - runs after AfterAppLoads BootLoader
|
40
|
+
def self.activate
|
41
|
+
end
|
42
|
+
|
43
|
+
# Deactivation hook - triggered by Merb::Slices.deactivate(Mjs)
|
44
|
+
def self.deactivate
|
45
|
+
end
|
46
|
+
|
47
|
+
# Setup routes inside the host application
|
48
|
+
#
|
49
|
+
# @param scope<Merb::Router::Behaviour>
|
50
|
+
# Routes will be added within this scope (namespace). In fact, any
|
51
|
+
# router behaviour is a valid namespace, so you can attach
|
52
|
+
# routes at any level of your router setup.
|
53
|
+
#
|
54
|
+
# @note prefix your named routes with :mjs_
|
55
|
+
# to avoid potential conflicts with global named routes.
|
56
|
+
def self.setup_router(scope)
|
57
|
+
# example of a named route
|
58
|
+
scope.match('/index(.:format)').to(:controller => 'main', :action => 'index').name(:index)
|
59
|
+
# the slice is mounted at /mjs - note that it comes before default_routes
|
60
|
+
scope.match('/').to(:controller => 'main', :action => 'index').name(:home)
|
61
|
+
# enable slice-level default routes by default
|
62
|
+
scope.default_routes
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
# Setup the slice layout for Mjs
|
68
|
+
#
|
69
|
+
# Use Mjs.push_path and Mjs.push_app_path
|
70
|
+
# to set paths to mjs-level and app-level paths. Example:
|
71
|
+
#
|
72
|
+
# Mjs.push_path(:application, Mjs.root)
|
73
|
+
# Mjs.push_app_path(:application, Merb.root / 'slices' / 'mjs')
|
74
|
+
# ...
|
75
|
+
#
|
76
|
+
# Any component path that hasn't been set will default to Mjs.root
|
77
|
+
#
|
78
|
+
# Or just call setup_default_structure! to setup a basic Merb MVC structure.
|
79
|
+
Mjs.setup_default_structure!
|
80
|
+
|
81
|
+
# Add dependencies for other Mjs classes below. Example:
|
82
|
+
# dependency "mjs/other"
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
end
|
data/lib/mjs/sinatra.rb
ADDED
data/spec/helper_spec.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/spec_helper')
|
2
|
+
|
3
|
+
class HelperSandbox
|
4
|
+
include Mjs::Helper
|
5
|
+
end
|
6
|
+
|
7
|
+
module Spec::Example::Subject::ExampleGroupMethods
|
8
|
+
def remote_function(opts, expected = nil, &block)
|
9
|
+
it "remote_function(#{opts.inspect})" do
|
10
|
+
subject.remote_function(opts).should == (expected || block.call)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe Mjs::Helper do
|
16
|
+
subject {HelperSandbox.new}
|
17
|
+
|
18
|
+
######################################################################
|
19
|
+
### link_to
|
20
|
+
|
21
|
+
provide :link_to
|
22
|
+
|
23
|
+
describe "#link_to" do
|
24
|
+
def call(opts = {})
|
25
|
+
subject.link_to("label", '/', opts)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not call remote_function" do
|
29
|
+
mock(subject).remote_function.never
|
30
|
+
call
|
31
|
+
end
|
32
|
+
|
33
|
+
describe " should call remote_function" do
|
34
|
+
before do
|
35
|
+
mock(subject).remote_function.with_any_args
|
36
|
+
end
|
37
|
+
|
38
|
+
it "when :remote given" do
|
39
|
+
call :remote => true
|
40
|
+
end
|
41
|
+
|
42
|
+
it "when :submit given" do
|
43
|
+
call :submit=>:form
|
44
|
+
end
|
45
|
+
|
46
|
+
it "when :update given" do
|
47
|
+
call :remote=>:dst
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
######################################################################
|
53
|
+
### button_to
|
54
|
+
|
55
|
+
provide :button_to
|
56
|
+
|
57
|
+
describe "#button_to" do
|
58
|
+
def call(opts = {})
|
59
|
+
subject.button_to("label", '/', opts)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not call remote_function" do
|
63
|
+
mock(subject).remote_function.never
|
64
|
+
call
|
65
|
+
end
|
66
|
+
|
67
|
+
describe " should call remote_function" do
|
68
|
+
before do
|
69
|
+
mock(subject).remote_function.with_any_args
|
70
|
+
end
|
71
|
+
|
72
|
+
it "when :remote given" do
|
73
|
+
call :remote => true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "when :submit given" do
|
77
|
+
call :submit=>:form
|
78
|
+
end
|
79
|
+
|
80
|
+
it "when :update given" do
|
81
|
+
call :remote=>:dst
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
######################################################################
|
87
|
+
### remote_function
|
88
|
+
|
89
|
+
provide :remote_function
|
90
|
+
|
91
|
+
remote_function(:url=>'/') do
|
92
|
+
"jQuery.ajax({dataType:'script', url:'/'});"
|
93
|
+
end
|
94
|
+
|
95
|
+
remote_function(:url=>'/', :remote=>true) do
|
96
|
+
"jQuery.ajax({dataType:'script', url:'/'});"
|
97
|
+
end
|
98
|
+
|
99
|
+
remote_function(:url=>'/', :submit=>:form) do
|
100
|
+
"jQuery.ajax({data:jQuery('#form input, #form select, #form textarea').serialize(), dataType:'script', type:'POST', url:'/'});"
|
101
|
+
end
|
102
|
+
|
103
|
+
remote_function(:url=>'/', :submit=>"form") do
|
104
|
+
"jQuery.ajax({data:jQuery('form').serialize(), dataType:'script', type:'POST', url:'/'});"
|
105
|
+
end
|
106
|
+
|
107
|
+
remote_function(:url=>'/', :update=>:dst) do
|
108
|
+
"jQuery.ajax({dataType:'html', success:function(request){jQuery('#dst').html(request)}, type:'POST', url:'/'});"
|
109
|
+
end
|
110
|
+
|
111
|
+
remote_function(:url=>'/', :update=>"dst") do
|
112
|
+
"jQuery.ajax({dataType:'html', success:function(request){jQuery('dst').html(request)}, type:'POST', url:'/'});"
|
113
|
+
end
|
114
|
+
|
115
|
+
remote_function(:url=>'/', :update=>:dst, :type=>:get) do
|
116
|
+
"jQuery.ajax({dataType:'html', success:function(request){jQuery('#dst').html(request)}, type:'GET', url:'/'});"
|
117
|
+
end
|
118
|
+
|
119
|
+
remote_function(:url=>'/', :update=>"dst", :type=>:get) do
|
120
|
+
"jQuery.ajax({dataType:'html', success:function(request){jQuery('dst').html(request)}, type:'GET', url:'/'});"
|
121
|
+
end
|
122
|
+
|
123
|
+
remote_function(:url=>'/', :submit=>"form", :update=>:dst) do
|
124
|
+
"jQuery.ajax({data:jQuery('form').serialize(), dataType:'html', success:function(request){jQuery('#dst').html(request)}, type:'POST', url:'/'});"
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
data/spec/its_helper.rb
ADDED
data/spec/mjs_spec.rb
CHANGED
@@ -1,20 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
1
|
+
require File.join(File.dirname(__FILE__), '/spec_helper')
|
2
2
|
|
3
|
-
describe "
|
4
|
-
|
5
|
-
# Implement your Mjs specs here
|
6
|
-
|
7
|
-
# To spec Mjs you need to hook it up to the router like this:
|
8
|
-
|
9
|
-
# before :all do
|
10
|
-
# Merb::Router.prepare { add_slice(:Mjs) } if standalone?
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# after :all do
|
14
|
-
# Merb::Router.reset! if standalone?
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# it "should have proper specs"
|
19
|
-
|
20
|
-
end
|
3
|
+
describe "xxx" do
|
4
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
######################################################################
|
2
|
+
### provide matcher
|
3
|
+
Spec::Matchers.define :provide do |expected|
|
4
|
+
match do |obj|
|
5
|
+
(obj.public_methods + obj.protected_methods + obj.private_methods).include?(expected.to_s)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Spec
|
10
|
+
module Example
|
11
|
+
module Subject
|
12
|
+
module ExampleGroupMethods
|
13
|
+
# == Examples
|
14
|
+
#
|
15
|
+
# describe User do
|
16
|
+
# subject { User.new }
|
17
|
+
# provide :name
|
18
|
+
#
|
19
|
+
# [intead of]
|
20
|
+
#
|
21
|
+
# it "should provide #name" do
|
22
|
+
# methods = subject.public_methods + subject.protected_methods + subject.private_methods
|
23
|
+
# methods.should include("name")
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
def provide(name)
|
28
|
+
it "should provide ##{name}" do
|
29
|
+
subject.should provide(name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
data/spec/spec_helper.rb
CHANGED
@@ -1,58 +1,20 @@
|
|
1
|
-
|
2
|
-
require 'merb-core'
|
3
|
-
require 'merb-slices'
|
1
|
+
|
4
2
|
require 'spec'
|
3
|
+
require 'rr'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
Spec::Runner.configure do |config|
|
6
|
+
config.mock_with RR::Adapters::Rspec
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
require
|
9
|
+
Dir.glob(File.join(File.dirname(__FILE__), '/../lib/*.rb')).each{|lib| require lib}
|
10
|
+
require File.join(File.dirname(__FILE__), '/its_helper')
|
11
|
+
require File.join(File.dirname(__FILE__), '/provide_helper')
|
12
12
|
|
13
|
-
# Using Merb.root below makes sure that the correct root is set for
|
14
|
-
# - testing standalone, without being installed as a gem and no host application
|
15
|
-
# - testing from within the host application; its root will be used
|
16
|
-
Merb.start_environment(
|
17
|
-
:testing => true,
|
18
|
-
:adapter => 'runner',
|
19
|
-
:environment => ENV['MERB_ENV'] || 'test',
|
20
|
-
:session_store => 'memory'
|
21
|
-
)
|
22
13
|
|
23
|
-
|
24
|
-
|
25
|
-
module SliceHelper
|
26
|
-
|
27
|
-
# The absolute path to the current slice
|
28
|
-
def current_slice_root
|
29
|
-
@current_slice_root ||= File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
30
|
-
end
|
31
|
-
|
32
|
-
# Whether the specs are being run from a host application or standalone
|
33
|
-
def standalone?
|
34
|
-
Merb.root == ::Mjs.root
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
14
|
+
def path(key)
|
15
|
+
Pathname(File.join(File.dirname(__FILE__) + "/fixtures/#{key}"))
|
39
16
|
end
|
40
17
|
|
41
|
-
|
42
|
-
|
43
|
-
config.include(Merb::Test::RouteHelper)
|
44
|
-
config.include(Merb::Test::ControllerHelper)
|
45
|
-
config.include(Merb::Test::SliceHelper)
|
18
|
+
def data(key)
|
19
|
+
(@__fixture_data_cache__ ||= {})[key] ||= path(key).read{}
|
46
20
|
end
|
47
|
-
|
48
|
-
# You can add your own helpers here
|
49
|
-
#
|
50
|
-
Merb::Test.add_helpers do
|
51
|
-
def mount_slice
|
52
|
-
Merb::Router.prepare { add_slice(:Mjs, "mjs") } if standalone?
|
53
|
-
end
|
54
|
-
|
55
|
-
def dismount_slice
|
56
|
-
Merb::Router.reset! if standalone?
|
57
|
-
end
|
58
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- maiha
|
@@ -9,20 +14,24 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-03-02 00:00:00 +09:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
name: extlib
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 9
|
30
|
+
- 14
|
31
|
+
version: 0.9.14
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: A ruby library that offers Ajax actions like RJS with jQuery
|
26
35
|
email: maiha@wota.jp
|
27
36
|
executables: []
|
28
37
|
|
@@ -41,13 +50,17 @@ files:
|
|
41
50
|
- lib/mjs/spectasks.rb
|
42
51
|
- lib/mjs/helper.rb
|
43
52
|
- lib/mjs/utils.rb
|
53
|
+
- lib/mjs/sinatra.rb
|
54
|
+
- lib/mjs/merb.rb
|
44
55
|
- lib/mjs/page_object.rb
|
45
56
|
- lib/mjs/slicetasks.rb
|
46
57
|
- lib/mjs/merbtasks.rb
|
47
58
|
- lib/mjs/java_script_context.rb
|
48
59
|
- spec/mjs_spec.rb
|
60
|
+
- spec/provide_helper.rb
|
61
|
+
- spec/helper_spec.rb
|
62
|
+
- spec/its_helper.rb
|
49
63
|
- spec/spec_helper.rb
|
50
|
-
- spec/requests/main_spec.rb
|
51
64
|
- app/views/layout/mjs.html.erb
|
52
65
|
- app/views/main/index.html.erb
|
53
66
|
- app/controllers/main.rb
|
@@ -55,8 +68,6 @@ files:
|
|
55
68
|
- app/helpers/application_helper.rb
|
56
69
|
- public/stylesheets/master.css
|
57
70
|
- public/javascripts/master.js
|
58
|
-
- stubs/app/controllers/main.rb
|
59
|
-
- stubs/app/controllers/application.rb
|
60
71
|
has_rdoc: true
|
61
72
|
homepage: http://github.com/maiha/mjs
|
62
73
|
licenses: []
|
@@ -70,20 +81,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
81
|
requirements:
|
71
82
|
- - ">="
|
72
83
|
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
73
86
|
version: "0"
|
74
|
-
version:
|
75
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
88
|
requirements:
|
77
89
|
- - ">="
|
78
90
|
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 0
|
79
93
|
version: "0"
|
80
|
-
version:
|
81
94
|
requirements: []
|
82
95
|
|
83
96
|
rubyforge_project: merb
|
84
|
-
rubygems_version: 1.3.
|
97
|
+
rubygems_version: 1.3.6
|
85
98
|
signing_key:
|
86
99
|
specification_version: 3
|
87
|
-
summary: A
|
100
|
+
summary: A ruby library that offers Ajax actions like RJS with jQuery
|
88
101
|
test_files: []
|
89
102
|
|
data/spec/requests/main_spec.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
|
2
|
-
|
3
|
-
describe "/mjs/" do
|
4
|
-
|
5
|
-
before(:all) do
|
6
|
-
mount_slice
|
7
|
-
end
|
8
|
-
|
9
|
-
describe "GET /" do
|
10
|
-
|
11
|
-
before(:each) do
|
12
|
-
@response = request("/mjs/")
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should be successful" do
|
16
|
-
@response.status.should be_successful
|
17
|
-
end
|
18
|
-
|
19
|
-
# This is just an example of what you can do
|
20
|
-
# You can also use the other webrat methods to click links,
|
21
|
-
# fill up forms etc...
|
22
|
-
it "should render the default slice layout" do
|
23
|
-
@response.should have_tag(:h1, :content => "Mjs Slice")
|
24
|
-
@response.should have_selector("div#container div#main")
|
25
|
-
@response.should have_xpath("//div[@id='container']/div[@id='main']")
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|