amrita2 2.0.0 → 2.0.1
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.
- data/README +1 -1
- data/init.rb +1 -0
- data/lib/amrita2/rails_bridge.rb +92 -7
- data/lib/amrita2/template.rb +12 -127
- data/lib/amrita2/testsupport.rb +0 -25
- data/lib/amrita2/version.rb +1 -1
- data/sample/depot/app/controllers/admin_controller.rb +3 -1
- data/sample/depot/app/helpers/cart_helper.rb +8 -0
- data/sample/depot/app/helpers/price_helper.rb +7 -0
- data/sample/depot/config/environment.rb +0 -14
- data/sample/depot/config/environments/development.rb +2 -2
- data/sample/depot/db/schema.rb +27 -20
- data/sample/depot/test/functional/admin_controller_test.rb +63 -22
- data/sample/depot/test/functional/store_controller_test.rb +30 -18
- data/sample/depot/vendor/plugins/will_paginate/init.rb +4 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate.rb +61 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +132 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +80 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +181 -0
- data/sample/depot/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +206 -0
- data/sample/depot/vendor/plugins/will_paginate/test/array_pagination_test.rb +131 -0
- data/sample/depot/vendor/plugins/will_paginate/test/boot.rb +23 -0
- data/sample/depot/vendor/plugins/will_paginate/test/finder_test.rb +290 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/admin.rb +3 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/company.rb +9 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/developer.rb +11 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/project.rb +15 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/reply.rb +5 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/schema.rb +38 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/topic.rb +4 -0
- data/sample/depot/vendor/plugins/will_paginate/test/fixtures/user.rb +2 -0
- data/sample/depot/vendor/plugins/will_paginate/test/helper.rb +25 -0
- data/sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_case.rb +23 -0
- data/sample/depot/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +67 -0
- data/sample/depot/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +13 -0
- data/sample/depot/vendor/plugins/will_paginate/test/pagination_test.rb +240 -0
- data/sample/hello/test1.rb +23 -0
- data/sample/login_engine/config/environment.rb +18 -20
- data/sample/login_engine/config/environments/development.rb +2 -2
- data/sample/login_engine/db/schema.rb +24 -17
- data/sample/login_engine/lib/login_engine/authenticated_system.rb +18 -18
- data/sample/login_engine/test/functional/user_controller_test.rb +1 -0
- data/sample/ramaze/ramaise_amrita2.rb +156 -0
- data/specs/attribute.rb +11 -0
- data/specs/datatypes.rb +13 -0
- data/specs/sample.rb +1 -2
- data/specs/sanitize.rb +14 -0
- metadata +28 -7
- data/sample/depot/app/helpers/ar_form.rb +0 -169
- data/sample/depot/app/helpers/form_tag.rb +0 -24
- data/sample/depot/app/helpers/standard_form.rb +0 -73
- data/sample/depot/test/integration/dsl_user_stories_test.rb +0 -126
- data/sample/depot/test/integration/user_stories_test.rb +0 -70
@@ -0,0 +1,11 @@
|
|
1
|
+
class Developer < User
|
2
|
+
has_and_belongs_to_many :projects, :include => :topics, :order => 'projects.name'
|
3
|
+
|
4
|
+
def self.with_poor_ones(&block)
|
5
|
+
with_scope :find => { :conditions => ['salary <= ?', 80000], :order => 'salary' } do
|
6
|
+
yield
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.per_page() 10 end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Project < ActiveRecord::Base
|
2
|
+
has_and_belongs_to_many :developers, :uniq => true
|
3
|
+
|
4
|
+
has_many :topics
|
5
|
+
# :finder_sql => 'SELECT * FROM topics WHERE (topics.project_id = #{id})',
|
6
|
+
# :counter_sql => 'SELECT COUNT(*) FROM topics WHERE (topics.project_id = #{id})'
|
7
|
+
|
8
|
+
has_many :replies, :through => :topics do
|
9
|
+
def find_recent(params = {})
|
10
|
+
with_scope :find => { :conditions => ['replies.created_at > ?', 15.minutes.ago] } do
|
11
|
+
find :all, params
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
|
3
|
+
create_table "developers_projects", :id => false, :force => true do |t|
|
4
|
+
t.column "developer_id", :integer, :null => false
|
5
|
+
t.column "project_id", :integer, :null => false
|
6
|
+
t.column "joined_on", :date
|
7
|
+
t.column "access_level", :integer, :default => 1
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table "projects", :force => true do |t|
|
11
|
+
t.column "name", :text
|
12
|
+
end
|
13
|
+
|
14
|
+
create_table "replies", :force => true do |t|
|
15
|
+
t.column "content", :text
|
16
|
+
t.column "created_at", :datetime
|
17
|
+
t.column "updated_at", :datetime
|
18
|
+
t.column "topic_id", :integer
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table "topics", :force => true do |t|
|
22
|
+
t.column "project_id", :integer
|
23
|
+
t.column "title", :string
|
24
|
+
t.column "subtitle", :string
|
25
|
+
t.column "content", :text
|
26
|
+
t.column "created_at", :datetime
|
27
|
+
t.column "updated_at", :datetime
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table "users", :force => true do |t|
|
31
|
+
t.column "name", :text
|
32
|
+
t.column "salary", :integer, :default => 70000
|
33
|
+
t.column "created_at", :datetime
|
34
|
+
t.column "updated_at", :datetime
|
35
|
+
t.column "type", :text
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
# gem install redgreen for colored test output
|
5
|
+
begin require 'redgreen'; rescue LoadError; end
|
6
|
+
|
7
|
+
require File.join(File.dirname(__FILE__), 'boot') unless defined?(ActiveRecord)
|
8
|
+
|
9
|
+
class Test::Unit::TestCase
|
10
|
+
protected
|
11
|
+
def assert_respond_to_all object, methods
|
12
|
+
methods.each do |method|
|
13
|
+
[method.to_s, method.to_sym].each { |m| assert_respond_to object, m }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Wrap tests that use Mocha and skip if unavailable.
|
19
|
+
def uses_mocha(test_name)
|
20
|
+
require 'mocha' unless Object.const_defined?(:Mocha)
|
21
|
+
yield
|
22
|
+
rescue LoadError => load_error
|
23
|
+
raise unless load_error.message =~ /mocha/i
|
24
|
+
$stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'activerecord_test_connector')
|
2
|
+
|
3
|
+
class ActiveRecordTestCase < Test::Unit::TestCase
|
4
|
+
# Set our fixture path
|
5
|
+
if ActiveRecordTestConnector.able_to_connect
|
6
|
+
self.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
7
|
+
self.use_transactional_fixtures = false
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.fixtures(*args)
|
11
|
+
super if ActiveRecordTestConnector.connected
|
12
|
+
end
|
13
|
+
|
14
|
+
def run(*args)
|
15
|
+
super if ActiveRecordTestConnector.connected
|
16
|
+
end
|
17
|
+
|
18
|
+
# Default so Test::Unit::TestCase doesn't complain
|
19
|
+
def test_truth
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
ActiveRecordTestConnector.setup
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'active_record/version'
|
3
|
+
require 'active_record/fixtures'
|
4
|
+
|
5
|
+
class ActiveRecordTestConnector
|
6
|
+
cattr_accessor :able_to_connect
|
7
|
+
cattr_accessor :connected
|
8
|
+
|
9
|
+
# Set our defaults
|
10
|
+
self.connected = false
|
11
|
+
self.able_to_connect = true
|
12
|
+
|
13
|
+
def self.setup
|
14
|
+
unless self.connected || !self.able_to_connect
|
15
|
+
setup_connection
|
16
|
+
load_schema
|
17
|
+
# require_fixture_models
|
18
|
+
Dependencies.load_paths.unshift(File.dirname(__FILE__) + "/../fixtures")
|
19
|
+
self.connected = true
|
20
|
+
end
|
21
|
+
rescue Exception => e # errors from ActiveRecord setup
|
22
|
+
$stderr.puts "\nSkipping ActiveRecord assertion tests: #{e}"
|
23
|
+
#$stderr.puts " #{e.backtrace.join("\n ")}\n"
|
24
|
+
self.able_to_connect = false
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.setup_connection
|
30
|
+
if Object.const_defined?(:ActiveRecord)
|
31
|
+
defaults = { :database => ':memory:' }
|
32
|
+
ActiveRecord::Base.logger = Logger.new STDOUT if $0 == 'irb'
|
33
|
+
|
34
|
+
begin
|
35
|
+
options = defaults.merge :adapter => 'sqlite3', :timeout => 500
|
36
|
+
ActiveRecord::Base.establish_connection(options)
|
37
|
+
ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options }
|
38
|
+
ActiveRecord::Base.connection
|
39
|
+
rescue Exception # errors from establishing a connection
|
40
|
+
$stderr.puts 'SQLite 3 unavailable; trying SQLite 2.'
|
41
|
+
options = defaults.merge :adapter => 'sqlite'
|
42
|
+
ActiveRecord::Base.establish_connection(options)
|
43
|
+
ActiveRecord::Base.configurations = { 'sqlite2_ar_integration' => options }
|
44
|
+
ActiveRecord::Base.connection
|
45
|
+
end
|
46
|
+
|
47
|
+
unless Object.const_defined?(:QUOTED_TYPE)
|
48
|
+
Object.send :const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')
|
49
|
+
end
|
50
|
+
else
|
51
|
+
raise "Can't setup connection since ActiveRecord isn't loaded."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.load_schema
|
56
|
+
ActiveRecord::Base.silence do
|
57
|
+
ActiveRecord::Migration.verbose = false
|
58
|
+
load File.dirname(__FILE__) + "/../fixtures/schema.rb"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.require_fixture_models
|
63
|
+
models = Dir.glob(File.dirname(__FILE__) + "/../fixtures/*.rb")
|
64
|
+
models = (models.grep(/user.rb/) + models).uniq
|
65
|
+
models.each { |f| require f }
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
dirname = File.dirname(__FILE__)
|
2
|
+
require File.join(dirname, '..', 'boot')
|
3
|
+
require File.join(dirname, 'activerecord_test_connector')
|
4
|
+
|
5
|
+
# setup the connection
|
6
|
+
ActiveRecordTestConnector.setup
|
7
|
+
|
8
|
+
# load all fixtures
|
9
|
+
fixture_path = File.join(dirname, '..', 'fixtures')
|
10
|
+
Fixtures.create_fixtures(fixture_path, ActiveRecord::Base.connection.tables)
|
11
|
+
|
12
|
+
require 'will_paginate'
|
13
|
+
WillPaginate.enable_activerecord
|
@@ -0,0 +1,240 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'action_controller'
|
3
|
+
require 'action_controller/test_process'
|
4
|
+
|
5
|
+
ActionController::Routing::Routes.draw do |map|
|
6
|
+
map.connect ':controller/:action/:id'
|
7
|
+
end
|
8
|
+
|
9
|
+
ActionController::Base.perform_caching = false
|
10
|
+
|
11
|
+
require 'will_paginate'
|
12
|
+
WillPaginate.enable_actionpack
|
13
|
+
|
14
|
+
class PaginationTest < Test::Unit::TestCase
|
15
|
+
|
16
|
+
class DevelopersController < ActionController::Base
|
17
|
+
def list_developers
|
18
|
+
@options = session[:wp] || {}
|
19
|
+
|
20
|
+
@developers = (1..11).to_a.paginate(
|
21
|
+
:page => params[@options[:param_name] || :page] || 1,
|
22
|
+
:per_page => params[:per_page] || 4
|
23
|
+
)
|
24
|
+
|
25
|
+
render :inline => '<%= will_paginate @developers, @options %>'
|
26
|
+
end
|
27
|
+
|
28
|
+
def guess_collection_name
|
29
|
+
@developers = session[:wp]
|
30
|
+
@options = session[:wp_options]
|
31
|
+
render :inline => '<%= will_paginate @options %>'
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
def rescue_errors(e) raise e end
|
36
|
+
def rescue_action(e) raise e end
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup
|
40
|
+
@controller = DevelopersController.new
|
41
|
+
@request = ActionController::TestRequest.new
|
42
|
+
@response = ActionController::TestResponse.new
|
43
|
+
super
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_will_paginate
|
47
|
+
get :list_developers
|
48
|
+
|
49
|
+
entries = assigns :developers
|
50
|
+
assert entries
|
51
|
+
assert_equal 4, entries.size
|
52
|
+
|
53
|
+
assert_select 'div.pagination', 1, 'no main DIV' do |el|
|
54
|
+
assert_select 'a[href]', 3 do |elements|
|
55
|
+
validate_page_numbers [2,3,2], elements
|
56
|
+
assert_select elements.last, ':last-child', "Next »"
|
57
|
+
end
|
58
|
+
assert_select 'span', 2
|
59
|
+
assert_select 'span.disabled:first-child', "« Previous"
|
60
|
+
assert_select 'span.current', entries.current_page.to_s
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_will_paginate_with_options
|
65
|
+
get :list_developers, { :page => 2 }, :wp => {
|
66
|
+
:class => 'will_paginate', :prev_label => 'Prev', :next_label => 'Next'
|
67
|
+
}
|
68
|
+
assert_response :success
|
69
|
+
|
70
|
+
entries = assigns :developers
|
71
|
+
assert entries
|
72
|
+
assert_equal 4, entries.size
|
73
|
+
|
74
|
+
assert_select 'div.will_paginate', 1, 'no main DIV' do
|
75
|
+
assert_select 'a[href]', 4 do |elements|
|
76
|
+
validate_page_numbers [1,1,3,3], elements
|
77
|
+
assert_select elements.first, 'a', "Prev"
|
78
|
+
assert_select elements.last, 'a', "Next"
|
79
|
+
end
|
80
|
+
assert_select 'span.current', entries.current_page.to_s
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_will_paginate_without_container
|
85
|
+
get :list_developers, {}, :wp => { :container => false }
|
86
|
+
assert_select 'div.pagination', 0, 'no main DIV'
|
87
|
+
assert_select 'a[href]', 3
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_will_paginate_without_page_links
|
91
|
+
get :list_developers, { :page => 2 }, :wp => { :page_links => false }
|
92
|
+
assert_select 'a[href]', 2 do |elements|
|
93
|
+
validate_page_numbers [1,3], elements
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_will_paginate_preserves_parameters_on_get
|
98
|
+
get :list_developers, :foo => { :bar => 'baz' }
|
99
|
+
assert_links_match /foo%5Bbar%5D=baz/
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_will_paginate_doesnt_preserve_parameters_on_post
|
103
|
+
post :list_developers, :foo => 'bar'
|
104
|
+
assert_no_links_match /foo=bar/
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_adding_additional_parameters
|
108
|
+
get :list_developers, {}, :wp => { :params => { :foo => 'bar' } }
|
109
|
+
assert_links_match /foo=bar/
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_removing_arbitrary_parameters
|
113
|
+
get :list_developers, { :foo => 'bar' }, :wp => { :params => { :foo => nil } }
|
114
|
+
assert_no_links_match /foo=bar/
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_adding_additional_route_parameters
|
118
|
+
get :list_developers, {}, :wp => { :params => { :controller => 'baz' } }
|
119
|
+
assert_links_match %r{\Wbaz/list_developers\W}
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_will_paginate_with_custom_page_param
|
123
|
+
get :list_developers, { :developers_page => 2 }, :wp => { :param_name => :developers_page }
|
124
|
+
assert_response :success
|
125
|
+
|
126
|
+
entries = assigns :developers
|
127
|
+
assert entries
|
128
|
+
assert_equal 4, entries.size
|
129
|
+
|
130
|
+
assert_select 'div.pagination', 1, 'no main DIV' do
|
131
|
+
assert_select 'a[href]', 4 do |elements|
|
132
|
+
validate_page_numbers [1,1,3,3], elements, :developers_page
|
133
|
+
end
|
134
|
+
assert_select 'span.current', entries.current_page.to_s
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_will_paginate_windows
|
139
|
+
get :list_developers, { :page => 6, :per_page => 1 }, :wp => { :inner_window => 1 }
|
140
|
+
assert_response :success
|
141
|
+
|
142
|
+
entries = assigns :developers
|
143
|
+
assert entries
|
144
|
+
assert_equal 1, entries.size
|
145
|
+
|
146
|
+
assert_select 'div.pagination', 1, 'no main DIV' do
|
147
|
+
assert_select 'a[href]', 8 do |elements|
|
148
|
+
validate_page_numbers [5,1,2,5,7,10,11,7], elements
|
149
|
+
assert_select elements.first, 'a', "« Previous"
|
150
|
+
assert_select elements.last, 'a', "Next »"
|
151
|
+
end
|
152
|
+
assert_select 'span.current', entries.current_page.to_s
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_will_paginate_eliminates_small_gaps
|
157
|
+
get :list_developers, { :page => 6, :per_page => 1 }, :wp => { :inner_window => 2 }
|
158
|
+
assert_response :success
|
159
|
+
|
160
|
+
assert_select 'div.pagination', 1, 'no main DIV' do
|
161
|
+
assert_select 'a[href]', 12 do |elements|
|
162
|
+
validate_page_numbers [5,1,2,3,4,5,7,8,9,10,11,7], elements
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_no_pagination
|
168
|
+
get :list_developers, :per_page => 12
|
169
|
+
entries = assigns :developers
|
170
|
+
assert_equal 1, entries.page_count
|
171
|
+
assert_equal 11, entries.size
|
172
|
+
|
173
|
+
assert_equal '', @response.body
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_faulty_input_raises_error
|
177
|
+
assert_raise WillPaginate::InvalidPage do
|
178
|
+
get :list_developers, :page => 'foo'
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
uses_mocha 'helper internals' do
|
183
|
+
def test_collection_name_can_be_guessed
|
184
|
+
collection = mock
|
185
|
+
collection.expects(:page_count).returns(1)
|
186
|
+
get :guess_collection_name, {}, :wp => collection
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_inferred_collection_name_raises_error_when_nil
|
191
|
+
ex = assert_raise ArgumentError do
|
192
|
+
get :guess_collection_name, {}, :wp => nil
|
193
|
+
end
|
194
|
+
assert ex.message.include?('@developers')
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_setting_id_for_container
|
198
|
+
get :list_developers
|
199
|
+
assert_select 'div.pagination', 1 do |div|
|
200
|
+
assert_nil div.first['id']
|
201
|
+
end
|
202
|
+
# magic ID
|
203
|
+
get :list_developers, {}, :wp => { :id => true }
|
204
|
+
assert_select 'div.pagination', 1 do |div|
|
205
|
+
assert_equal 'fixnums_pagination', div.first['id']
|
206
|
+
end
|
207
|
+
# explicit ID
|
208
|
+
get :list_developers, {}, :wp => { :id => 'custom_id' }
|
209
|
+
assert_select 'div.pagination', 1 do |div|
|
210
|
+
assert_equal 'custom_id', div.first['id']
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
protected
|
215
|
+
|
216
|
+
def validate_page_numbers expected, links, param_name = :page
|
217
|
+
param_pattern = /\W#{param_name}=([^&]*)/
|
218
|
+
|
219
|
+
assert_equal(expected, links.map { |e|
|
220
|
+
e['href'] =~ param_pattern
|
221
|
+
$1 ? $1.to_i : $1
|
222
|
+
})
|
223
|
+
end
|
224
|
+
|
225
|
+
def assert_links_match pattern
|
226
|
+
assert_select 'div.pagination a[href]' do |elements|
|
227
|
+
elements.each do |el|
|
228
|
+
assert_match pattern, el['href']
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def assert_no_links_match pattern
|
234
|
+
assert_select 'div.pagination a[href]' do |elements|
|
235
|
+
elements.each do |el|
|
236
|
+
assert_no_match pattern, el['href']
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|