active_scaffold_sortable_vho 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2006 Richard White
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,94 @@
1
+ h1. Drag-Drop Sortable for ActiveScaffold
2
+
3
+ Currently, this plugin is compatible with rails 3.x and master branches of vhochstein/ActiveScaffold.
4
+
5
+ h2. Overview
6
+
7
+ This plugin enables those slicker-than-snot ajax drag-drop sortable elements on your active-scaffold page, with so little configuration you almost get it for free.
8
+
9
+ h2. Installation
10
+
11
+ You'll need at least vhochstein/ActiveScaffold to use this, and rails 3.x
12
+
13
+
14
+ <pre>
15
+ script/plugin install clone git://github.com/vhochstein/active_scaffold_sortable.git
16
+ </pre>
17
+
18
+ h2. Usage
19
+
20
+ h4. Step 1
21
+
22
+ Create a model with a column named 'position':
23
+
24
+ <pre>
25
+ # app/models/entry.rb
26
+
27
+ # id integer
28
+ # title string(255)
29
+ # birthday date
30
+ # position integer
31
+
32
+ class Entry < ActiveRecord::Base
33
+ end
34
+ </pre>
35
+
36
+ h4. Step 2
37
+
38
+ Create your scaffold controller
39
+
40
+ <pre>
41
+ # app/controllers/entries_controller.rb
42
+
43
+ class EntryController < ApplicationController
44
+ active_scaffold :entries do |config|
45
+ config.actions << :sortable
46
+ config.sortable.column = :position
47
+ end
48
+ end
49
+ </pre>
50
+
51
+
52
+ h4. Step 3
53
+
54
+ Create your layout
55
+
56
+ <pre>
57
+ # app/views/layouts/application.rhtml
58
+ <html>
59
+ <head>
60
+ <title>active scaffold demo application</title>
61
+ <%= javascript_include_tag :defaults %>
62
+ <%= active_scaffold_includes %>
63
+ </head>
64
+ <body>
65
+ <%= yield %>
66
+ </body>
67
+ </html>
68
+ </pre>
69
+
70
+ h2. Notice:
71
+
72
+ If you are using acts_as_list plugin you can skip the step 3
73
+
74
+ h2. Support
75
+
76
+ If you have issues installing the plugin, search / post to the "Active Scaffold":http://groups.google.com/group/activescaffold forum or "Create an issue":http://github.com/vhochstein/active_scaffold_sortable/issues
77
+
78
+ h2. Contributing
79
+
80
+ Fork, hack, push, and request a pull:
81
+
82
+ http://github.com/vhochstein/active_scaffold_sortable/
83
+
84
+ h2. License
85
+
86
+ Released under the MIT license (included).
87
+
88
+ h2. Author
89
+
90
+ Contact me:
91
+ <pre>
92
+ Tim Harper - irb(main):001:0> ( 'tim_see_harperATgmail._see_om'.gsub('_see_', 'c').gsub('AT', '@') )
93
+ Sergio Cambra - irb(main):001:0> ( 'sergioATentrecables._see_om'.gsub('_see_', 'c').gsub('AT', '@') )
94
+ </pre>
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ require './lib/active_scaffold_sortable/version.rb'
14
+ Jeweler::Tasks.new do |gem|
15
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
16
+ gem.name = "active_scaffold_sortable_vho"
17
+ gem.version = ActiveScaffoldSortable::Version::STRING
18
+ gem.homepage = "http://github.com/vhochstein/active_scaffold_sortable"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Drag n Drop Sorting for Activescaffold}
21
+ gem.description = %Q{Sort Tree or List Structures by Drag n Drop}
22
+ gem.email = "activescaffold@googlegroups.com"
23
+ gem.authors = ["Volker Hochstein"]
24
+ gem.add_runtime_dependency 'active_scaffold_vho', '~> 3.0'
25
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
26
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
27
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
28
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rake/testtask'
33
+ desc 'Test plugin.'
34
+ Rake::TestTask.new(:test) do |t|
35
+ t.libs << 'test'
36
+ t.pattern = 'test/**/*_test.rb'
37
+ t.verbose = true
38
+ end
39
+
40
+ require 'rcov/rcovtask'
41
+ Rcov::RcovTask.new do |test|
42
+ test.libs << 'test'
43
+ test.pattern = 'test/**/test_*.rb'
44
+ test.verbose = true
45
+ end
46
+
47
+ task :default => :test
48
+
49
+ require 'rake/rdoctask'
50
+ desc 'Generate documentation for plugin.'
51
+ Rake::RDocTask.new(:rdoc) do |rdoc|
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "active_scaffold_sortable #{ActiveScaffoldSortable::Version::STRING}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
@@ -0,0 +1,6 @@
1
+ .sortable {
2
+ cursor: move;
3
+ }
4
+ .sortable .in_place_editor_field {
5
+ cursor: pointer;
6
+ }
@@ -0,0 +1,9 @@
1
+ <%= render :super %>
2
+ <% if ActiveScaffold.js_framework == :prototype %>
3
+ <%= sortable_element *sort_params %>
4
+ <% elsif ActiveScaffold.js_framework == :jquery %>
5
+ <% reorder_params = {}
6
+ reorder_params[:eid] = params[:eid] unless params[:eid].blank?
7
+ options = {:update => true, :action => 'reorder'} %>
8
+ <%= javascript_tag "ActiveScaffold.sortable('#{sort_params[0]}', #{controller_name.to_json}, #{options.to_json}, #{reorder_params.to_json});" %>
9
+ <% end %>
@@ -0,0 +1,10 @@
1
+ page << render(:super, :locals => {:insert_at => :bottom})
2
+ unless nested? && (nested.belongs_to? || nested.has_one?)
3
+ if ActiveScaffold.js_framework == :prototype
4
+ page.sortable(*sort_params)
5
+ elsif ActiveScaffold.js_framework == :jquery
6
+ reorder_params = {}
7
+ reorder_params[:eid] = params[:eid] unless params[:eid].blank?
8
+ page << "ActiveScaffold.sortable('#{sort_params[0]}', #{controller_name.to_json}, #{reorder_params.to_json});"
9
+ end if controller.send :successful?
10
+ end
@@ -0,0 +1,11 @@
1
+ page << render(:super)
2
+ # if we are currently editing a nested belongs_to association do not do any sorting stuff
3
+ unless nested? && (nested.belongs_to? || nested.has_one?)
4
+ if ActiveScaffold.js_framework == :prototype
5
+ page.sortable(*sort_params)
6
+ elsif ActiveScaffold.js_framework == :jquery
7
+ reorder_params = {}
8
+ reorder_params[:eid] = params[:eid] unless params[:eid].blank?
9
+ page << "ActiveScaffold.sortable('#{sort_params[0]}', #{controller_name.to_json}, #{reorder_params.to_json});"
10
+ end if controller.send :successful?
11
+ end
@@ -0,0 +1 @@
1
+ page << "ActiveScaffold.stripe('#{active_scaffold_tbody_id}');"
data/init.rb ADDED
@@ -0,0 +1,9 @@
1
+ ACTIVE_SCAFFOLD_SORTABLE_INSTALLED = :plugin
2
+
3
+ require 'active_scaffold_sortable'
4
+
5
+ begin
6
+ ActiveScaffoldAssets.copy_to_public(ActiveScaffoldSortable.root)
7
+ rescue
8
+ raise $! unless Rails.env == 'production'
9
+ end
@@ -0,0 +1,80 @@
1
+ module ActiveScaffold::Actions
2
+ module Sortable
3
+ def self.included(base)
4
+ base.helper ActiveScaffold::Helpers::SortableHelpers
5
+ base.before_filter :sortable_authorized?, :only => :reorder
6
+ base.active_scaffold_config.configure do |config|
7
+ config.list.pagination = false
8
+
9
+ # turn sorting off
10
+ sortable_column = config.sortable.column.name
11
+ config.columns.each {|c| c.sort = false unless c.name == sortable_column }
12
+ config.list.sorting = { sortable_column => "asc" }
13
+
14
+ config.actions.each do |action_name|
15
+ action = config.send(action_name)
16
+ action.columns.exclude(sortable_column) if action.respond_to? :columns
17
+ end
18
+
19
+ dir = File.join(ActiveScaffold::Config::Sortable.plugin_directory, 'frontends')
20
+ base.add_active_scaffold_path File.join(dir, frontend, 'views') if config.frontend.to_sym != :default
21
+ base.add_active_scaffold_path File.join(dir, 'default', 'views')
22
+ end
23
+ end
24
+
25
+ def reorder
26
+ model = active_scaffold_config.model
27
+
28
+ unless (model.instance_methods & [:nested_set_scope, 'nested_set_scope']).empty?
29
+ reorder_children_in_tree(model)
30
+ else
31
+ if model.respond_to? :ancestry_column
32
+ reorder_ancestry_tree(model)
33
+ else
34
+ reorder_simple_list(model)
35
+ end
36
+ end
37
+ end
38
+
39
+ protected
40
+ def sortable_authorized?
41
+ authorized_for?(:action => :update)
42
+ end
43
+
44
+ def reorder_ancestry_tree(model)
45
+ first_record = model.find(params[active_scaffold_tbody_id].first)
46
+ unless first_record.nil?
47
+ records = first_record.is_root? ? model.roots: first_record.parent.children
48
+ reorder_simple_list(model)
49
+ else
50
+ Rails.logger.info("Failed to find first record to reorder")
51
+ end
52
+ end
53
+
54
+ def reorder_simple_list(model)
55
+ column_name = active_scaffold_config.sortable.column.name
56
+ params[active_scaffold_tbody_id].each_with_index do |id, index|
57
+ model.update_all({column_name => index + 1}, {model.primary_key => id})
58
+ end
59
+ end
60
+
61
+ def reorder_children_in_tree(model)
62
+ current_order = model.find(params[active_scaffold_tbody_id].first).try(:self_and_siblings)
63
+ new_order = params[active_scaffold_tbody_id].collect {|item_id| item_id.to_i}
64
+ new_order.each_with_index do |record_id, new_position|
65
+ if record_id != current_order[new_position].id
66
+ current_order = move_child(current_order.find {|child| child.id == record_id}, new_position, current_order)
67
+ end
68
+ end if new_order.length == current_order.length
69
+ end
70
+
71
+ def move_child(child, new_position, children)
72
+ old_position = children.index(child)
73
+ (old_position - new_position).abs.times do |step|
74
+ child.send((old_position - new_position) > 0 ? :move_left : :move_right)
75
+ end
76
+ child.self_and_siblings
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,30 @@
1
+ module ActiveScaffold::Config
2
+ class Sortable < Base
3
+ def initialize(core_config)
4
+ @options = {}
5
+ @core = core_config
6
+
7
+ self.column = core_config.model.new.position_column unless (@core.model.instance_methods & [:acts_as_list_class, 'acts_as_list_class']).empty?
8
+ self.column = core_config.model.new.left_column_name unless (@core.model.instance_methods & [:nested_set_scope, 'nested_set_scope']).empty?
9
+ if self.column.nil?
10
+ raise "ActiveScaffoldSortable: Missing sortable attribute '#{core_config.model.new.position_column}' in model '#{core_config.model.to_s}'" if @core.model.instance_methods.include? 'acts_as_list_class'
11
+ raise "ActiveScaffoldSortable: Missing sortable attribute '#{core_config.model.new.left_column_name}' in model '#{core_config.model.to_s}'" if @core.model.instance_methods.include? 'nested_set_scope'
12
+ end
13
+
14
+ end
15
+
16
+ cattr_accessor :plugin_directory
17
+ @@plugin_directory = File.expand_path(__FILE__).match(%{(^.*)/lib/active_scaffold/config/sortable.rb})[1]
18
+
19
+ self.crud_type = :update
20
+
21
+ attr_reader :column
22
+ def column=(column_name)
23
+ @column = @core.columns[column_name]
24
+ Rails.logger.error("ActiveScaffold Sortable: postion column: #{column_name} not found in model") if @column.nil?
25
+ @column
26
+ end
27
+
28
+ attr_accessor :options
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ module ActiveScaffold::Helpers
2
+ module SortableHelpers
3
+ def sort_params
4
+ options = {
5
+ :tag => 'tr',
6
+ :url => {:action => :reorder, :controller => controller_name },
7
+ :format => '/^[^_-](?:[A-Za-z0-9_-]*)-(.*)-row$/',
8
+ :with => "Sortable.serialize(#{active_scaffold_tbody_id.to_json})"
9
+ }
10
+ additional_params = [:parent_controller, :eid, :controller].reject {|param| params[param].blank?}
11
+ options[:with] = additional_params.inject(options[:with]) do |string, param|
12
+ "#{string} + '&#{param}=' + encodeURIComponent('#{escape_javascript params[param]}')"
13
+ end
14
+ options.merge! active_scaffold_config.sortable.options
15
+
16
+ [active_scaffold_tbody_id, options]
17
+ end
18
+
19
+ def list_row_class(record)
20
+ 'sortable'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ require "#{File.dirname(__FILE__)}/active_scaffold_sortable/config/core.rb"
2
+ require "#{File.dirname(__FILE__)}/active_scaffold_sortable/core.rb"
3
+ require "#{File.dirname(__FILE__)}/active_scaffold_sortable/view_helpers.rb"
4
+
5
+
6
+ module ActiveScaffoldSortable
7
+ def self.root
8
+ File.dirname(__FILE__) + "/.."
9
+ end
10
+ end
11
+
12
+ module ActiveScaffold
13
+ module Actions
14
+ ActiveScaffold.autoload_subdir('actions', self, File.dirname(__FILE__))
15
+ end
16
+
17
+ module Config
18
+ ActiveScaffold.autoload_subdir('config', self, File.dirname(__FILE__))
19
+ end
20
+
21
+ module Helpers
22
+ ActiveScaffold.autoload_subdir('helpers', self, File.dirname(__FILE__))
23
+ end
24
+ end
25
+
26
+ ActiveScaffold::Config::Core.send :include, ActiveScaffoldSortable::Core
27
+ ActionView::Base.send(:include, ActiveScaffoldSortable::ViewHelpers)
28
+
29
+ ##
30
+ ## Run the install assets script, too, just to make sure
31
+ ## But at least rescue the action in production
32
+ ##
33
+ Rails::Application.initializer("active_scaffold_sortable.install_assets", :after => "active_scaffold.install_assets") do
34
+ begin
35
+ ActiveScaffoldAssets.copy_to_public(ActiveScaffoldSortable.root)
36
+ rescue
37
+ raise $! unless Rails.env == 'production'
38
+ end
39
+ end unless defined?(ACTIVE_SCAFFOLD_SORTABLE_INSTALLED) && ACTIVE_SCAFFOLD_SORTABLE_INSTALLED == :plugin
@@ -0,0 +1,4 @@
1
+ # Need to open the AS module carefully due to Rails 2.3 lazy loading
2
+ ActiveScaffold::Config::Core.class_eval do
3
+ ActionDispatch::Routing::ACTIVE_SCAFFOLD_CORE_ROUTING[:collection][:reorder] = :post
4
+ end
@@ -0,0 +1,13 @@
1
+ module ActiveScaffoldSortable
2
+ module Core
3
+ def self.included(base)
4
+ base.alias_method_chain :initialize, :sortable
5
+ end
6
+
7
+ def initialize_with_sortable(model_id)
8
+ initialize_without_sortable(model_id)
9
+ # seems some rubies are returning strings in instance_methods and other symbols...
10
+ self.actions << :sortable if !(model.instance_methods & ['acts_as_list_class', :acts_as_list_class, 'nested_set_scope', :nested_set_scope]).empty?
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module ActiveScaffoldSortable
2
+ module Version
3
+ MAJOR = 3
4
+ MINOR = 0
5
+ PATCH = 0
6
+
7
+ STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module ActiveScaffoldSortable
2
+ module ViewHelpers
3
+ def self.included(base)
4
+ base.alias_method_chain :active_scaffold_stylesheets, :sortable
5
+ end
6
+
7
+ def active_scaffold_stylesheets_with_sortable(frontend = :default)
8
+ active_scaffold_stylesheets_without_sortable(frontend) + [ActiveScaffold::Config::Core.asset_path('sortable.css', frontend)]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ ACTIVE_SCAFFOLD_SORTABLE_INSTALLED = :gem
2
+ require 'active_scaffold_sortable'
@@ -0,0 +1,52 @@
1
+ require 'test_helper.rb'
2
+
3
+ class AutoModelsControllerTest < ActionController::TestCase
4
+ @@sortable_regexp = Regexp.new('Sortable.create\("as_auto_models-tbody", \{format:/\^\[\^_-\]\(\?:\[A-Za-z0-9_-\]\*\)-\(\.\*\)-row\$/, onUpdate:function\(\)\{new Ajax.Request\(\'/auto_models/reorder\', \{asynchronous:true, evalScripts:true, parameters:Sortable.serialize\("as_auto_models-tbody"\) \+ \'&controller=\' \+ encodeURIComponent\(\'auto_models\'\)\}\)\}, tag:\'tr\'\}\)')
5
+ setup { AutoModel.create :name => 'test', :position => 1 }
6
+
7
+ context "reordering" do
8
+ setup do
9
+ updates = sequence(:updates)
10
+ AutoModel.expects(:update_all).with({:position => 1}, 'id' => '2').in_sequence(updates)
11
+ AutoModel.expects(:update_all).with({:position => 2}, 'id' => '1').in_sequence(updates)
12
+ xhr :post, :reorder, :'as_auto_models-tbody' => ['2', '1']
13
+ end
14
+ should_respond_with :success
15
+ should_render_template :reorder
16
+ should "update stripe" do
17
+ assert_equal 'ActiveScaffold.stripe(\'as_auto_models-tbody\');', @response.body
18
+ end
19
+ end
20
+
21
+ context "listing" do
22
+ setup { get :index }
23
+ should "render record with sortable class" do
24
+ assert_select '.records tr.record.sortable'
25
+ end
26
+ should "render sortable script" do
27
+ assert_select 'script[type=text/javascript]', @@sortable_regexp
28
+ end
29
+ end
30
+
31
+ context "creating" do
32
+ setup { xhr :post, :create, :record => {:name => 'test2', :position => 2} }
33
+ should_respond_with :success
34
+ should "insert at top" do
35
+ assert_match "$(\"as_auto_models-tbody\").insert(\"as_auto_models-list-#{assigns(:record).id}-row\");", @response.body
36
+ end
37
+ should "update stripe" do
38
+ assert_match 'ActiveScaffold.stripe(\'as_auto_models-tbody\');', @response.body
39
+ end
40
+ should "update sortable" do
41
+ assert_match @@sortable_regexp, @response.body
42
+ end
43
+ end
44
+
45
+ context "updating" do
46
+ setup { xhr :put, :update, :id => 1, :record => {:name => 'test updated'} }
47
+ should_respond_with :success
48
+ should "update sortable" do
49
+ assert_match @@sortable_regexp, @response.body
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,59 @@
1
+ require 'test_helper.rb'
2
+
3
+ class ConfigTest < Test::Unit::TestCase
4
+ def test_not_enable_sortable
5
+ assert !ModelsController.active_scaffold_config.actions.include?(:sortable)
6
+ end
7
+
8
+ def test_auto_enable_sortable
9
+ assert AutoModelsController.active_scaffold_config.actions.include?(:sortable)
10
+ end
11
+
12
+ def test_manual_enable_sortable
13
+ assert SortableModelsController.active_scaffold_config.actions.include?(:sortable)
14
+ end
15
+
16
+ def test_position_column
17
+ assert_equal :position, AutoModelsController.active_scaffold_config.sortable.column.name
18
+ assert_equal :name, SortableModelsController.active_scaffold_config.sortable.column.name
19
+ end
20
+
21
+ def test_position_column_not_included
22
+ assert !AutoModelsController.active_scaffold_config.list.columns.include?(:position)
23
+ assert !AutoModelsController.active_scaffold_config.update.columns.include?(:position)
24
+ assert !AutoModelsController.active_scaffold_config.create.columns.include?(:position)
25
+ assert !AutoModelsController.active_scaffold_config.show.columns.include?(:position)
26
+ assert !AutoModelsController.active_scaffold_config.subform.columns.include?(:position)
27
+ assert !AutoModelsController.active_scaffold_config.search.columns.include?(:position)
28
+
29
+ assert !SortableModelsController.active_scaffold_config.list.columns.include?(:name)
30
+ assert !SortableModelsController.active_scaffold_config.update.columns.include?(:name)
31
+ assert !SortableModelsController.active_scaffold_config.create.columns.include?(:name)
32
+ assert !SortableModelsController.active_scaffold_config.show.columns.include?(:name)
33
+ end
34
+
35
+ def test_sorting
36
+ assert_equal('"models"."id" ASC', ModelsController.active_scaffold_config.list.sorting.clause)
37
+ assert ModelsController.active_scaffold_config.columns[:name].sortable?
38
+ assert ModelsController.active_scaffold_config.columns[:position].sortable?
39
+
40
+ assert_equal('"models"."position" ASC', AutoModelsController.active_scaffold_config.list.sorting.clause)
41
+ assert !AutoModelsController.active_scaffold_config.columns[:name].sortable?
42
+
43
+ assert_equal('"models"."name" ASC', SortableModelsController.active_scaffold_config.list.sorting.clause)
44
+ assert !SortableModelsController.active_scaffold_config.columns[:position].sortable?
45
+ end
46
+
47
+ def test_pagination
48
+ assert ModelsController.active_scaffold_config.list.pagination
49
+ assert !AutoModelsController.active_scaffold_config.list.pagination
50
+ assert !SortableModelsController.active_scaffold_config.list.pagination
51
+ end
52
+
53
+ def test_active_scaffold_paths
54
+ path = File.join(Rails.root, 'vendor/plugins/active_scaffold_sortable/frontends/default/views')
55
+ assert !ModelsController.active_scaffold_paths.include?(path)
56
+ assert AutoModelsController.active_scaffold_paths.include?(path)
57
+ assert SortableModelsController.active_scaffold_paths.include?(path)
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ class AutoModelsController < ActionController::Base
2
+ active_scaffold :auto_model
3
+ end
@@ -0,0 +1,3 @@
1
+ class ModelsController < ActionController::Base
2
+ active_scaffold
3
+ end
@@ -0,0 +1,7 @@
1
+ class SortableModelsController < ActionController::Base
2
+ active_scaffold :model do |config|
3
+ config.actions.exclude :search
4
+ config.actions << :sortable
5
+ config.sortable.column = :name
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class AutoModel < Model
2
+ def acts_as_list_class
3
+ end
4
+
5
+ def position_column
6
+ 'position'
7
+ end
8
+ end
@@ -0,0 +1,2 @@
1
+ class Model < ActiveRecord::Base
2
+ end
@@ -0,0 +1,5 @@
1
+ require 'test_helper.rb'
2
+
3
+ class RouterTest < ActionController::TestCase
4
+ should_route :post, "/sortable_models/reorder", :controller => :sortable_models, :action => :reorder
5
+ end
data/test/schema.rb ADDED
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ ActiveRecord::Schema.define(:version => 1) do
4
+ create_table 'models', :force => true do |t|
5
+ t.string 'name'
6
+ t.integer 'position'
7
+ end
8
+ add_index 'models', ['position']
9
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require 'test/unit'
5
+ # You can use "rake test AR_VERSION=2.0.5" to test against 2.0.5, for example.
6
+ # The default is to use the latest installed ActiveRecord.
7
+ if ENV["AR_VERSION"]
8
+ gem 'activerecord', "#{ENV["AR_VERSION"]}"
9
+ gem 'actionpack', "#{ENV["AR_VERSION"]}"
10
+ gem 'activesupport', "#{ENV["AR_VERSION"]}"
11
+ end
12
+ require 'rubygems'
13
+ require 'active_record'
14
+ require 'action_controller'
15
+ require 'action_view/test_case'
16
+ require 'action_mailer'
17
+ require 'active_support'
18
+ require 'initializer'
19
+ ActionController::Base::logger = ActiveSupport::BufferedLogger.new(Tempfile.new('log').path)
20
+
21
+ RAILS_ROOT = File.join(File.dirname(__FILE__), '../../../..')
22
+ Rails.configuration = Rails::Configuration.new
23
+
24
+ require 'shoulda'
25
+ require 'shoulda/rails'
26
+ require 'mocha'
27
+ begin
28
+ require 'redgreen'
29
+ rescue LoadError
30
+ end
31
+
32
+ ActiveSupport::Dependencies.load_paths = %w(test/models test/controllers lib ../active_scaffold/lib).map {|dir| File.dirname(__FILE__) + "/../#{dir}"}
33
+ $:.unshift *ActiveSupport::Dependencies.load_paths
34
+
35
+ require File.join(File.dirname(__FILE__), '../../active_scaffold/environment')
36
+ require 'sortable'
37
+
38
+ ActionController::Routing::Routes.draw do |map|
39
+ map.root :controller => 'home'
40
+ map.resources :sortable_models, :active_scaffold => true
41
+ map.resources :auto_models, :active_scaffold => true
42
+ map.resources :models, :active_scaffold => true
43
+ end
44
+
45
+ ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
46
+ silence_stream(STDOUT) do
47
+ load(File.dirname(__FILE__) + "/schema.rb")
48
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_scaffold_sortable_vho
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease: false
6
+ segments:
7
+ - 3
8
+ - 0
9
+ - 0
10
+ version: 3.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Volker Hochstein
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-27 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: shoulda
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ requirement: *id001
34
+ type: :development
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ name: bundler
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 0
48
+ version: 1.0.0
49
+ requirement: *id002
50
+ type: :development
51
+ - !ruby/object:Gem::Dependency
52
+ prerelease: false
53
+ name: jeweler
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 1
62
+ - 5
63
+ - 2
64
+ version: 1.5.2
65
+ requirement: *id003
66
+ type: :development
67
+ - !ruby/object:Gem::Dependency
68
+ prerelease: false
69
+ name: rcov
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirement: *id004
80
+ type: :development
81
+ - !ruby/object:Gem::Dependency
82
+ prerelease: false
83
+ name: active_scaffold_vho
84
+ version_requirements: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ hash: 7
90
+ segments:
91
+ - 3
92
+ - 0
93
+ version: "3.0"
94
+ requirement: *id005
95
+ type: :runtime
96
+ description: Sort Tree or List Structures by Drag n Drop
97
+ email: activescaffold@googlegroups.com
98
+ executables: []
99
+
100
+ extensions: []
101
+
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.textile
105
+ files:
106
+ - .document
107
+ - LICENSE.txt
108
+ - README.textile
109
+ - Rakefile
110
+ - frontends/default/stylesheets/sortable.css
111
+ - frontends/default/views/_list_with_header.html.erb
112
+ - frontends/default/views/on_create.js.rjs
113
+ - frontends/default/views/on_update.js.rjs
114
+ - frontends/default/views/reorder.js.rjs
115
+ - init.rb
116
+ - lib/active_scaffold/actions/sortable.rb
117
+ - lib/active_scaffold/config/sortable.rb
118
+ - lib/active_scaffold/helpers/sortable_helpers.rb
119
+ - lib/active_scaffold_sortable.rb
120
+ - lib/active_scaffold_sortable/config/core.rb
121
+ - lib/active_scaffold_sortable/core.rb
122
+ - lib/active_scaffold_sortable/version.rb
123
+ - lib/active_scaffold_sortable/view_helpers.rb
124
+ - lib/active_scaffold_sortable_vho.rb
125
+ - test/auto_models_controller_test.rb
126
+ - test/config_test.rb
127
+ - test/controllers/auto_models_controller.rb
128
+ - test/controllers/models_controller.rb
129
+ - test/controllers/sortable_models_controller.rb
130
+ - test/models/auto_model.rb
131
+ - test/models/model.rb
132
+ - test/router_test.rb
133
+ - test/schema.rb
134
+ - test/test_helper.rb
135
+ has_rdoc: true
136
+ homepage: http://github.com/vhochstein/active_scaffold_sortable
137
+ licenses:
138
+ - MIT
139
+ post_install_message:
140
+ rdoc_options: []
141
+
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: 3
150
+ segments:
151
+ - 0
152
+ version: "0"
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ hash: 3
159
+ segments:
160
+ - 0
161
+ version: "0"
162
+ requirements: []
163
+
164
+ rubyforge_project:
165
+ rubygems_version: 1.3.7
166
+ signing_key:
167
+ specification_version: 3
168
+ summary: Drag n Drop Sorting for Activescaffold
169
+ test_files:
170
+ - test/auto_models_controller_test.rb
171
+ - test/config_test.rb
172
+ - test/controllers/auto_models_controller.rb
173
+ - test/controllers/models_controller.rb
174
+ - test/controllers/sortable_models_controller.rb
175
+ - test/models/auto_model.rb
176
+ - test/models/model.rb
177
+ - test/router_test.rb
178
+ - test/schema.rb
179
+ - test/test_helper.rb