sorting_table_for 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.mdown +213 -0
- data/Rakefile +11 -0
- data/init.rb +7 -0
- data/lib/model/sorting_table_model_scope.rb +53 -0
- data/lib/sorting_table_for.rb +37 -0
- data/lib/sorting_table_for/i18n.rb +36 -0
- data/lib/sorting_table_for/table_builder.rb +366 -0
- data/lib/sorting_table_for/tools.rb +43 -0
- data/spec/db/database.yml +3 -0
- data/spec/db/schema.rb +20 -0
- data/spec/fixtures/user.rb +24 -0
- data/spec/helpers/builder_spec.rb +47 -0
- data/spec/helpers/cell_value_spec.rb +85 -0
- data/spec/helpers/column_spec.rb +359 -0
- data/spec/helpers/header_spec.rb +337 -0
- data/spec/helpers/i18n_spec.rb +54 -0
- data/spec/locales/test.yml +92 -0
- data/spec/locales/test_rails3.yml +92 -0
- data/spec/model/sorting_table_model_scope_spec.rb +89 -0
- data/spec/spec_helper.rb +70 -0
- metadata +89 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
test:
|
2
|
+
date:
|
3
|
+
formats:
|
4
|
+
default: "%Y-%m-%d"
|
5
|
+
short: "%b %d"
|
6
|
+
long: "%B %d, %Y"
|
7
|
+
|
8
|
+
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
|
9
|
+
abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
|
10
|
+
|
11
|
+
month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
|
12
|
+
abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
|
13
|
+
order:
|
14
|
+
- :year
|
15
|
+
- :month
|
16
|
+
- :day
|
17
|
+
|
18
|
+
time:
|
19
|
+
formats:
|
20
|
+
default: "%a, %d %b %Y %H:%M:%S %z"
|
21
|
+
short: "%d %b %H:%M"
|
22
|
+
long: "%B %d, %Y %H:%M"
|
23
|
+
am: "am"
|
24
|
+
pm: "pm"
|
25
|
+
|
26
|
+
number:
|
27
|
+
format:
|
28
|
+
separator: "."
|
29
|
+
delimiter: ","
|
30
|
+
precision: 3
|
31
|
+
significant: false
|
32
|
+
strip_insignificant_zeros: false
|
33
|
+
|
34
|
+
currency:
|
35
|
+
format:
|
36
|
+
format: "%u%n"
|
37
|
+
unit: "$"
|
38
|
+
separator: "."
|
39
|
+
delimiter: ","
|
40
|
+
precision: 2
|
41
|
+
significant: false
|
42
|
+
strip_insignificant_zeros: false
|
43
|
+
|
44
|
+
sorting_table_for:
|
45
|
+
total_entries: "Total Entries %{value}"
|
46
|
+
columns:
|
47
|
+
bool_true: 'True'
|
48
|
+
bool_false: 'False'
|
49
|
+
|
50
|
+
fakes:
|
51
|
+
index:
|
52
|
+
edit: 'Edit'
|
53
|
+
delete: 'Delete'
|
54
|
+
header:
|
55
|
+
username: 'Usernames'
|
56
|
+
firstname: 'Firstnames'
|
57
|
+
lastname: 'Lastnames'
|
58
|
+
position: 'Positions'
|
59
|
+
salary: 'Salary'
|
60
|
+
price: 'Prices'
|
61
|
+
active: 'Actives'
|
62
|
+
created_at: 'Created at'
|
63
|
+
updated_at: 'Updated at'
|
64
|
+
edit: 'Edit users'
|
65
|
+
delete: 'Delete users'
|
66
|
+
my_fake: 'Hello fake'
|
67
|
+
|
68
|
+
|
69
|
+
fake_scope:
|
70
|
+
my_test: 'Hello'
|
71
|
+
|
72
|
+
test_name: 'i18n name'
|
73
|
+
fakes_controller:
|
74
|
+
fake_action:
|
75
|
+
name: 'fake name'
|
76
|
+
my_test: 'say %{value}'
|
77
|
+
my_add:
|
78
|
+
name: 'fake add'
|
79
|
+
|
80
|
+
user:
|
81
|
+
fake_namespace:
|
82
|
+
fakes_controller:
|
83
|
+
fake_action:
|
84
|
+
name: 'fake'
|
85
|
+
|
86
|
+
fake_namespace:
|
87
|
+
fakes_controller:
|
88
|
+
fake_action:
|
89
|
+
name: 'fake namespace'
|
90
|
+
|
91
|
+
fake_action:
|
92
|
+
name: 'fake action'
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../fixtures/user')
|
3
|
+
|
4
|
+
describe SortingTableModelScope do
|
5
|
+
|
6
|
+
describe "# default usage" do
|
7
|
+
|
8
|
+
it "should do nothing with no option" do
|
9
|
+
User.sorting_table.all.should == User.all
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should do nothing with option nil" do
|
13
|
+
User.sorting_table(nil).all.should == User.all
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should do nothing with all options nil" do
|
17
|
+
User.sorting_table(nil, nil, nil).all.should == User.all
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise an error with 4 arguments" do
|
21
|
+
expect {
|
22
|
+
User.sorting_table(nil, nil, nil, nil).all
|
23
|
+
}.to raise_error { ArgumentError }
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should works with other scope" do
|
27
|
+
User.good_position.sorting_table.set_limit(2).all.should == User.find(:all, :conditions => 'position > 3', :limit => 2)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not erase other order" do
|
31
|
+
User.sorting_table(nil, :firstname, :desc).find(:all, :order => 'lastname asc').should == User.find(:all, :order => 'lastname asc, firstname desc')
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "# params usage" do
|
37
|
+
|
38
|
+
it "should works with correct params" do
|
39
|
+
User.sorting_table({ "table_sort" => { "username" => "asc" } }).all.should == User.find(:all, :order => 'username asc')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should do nothing with wrong column" do
|
43
|
+
User.sorting_table({ "table_sort" => { "test" => "asc" } }).all.should == User.all
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should do nothing with wrong direction" do
|
47
|
+
User.sorting_table({ "table_sort" => { "username" => "test" } }).all.should == User.all
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should do nothing with wrong arguments" do
|
51
|
+
User.sorting_table({ "table_sort" => { "price" => nil } }).all.should == User.all
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should do nothing with wrong arguments (2)" do
|
55
|
+
User.sorting_table({ "table_sort" => nil }).all.should == User.all
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should order by params not option" do
|
59
|
+
User.sorting_table({ "table_sort" => { "username" => "asc" } }, :firstname, :desc).all.should == User.find(:all, :order => 'username asc')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should works with custom param name" do
|
63
|
+
SortingTableFor::TableBuilder.params_sort_table = :sort_my_test
|
64
|
+
User.sorting_table({ "sort_my_test" => { "username" => "asc" } }).all.should == User.find(:all, :order => 'username asc')
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "# options usage" do
|
70
|
+
|
71
|
+
it "should works with option" do
|
72
|
+
User.sorting_table(nil, :username, :desc).all.should == User.find(:all, :order => 'username desc')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should set option asc if not given" do
|
76
|
+
User.sorting_table(nil, :username).all.should == User.find(:all, :order => 'username asc')
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should do nothing with wrong column" do
|
80
|
+
User.sorting_table(nil, :test).all.should == User.all
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should do nothing with wring direction" do
|
84
|
+
User.sorting_table(nil, :username, :test).all.should == User.all
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
5
|
+
rescue LoadError
|
6
|
+
puts "You need to install rspec in your base app"
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
|
10
|
+
puts "Launching spec for Rails #{Rails.version}"
|
11
|
+
|
12
|
+
if ::SortingTableFor::Tools::rails3?
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include Webrat::Matchers, :type => :views
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
## Load fixtures
|
20
|
+
##
|
21
|
+
|
22
|
+
ActiveRecord::Base.logger = false
|
23
|
+
#ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), 'debug.log'))
|
24
|
+
|
25
|
+
configuration = YAML.load_file(File.join(File.dirname(__FILE__), 'db', 'database.yml'))
|
26
|
+
ActiveRecord::Base.establish_connection(configuration[ENV["DB"] || "sqlite3"])
|
27
|
+
|
28
|
+
ActiveRecord::Base.silence do
|
29
|
+
ActiveRecord::Migration.verbose = false
|
30
|
+
load(File.join(File.dirname(__FILE__), "db", "schema.rb"))
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
## Load I18n locales
|
35
|
+
##
|
36
|
+
|
37
|
+
if ::SortingTableFor::Tools::rails3?
|
38
|
+
I18n.load_path = Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'locales', 'test_rails3.yml')]
|
39
|
+
else
|
40
|
+
I18n.load_path = Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'locales', 'test.yml')]
|
41
|
+
end
|
42
|
+
I18n.locale = :test
|
43
|
+
I18n.default_locale = :test
|
44
|
+
|
45
|
+
##
|
46
|
+
## Init plugin
|
47
|
+
##
|
48
|
+
|
49
|
+
require File.join(File.dirname(__FILE__), '..', 'init.rb')
|
50
|
+
|
51
|
+
##
|
52
|
+
## Spec Helper
|
53
|
+
##
|
54
|
+
|
55
|
+
module SortingTableForSpecHelper
|
56
|
+
include ActiveSupport
|
57
|
+
include SortingTableFor
|
58
|
+
|
59
|
+
def have_comp_tag(selector, options = {})
|
60
|
+
if ::SortingTableFor::Tools::rails3?
|
61
|
+
if options.has_key? :text
|
62
|
+
options[:content] = options[:text]
|
63
|
+
options.delete :text
|
64
|
+
end
|
65
|
+
return have_selector(selector, options)
|
66
|
+
end
|
67
|
+
have_tag(selector, options)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sorting_table_for
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Thomas Floch
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-30 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A Rails table builder made to easily create table or sort a table. The syntax is simple to write and easy to read.
|
23
|
+
email: thomas.floch@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/model/sorting_table_model_scope.rb
|
32
|
+
- lib/sorting_table_for/i18n.rb
|
33
|
+
- lib/sorting_table_for/table_builder.rb
|
34
|
+
- lib/sorting_table_for/tools.rb
|
35
|
+
- lib/sorting_table_for.rb
|
36
|
+
- spec/db/database.yml
|
37
|
+
- spec/db/schema.rb
|
38
|
+
- spec/fixtures/user.rb
|
39
|
+
- spec/helpers/builder_spec.rb
|
40
|
+
- spec/helpers/cell_value_spec.rb
|
41
|
+
- spec/helpers/column_spec.rb
|
42
|
+
- spec/helpers/header_spec.rb
|
43
|
+
- spec/helpers/i18n_spec.rb
|
44
|
+
- spec/locales/test.yml
|
45
|
+
- spec/locales/test_rails3.yml
|
46
|
+
- spec/model/sorting_table_model_scope_spec.rb
|
47
|
+
- spec/spec_helper.rb
|
48
|
+
- MIT-LICENSE
|
49
|
+
- Rakefile
|
50
|
+
- README.mdown
|
51
|
+
- init.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/arkownz/sorting_table_for
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 19
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 3
|
79
|
+
- 4
|
80
|
+
version: 1.3.4
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: sorting_table_for
|
84
|
+
rubygems_version: 1.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: A Rails table builder made to easily create and sort a table
|
88
|
+
test_files: []
|
89
|
+
|