savage-beast 0.1.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.
- data/.gitignore +2 -0
- data/README.rdoc +42 -0
- data/Rakefile +25 -0
- data/VERSION +1 -0
- data/app/controllers/application.rb +6 -0
- data/app/controllers/beast_application_controller.rb +3 -0
- data/app/controllers/forums_controller.rb +64 -0
- data/app/controllers/moderators_controller.rb +10 -0
- data/app/controllers/monitorships_controller.rb +22 -0
- data/app/controllers/posts_controller.rb +134 -0
- data/app/controllers/topics_controller.rb +110 -0
- data/app/helpers/count_helper.rb +13 -0
- data/app/helpers/forums_helper.rb +15 -0
- data/app/helpers/moderators_helper.rb +2 -0
- data/app/helpers/monitorships_helper.rb +2 -0
- data/app/helpers/posts_helper.rb +3 -0
- data/app/helpers/topics_helper.rb +3 -0
- data/app/models/forum.rb +26 -0
- data/app/models/moderatorship.rb +6 -0
- data/app/models/monitorship.rb +5 -0
- data/app/models/monitorships_sweeper.rb +9 -0
- data/app/models/post.rb +33 -0
- data/app/models/posts_sweeper.rb +12 -0
- data/app/models/topic.rb +94 -0
- data/app/views/forums/_form.html.erb +21 -0
- data/app/views/forums/edit.html.erb +12 -0
- data/app/views/forums/index.html.erb +77 -0
- data/app/views/forums/new.html.erb +10 -0
- data/app/views/forums/show.html.erb +94 -0
- data/app/views/layouts/_head.html.erb +34 -0
- data/app/views/layouts/_post.rss.builder +9 -0
- data/app/views/layouts/application.html.erb +29 -0
- data/app/views/layouts/beast.html.erb +29 -0
- data/app/views/monitorships/create.js.rjs +4 -0
- data/app/views/monitorships/destroy.js.rjs +4 -0
- data/app/views/posts/_edit.html.erb +38 -0
- data/app/views/posts/edit.html.erb +14 -0
- data/app/views/posts/edit.js.rjs +6 -0
- data/app/views/posts/index.html.erb +53 -0
- data/app/views/posts/index.rss.builder +20 -0
- data/app/views/posts/monitored.html.erb +55 -0
- data/app/views/posts/monitored.rss.builder +15 -0
- data/app/views/posts/update.js.rjs +3 -0
- data/app/views/topics/_form.html.erb +28 -0
- data/app/views/topics/edit.html.erb +10 -0
- data/app/views/topics/index.html.erb +2 -0
- data/app/views/topics/new.html.erb +18 -0
- data/app/views/topics/show.html.erb +183 -0
- data/app/views/topics/show.rss.builder +16 -0
- data/config/routes.rb +18 -0
- data/generators/beast/beast_generator.rb +88 -0
- data/generators/beast/templates/migrations/create_savage_tables.rb +73 -0
- data/generators/beast/templates/public/images/clearbits/_readme.txt +12 -0
- data/generators/beast/templates/public/images/clearbits/add.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/addressbook.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/alert.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/apple.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow1_e.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow1_n.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow1_ne.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow1_nw.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow1_s.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow1_se.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow1_sw.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow1_w.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow2_e.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow2_n.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow2_ne.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow2_nw.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow2_s.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow2_se.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow2_sw.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow2_w.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow3_e.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow3_n.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow3_ne.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow3_nw.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow3_s.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow3_se.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow3_sw.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/arrow3_w.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/ascii.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/back.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/bg_blank.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/bg_circle.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/bg_rounded.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/bg_rounded_ne.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/bg_rounded_nw.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/bg_rounded_se.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/bg_rounded_sw.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/bigsmile.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/binary.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/blah.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/bstop.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/buy.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/calday.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/calendar.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/camera.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/cart.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/cd.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/cellphone.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/chat.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/check.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/close.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/comment.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/cube.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/day.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/denied.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/document.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/download.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/edit.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/eject.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/equalizer.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/first.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/flag.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/flash.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/folder.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/forward.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/frown.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/ftp.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/graph.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/heart.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/home.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/html.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/ipod.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/last.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/lock.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/loop.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/mail.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/man.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/manman.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/music.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/mute.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/mute_centered.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/newwindow.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/next.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/night.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/open.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/pause.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/phone.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/play.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/previous.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/quicktime.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/redo.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/reload.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/sad.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/save.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/scream.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/search.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/seconds.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/smile.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/smirk.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/star.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/stop.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/subtract.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/switch.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/target.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/tcp.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/time.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/toggle.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/tongue.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/tools.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/trackback.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/trash.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/tv.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/type.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/undo.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/unlock.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/upload.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/user.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/video.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/volume_high.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/volume_low.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/wifi.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/window.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/woman.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/womanman.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/work.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/zoomin.gif +0 -0
- data/generators/beast/templates/public/images/clearbits/zoomout.gif +0 -0
- data/generators/beast/templates/public/images/feed-icon.png +0 -0
- data/generators/beast/templates/public/images/rails.png +0 -0
- data/generators/beast/templates/public/images/reply_background.png +0 -0
- data/generators/beast/templates/public/images/small_circle.gif +0 -0
- data/generators/beast/templates/public/images/spinner.gif +0 -0
- data/generators/beast/templates/public/images/spinner_black.gif +0 -0
- data/generators/beast/templates/public/images/spinner_bounce.gif +0 -0
- data/generators/beast/templates/public/javascripts/beast.js +80 -0
- data/generators/beast/templates/public/stylesheets/display.css +941 -0
- data/lang/en.yml +206 -0
- data/lib/beast.rb +79 -0
- data/lib/savage_beast/application_helper.rb +91 -0
- data/lib/savage_beast/authentication_system.rb +47 -0
- data/lib/savage_beast/user_init.rb +79 -0
- data/lib/tasks/capistrano.rake +90 -0
- data/lib/tasks/deploy_edge.rake +44 -0
- data/lib/tasks/savage_beast.rake +133 -0
- data/po/beast.pot +712 -0
- data/po/nl/beast.po +700 -0
- data/tested_plugins/acts_as_list/README +23 -0
- data/tested_plugins/acts_as_list/init.rb +3 -0
- data/tested_plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/tested_plugins/acts_as_list/test/list_test.rb +332 -0
- data/tested_plugins/gibberish/LICENSE +18 -0
- data/tested_plugins/gibberish/README +118 -0
- data/tested_plugins/gibberish/Rakefile +14 -0
- data/tested_plugins/gibberish/init.rb +3 -0
- data/tested_plugins/gibberish/lang/es.yml +3 -0
- data/tested_plugins/gibberish/lang/fr.yml +3 -0
- data/tested_plugins/gibberish/lib/gibberish.rb +8 -0
- data/tested_plugins/gibberish/lib/gibberish/localize.rb +88 -0
- data/tested_plugins/gibberish/lib/gibberish/string_ext.rb +17 -0
- data/tested_plugins/gibberish/test/gibberish_test.rb +203 -0
- data/tested_plugins/gibberish/test/lang/es.yml +1 -0
- data/tested_plugins/gibberish/test/lang/fr.yml +1 -0
- data/tested_plugins/mislav-will_paginate/CHANGELOG.rdoc +110 -0
- data/tested_plugins/mislav-will_paginate/LICENSE +18 -0
- data/tested_plugins/mislav-will_paginate/README.rdoc +107 -0
- data/tested_plugins/mislav-will_paginate/Rakefile +53 -0
- data/tested_plugins/mislav-will_paginate/examples/apple-circle.gif +0 -0
- data/tested_plugins/mislav-will_paginate/examples/index.haml +69 -0
- data/tested_plugins/mislav-will_paginate/examples/index.html +92 -0
- data/tested_plugins/mislav-will_paginate/examples/pagination.css +90 -0
- data/tested_plugins/mislav-will_paginate/examples/pagination.sass +91 -0
- data/tested_plugins/mislav-will_paginate/init.rb +1 -0
- data/tested_plugins/mislav-will_paginate/lib/will_paginate.rb +78 -0
- data/tested_plugins/mislav-will_paginate/lib/will_paginate/array.rb +16 -0
- data/tested_plugins/mislav-will_paginate/lib/will_paginate/collection.rb +146 -0
- data/tested_plugins/mislav-will_paginate/lib/will_paginate/core_ext.rb +32 -0
- data/tested_plugins/mislav-will_paginate/lib/will_paginate/finder.rb +264 -0
- data/tested_plugins/mislav-will_paginate/lib/will_paginate/named_scope.rb +170 -0
- data/tested_plugins/mislav-will_paginate/lib/will_paginate/named_scope_patch.rb +37 -0
- data/tested_plugins/mislav-will_paginate/lib/will_paginate/version.rb +9 -0
- data/tested_plugins/mislav-will_paginate/lib/will_paginate/view_helpers.rb +402 -0
- data/tested_plugins/mislav-will_paginate/test/boot.rb +21 -0
- data/tested_plugins/mislav-will_paginate/test/collection_test.rb +143 -0
- data/tested_plugins/mislav-will_paginate/test/console +8 -0
- data/tested_plugins/mislav-will_paginate/test/database.yml +22 -0
- data/tested_plugins/mislav-will_paginate/test/finder_test.rb +476 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/admin.rb +3 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/developer.rb +14 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/developers_projects.yml +13 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/project.rb +15 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/projects.yml +6 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/replies.yml +29 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/reply.rb +7 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/schema.rb +38 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/topic.rb +10 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/topics.yml +30 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/user.rb +2 -0
- data/tested_plugins/mislav-will_paginate/test/fixtures/users.yml +35 -0
- data/tested_plugins/mislav-will_paginate/test/helper.rb +40 -0
- data/tested_plugins/mislav-will_paginate/test/lib/activerecord_test_case.rb +43 -0
- data/tested_plugins/mislav-will_paginate/test/lib/activerecord_test_connector.rb +75 -0
- data/tested_plugins/mislav-will_paginate/test/lib/load_fixtures.rb +11 -0
- data/tested_plugins/mislav-will_paginate/test/lib/view_test_process.rb +178 -0
- data/tested_plugins/mislav-will_paginate/test/tasks.rake +59 -0
- data/tested_plugins/mislav-will_paginate/test/view_test.rb +365 -0
- data/tested_plugins/white_list/README +29 -0
- data/tested_plugins/white_list/Rakefile +22 -0
- data/tested_plugins/white_list/init.rb +2 -0
- data/tested_plugins/white_list/lib/white_list_helper.rb +97 -0
- data/tested_plugins/white_list/test/white_list_test.rb +132 -0
- data/tested_plugins/white_list_formatted_content/init.rb +27 -0
- metadata +322 -0
@@ -0,0 +1,14 @@
|
|
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
|
+
named_scope :distinct, :select => 'DISTINCT `users`.*'
|
11
|
+
named_scope :poor, :conditions => ['salary <= ?', 80000], :order => 'salary'
|
12
|
+
|
13
|
+
def self.per_page() 10 end
|
14
|
+
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,29 @@
|
|
1
|
+
witty_retort:
|
2
|
+
id: 1
|
3
|
+
topic_id: 1
|
4
|
+
content: Birdman is better!
|
5
|
+
created_at: <%= 6.hours.ago.to_s(:db) %>
|
6
|
+
|
7
|
+
another:
|
8
|
+
id: 2
|
9
|
+
topic_id: 2
|
10
|
+
content: Nuh uh!
|
11
|
+
created_at: <%= 1.hour.ago.to_s(:db) %>
|
12
|
+
|
13
|
+
spam:
|
14
|
+
id: 3
|
15
|
+
topic_id: 1
|
16
|
+
content: Nice site!
|
17
|
+
created_at: <%= 1.hour.ago.to_s(:db) %>
|
18
|
+
|
19
|
+
decisive:
|
20
|
+
id: 4
|
21
|
+
topic_id: 4
|
22
|
+
content: "I'm getting to the bottom of this"
|
23
|
+
created_at: <%= 30.minutes.ago.to_s(:db) %>
|
24
|
+
|
25
|
+
brave:
|
26
|
+
id: 5
|
27
|
+
topic_id: 4
|
28
|
+
content: "AR doesn't scare me a bit"
|
29
|
+
created_at: <%= 10.minutes.ago.to_s(:db) %>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
|
3
|
+
create_table "users", :force => true do |t|
|
4
|
+
t.column "name", :text
|
5
|
+
t.column "salary", :integer, :default => 70000
|
6
|
+
t.column "created_at", :datetime
|
7
|
+
t.column "updated_at", :datetime
|
8
|
+
t.column "type", :text
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table "projects", :force => true do |t|
|
12
|
+
t.column "name", :text
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table "developers_projects", :id => false, :force => true do |t|
|
16
|
+
t.column "developer_id", :integer, :null => false
|
17
|
+
t.column "project_id", :integer, :null => false
|
18
|
+
t.column "joined_on", :date
|
19
|
+
t.column "access_level", :integer, :default => 1
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table "topics", :force => true do |t|
|
23
|
+
t.column "project_id", :integer
|
24
|
+
t.column "title", :string
|
25
|
+
t.column "subtitle", :string
|
26
|
+
t.column "content", :text
|
27
|
+
t.column "created_at", :datetime
|
28
|
+
t.column "updated_at", :datetime
|
29
|
+
end
|
30
|
+
|
31
|
+
create_table "replies", :force => true do |t|
|
32
|
+
t.column "content", :text
|
33
|
+
t.column "created_at", :datetime
|
34
|
+
t.column "updated_at", :datetime
|
35
|
+
t.column "topic_id", :integer
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Topic < ActiveRecord::Base
|
2
|
+
has_many :replies, :dependent => :destroy, :order => 'replies.created_at DESC'
|
3
|
+
belongs_to :project
|
4
|
+
|
5
|
+
named_scope :mentions_activerecord, :conditions => ['topics.title LIKE ?', '%ActiveRecord%']
|
6
|
+
|
7
|
+
named_scope :with_replies_starting_with, lambda { |text|
|
8
|
+
{ :conditions => "replies.content LIKE '#{text}%' ", :include => :replies }
|
9
|
+
}
|
10
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
futurama:
|
2
|
+
id: 1
|
3
|
+
title: Isnt futurama awesome?
|
4
|
+
subtitle: It really is, isnt it.
|
5
|
+
content: I like futurama
|
6
|
+
created_at: <%= 1.day.ago.to_s(:db) %>
|
7
|
+
updated_at:
|
8
|
+
|
9
|
+
harvey_birdman:
|
10
|
+
id: 2
|
11
|
+
title: Harvey Birdman is the king of all men
|
12
|
+
subtitle: yup
|
13
|
+
content: He really is
|
14
|
+
created_at: <%= 2.hours.ago.to_s(:db) %>
|
15
|
+
updated_at:
|
16
|
+
|
17
|
+
rails:
|
18
|
+
id: 3
|
19
|
+
project_id: 1
|
20
|
+
title: Rails is nice
|
21
|
+
subtitle: It makes me happy
|
22
|
+
content: except when I have to hack internals to fix pagination. even then really.
|
23
|
+
created_at: <%= 20.minutes.ago.to_s(:db) %>
|
24
|
+
|
25
|
+
ar:
|
26
|
+
id: 4
|
27
|
+
project_id: 1
|
28
|
+
title: ActiveRecord sometimes freaks me out
|
29
|
+
content: "I mean, what's the deal with eager loading?"
|
30
|
+
created_at: <%= 15.minutes.ago.to_s(:db) %>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
david:
|
2
|
+
id: 1
|
3
|
+
name: David
|
4
|
+
salary: 80000
|
5
|
+
type: Developer
|
6
|
+
|
7
|
+
jamis:
|
8
|
+
id: 2
|
9
|
+
name: Jamis
|
10
|
+
salary: 150000
|
11
|
+
type: Developer
|
12
|
+
|
13
|
+
<% for digit in 3..10 %>
|
14
|
+
dev_<%= digit %>:
|
15
|
+
id: <%= digit %>
|
16
|
+
name: fixture_<%= digit %>
|
17
|
+
salary: 100000
|
18
|
+
type: Developer
|
19
|
+
<% end %>
|
20
|
+
|
21
|
+
poor_jamis:
|
22
|
+
id: 11
|
23
|
+
name: Jamis
|
24
|
+
salary: 9000
|
25
|
+
type: Developer
|
26
|
+
|
27
|
+
admin:
|
28
|
+
id: 12
|
29
|
+
name: admin
|
30
|
+
type: Admin
|
31
|
+
|
32
|
+
goofy:
|
33
|
+
id: 13
|
34
|
+
name: Goofy
|
35
|
+
type: Admin
|
@@ -0,0 +1,40 @@
|
|
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 '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
|
+
|
17
|
+
def collect_deprecations
|
18
|
+
old_behavior = WillPaginate::Deprecation.behavior
|
19
|
+
deprecations = []
|
20
|
+
WillPaginate::Deprecation.behavior = Proc.new do |message, callstack|
|
21
|
+
deprecations << message
|
22
|
+
end
|
23
|
+
result = yield
|
24
|
+
[result, deprecations]
|
25
|
+
ensure
|
26
|
+
WillPaginate::Deprecation.behavior = old_behavior
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Wrap tests that use Mocha and skip if unavailable.
|
31
|
+
def uses_mocha(test_name)
|
32
|
+
unless Object.const_defined?(:Mocha)
|
33
|
+
gem 'mocha', '>= 0.9.5'
|
34
|
+
require 'mocha'
|
35
|
+
end
|
36
|
+
rescue LoadError => load_error
|
37
|
+
$stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
|
38
|
+
else
|
39
|
+
yield
|
40
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'lib/activerecord_test_connector'
|
2
|
+
|
3
|
+
class ActiveRecordTestCase < Test::Unit::TestCase
|
4
|
+
if defined?(ActiveSupport::Testing::SetupAndTeardown)
|
5
|
+
include ActiveSupport::Testing::SetupAndTeardown
|
6
|
+
end
|
7
|
+
|
8
|
+
if defined?(ActiveRecord::TestFixtures)
|
9
|
+
include ActiveRecord::TestFixtures
|
10
|
+
end
|
11
|
+
# Set our fixture path
|
12
|
+
if ActiveRecordTestConnector.able_to_connect
|
13
|
+
self.fixture_path = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
14
|
+
self.use_transactional_fixtures = true
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.fixtures(*args)
|
18
|
+
super if ActiveRecordTestConnector.connected
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(*args)
|
22
|
+
super if ActiveRecordTestConnector.connected
|
23
|
+
end
|
24
|
+
|
25
|
+
# Default so Test::Unit::TestCase doesn't complain
|
26
|
+
def test_truth
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def assert_queries(num = 1)
|
32
|
+
$query_count = 0
|
33
|
+
yield
|
34
|
+
ensure
|
35
|
+
assert_equal num, $query_count, "#{$query_count} instead of #{num} queries were executed."
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert_no_queries(&block)
|
39
|
+
assert_queries(0, &block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
ActiveRecordTestConnector.setup
|
@@ -0,0 +1,75 @@
|
|
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
|
+
FIXTURES_PATH = File.join(File.dirname(__FILE__), '..', 'fixtures')
|
10
|
+
|
11
|
+
# Set our defaults
|
12
|
+
self.connected = false
|
13
|
+
self.able_to_connect = true
|
14
|
+
|
15
|
+
def self.setup
|
16
|
+
unless self.connected || !self.able_to_connect
|
17
|
+
setup_connection
|
18
|
+
load_schema
|
19
|
+
add_load_path FIXTURES_PATH
|
20
|
+
self.connected = true
|
21
|
+
end
|
22
|
+
rescue Exception => e # errors from ActiveRecord setup
|
23
|
+
$stderr.puts "\nSkipping ActiveRecord tests: #{e}\n\n"
|
24
|
+
self.able_to_connect = false
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.add_load_path(path)
|
30
|
+
dep = defined?(ActiveSupport::Dependencies) ? ActiveSupport::Dependencies : ::Dependencies
|
31
|
+
dep.load_paths.unshift path
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.setup_connection
|
35
|
+
db = ENV['DB'].blank?? 'sqlite3' : ENV['DB']
|
36
|
+
|
37
|
+
configurations = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'database.yml'))
|
38
|
+
raise "no configuration for '#{db}'" unless configurations.key? db
|
39
|
+
configuration = configurations[db]
|
40
|
+
|
41
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT) if $0 == 'irb'
|
42
|
+
puts "using #{configuration['adapter']} adapter" unless ENV['DB'].blank?
|
43
|
+
|
44
|
+
gem 'sqlite3-ruby' if 'sqlite3' == db
|
45
|
+
|
46
|
+
ActiveRecord::Base.establish_connection(configuration)
|
47
|
+
ActiveRecord::Base.configurations = { db => configuration }
|
48
|
+
prepare ActiveRecord::Base.connection
|
49
|
+
|
50
|
+
unless Object.const_defined?(:QUOTED_TYPE)
|
51
|
+
Object.send :const_set, :QUOTED_TYPE, ActiveRecord::Base.connection.quote_column_name('type')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.load_schema
|
56
|
+
ActiveRecord::Base.silence do
|
57
|
+
ActiveRecord::Migration.verbose = false
|
58
|
+
load File.join(FIXTURES_PATH, 'schema.rb')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.prepare(conn)
|
63
|
+
class << conn
|
64
|
+
IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SHOW FIELDS /]
|
65
|
+
|
66
|
+
def execute_with_counting(sql, name = nil, &block)
|
67
|
+
$query_count ||= 0
|
68
|
+
$query_count += 1 unless IGNORED_SQL.any? { |r| sql =~ r }
|
69
|
+
execute_without_counting(sql, name, &block)
|
70
|
+
end
|
71
|
+
|
72
|
+
alias_method_chain :execute, :counting
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'boot'
|
2
|
+
require 'lib/activerecord_test_connector'
|
3
|
+
|
4
|
+
# setup the connection
|
5
|
+
ActiveRecordTestConnector.setup
|
6
|
+
|
7
|
+
# load all fixtures
|
8
|
+
Fixtures.create_fixtures(ActiveRecordTestConnector::FIXTURES_PATH, ActiveRecord::Base.connection.tables)
|
9
|
+
|
10
|
+
require 'will_paginate'
|
11
|
+
WillPaginate.enable_activerecord
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'action_controller'
|
2
|
+
require 'action_controller/test_process'
|
3
|
+
|
4
|
+
require 'will_paginate'
|
5
|
+
WillPaginate.enable_actionpack
|
6
|
+
|
7
|
+
ActionController::Routing::Routes.draw do |map|
|
8
|
+
map.connect 'dummy/page/:page', :controller => 'dummy'
|
9
|
+
map.connect 'dummy/dots/page.:page', :controller => 'dummy', :action => 'dots'
|
10
|
+
map.connect 'ibocorp/:page', :controller => 'ibocorp',
|
11
|
+
:requirements => { :page => /\d+/ },
|
12
|
+
:defaults => { :page => 1 }
|
13
|
+
|
14
|
+
map.connect ':controller/:action/:id'
|
15
|
+
end
|
16
|
+
|
17
|
+
ActionController::Base.perform_caching = false
|
18
|
+
|
19
|
+
class WillPaginate::ViewTestCase < Test::Unit::TestCase
|
20
|
+
if defined?(ActionController::TestCase::Assertions)
|
21
|
+
include ActionController::TestCase::Assertions
|
22
|
+
end
|
23
|
+
if defined?(ActiveSupport::Testing::Deprecation)
|
24
|
+
include ActiveSupport::Testing::Deprecation
|
25
|
+
end
|
26
|
+
|
27
|
+
def setup
|
28
|
+
super
|
29
|
+
@controller = DummyController.new
|
30
|
+
@request = @controller.request
|
31
|
+
@html_result = nil
|
32
|
+
@template = '<%= will_paginate collection, options %>'
|
33
|
+
|
34
|
+
@view = ActionView::Base.new
|
35
|
+
@view.assigns['controller'] = @controller
|
36
|
+
@view.assigns['_request'] = @request
|
37
|
+
@view.assigns['_params'] = @request.params
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_no_complain; end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def paginate(collection = {}, options = {}, &block)
|
45
|
+
if collection.instance_of? Hash
|
46
|
+
page_options = { :page => 1, :total_entries => 11, :per_page => 4 }.merge(collection)
|
47
|
+
collection = [1].paginate(page_options)
|
48
|
+
end
|
49
|
+
|
50
|
+
locals = { :collection => collection, :options => options }
|
51
|
+
|
52
|
+
unless @view.respond_to? :render_template
|
53
|
+
# Rails 2.2
|
54
|
+
@html_result = ActionView::InlineTemplate.new(@template).render(@view, locals)
|
55
|
+
else
|
56
|
+
if defined? ActionView::InlineTemplate
|
57
|
+
# Rails 2.1
|
58
|
+
args = [ ActionView::InlineTemplate.new(@view, @template, locals) ]
|
59
|
+
else
|
60
|
+
# older Rails versions
|
61
|
+
args = [nil, @template, nil, locals]
|
62
|
+
end
|
63
|
+
|
64
|
+
@html_result = @view.render_template(*args)
|
65
|
+
end
|
66
|
+
|
67
|
+
@html_document = HTML::Document.new(@html_result, true, false)
|
68
|
+
|
69
|
+
if block_given?
|
70
|
+
classname = options[:class] || WillPaginate::ViewHelpers.pagination_options[:class]
|
71
|
+
assert_select("div.#{classname}", 1, 'no main DIV', &block)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def response_from_page_or_rjs
|
76
|
+
@html_document.root
|
77
|
+
end
|
78
|
+
|
79
|
+
def validate_page_numbers expected, links, param_name = :page
|
80
|
+
param_pattern = /\W#{CGI.escape(param_name.to_s)}=([^&]*)/
|
81
|
+
|
82
|
+
assert_equal(expected, links.map { |e|
|
83
|
+
e['href'] =~ param_pattern
|
84
|
+
$1 ? $1.to_i : $1
|
85
|
+
})
|
86
|
+
end
|
87
|
+
|
88
|
+
def assert_links_match pattern, links = nil, numbers = nil
|
89
|
+
links ||= assert_select 'div.pagination a[href]' do |elements|
|
90
|
+
elements
|
91
|
+
end
|
92
|
+
|
93
|
+
pages = [] if numbers
|
94
|
+
|
95
|
+
links.each do |el|
|
96
|
+
assert_match pattern, el['href']
|
97
|
+
if numbers
|
98
|
+
el['href'] =~ pattern
|
99
|
+
pages << ($1.nil?? nil : $1.to_i)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_equal numbers, pages, "page numbers don't match" if numbers
|
104
|
+
end
|
105
|
+
|
106
|
+
def assert_no_links_match pattern
|
107
|
+
assert_select 'div.pagination a[href]' do |elements|
|
108
|
+
elements.each do |el|
|
109
|
+
assert_no_match pattern, el['href']
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class DummyRequest
|
116
|
+
attr_accessor :symbolized_path_parameters
|
117
|
+
|
118
|
+
def initialize
|
119
|
+
@get = true
|
120
|
+
@params = {}
|
121
|
+
@symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
|
122
|
+
end
|
123
|
+
|
124
|
+
def get?
|
125
|
+
@get
|
126
|
+
end
|
127
|
+
|
128
|
+
def post
|
129
|
+
@get = false
|
130
|
+
end
|
131
|
+
|
132
|
+
def relative_url_root
|
133
|
+
''
|
134
|
+
end
|
135
|
+
|
136
|
+
def params(more = nil)
|
137
|
+
@params.update(more) if more
|
138
|
+
@params
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
class DummyController
|
143
|
+
attr_reader :request
|
144
|
+
attr_accessor :controller_name
|
145
|
+
|
146
|
+
def initialize
|
147
|
+
@request = DummyRequest.new
|
148
|
+
@url = ActionController::UrlRewriter.new(@request, @request.params)
|
149
|
+
end
|
150
|
+
|
151
|
+
def params
|
152
|
+
@request.params
|
153
|
+
end
|
154
|
+
|
155
|
+
def url_for(params)
|
156
|
+
@url.rewrite(params)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
module HTML
|
161
|
+
Node.class_eval do
|
162
|
+
def inner_text
|
163
|
+
children.map(&:inner_text).join('')
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
Text.class_eval do
|
168
|
+
def inner_text
|
169
|
+
self.to_s
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
Tag.class_eval do
|
174
|
+
def inner_text
|
175
|
+
childless?? '' : super
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|