kitestrings 1.0.1 → 1.0.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/kitestrings.gemspec +5 -3
- data/lib/form_object.rb +8 -0
- data/lib/kitestrings/version.rb +1 -1
- data/lib/page_and_sort_helper.rb +4 -4
- data/spec/lib/page_and_sort_helper_spec.rb +11 -12
- data/spec/spec_helper.rb +2 -0
- data/spec/support/active_record.rb +13 -0
- metadata +35 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f8cfadafb753d3b207291378f33d28c54544695
|
4
|
+
data.tar.gz: 353789de7071c765b2a09134199761d43b1b2220
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8954419b577c34c1e9cf80930521ee623e01a6cd58aec11e7fd87c3b488e5da53ac8555342b1c52ec0f4a329cd14cb726df826201ed9383240451eec757ba1ce
|
7
|
+
data.tar.gz: a9f4038bc92af401e244105262d79bb6b138881c08090612eb542db17fb07363d2017ad86ee0c5dd7d5bcecb713521816188b05a56f27917ed483238a8d3253a
|
data/CHANGELOG.md
ADDED
data/kitestrings.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'kitestrings/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "kitestrings"
|
8
8
|
spec.version = Kitestrings::VERSION
|
9
|
-
spec.authors = ["ridget"]
|
10
|
-
spec.email = ["tom.ridge@tworedkites.com"]
|
9
|
+
spec.authors = ["ridget", "Matt Connolly"]
|
10
|
+
spec.email = ["tom.ridge@tworedkites.com", "matt.connolly@tworedkites.com"]
|
11
11
|
spec.summary = %q{For all the 2rk goodness}
|
12
12
|
spec.description = %q{}
|
13
13
|
spec.homepage = ""
|
@@ -24,5 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.6"
|
25
25
|
spec.add_development_dependency "rake"
|
26
26
|
spec.add_development_dependency "rspec", "~> 2.14"
|
27
|
-
spec.add_development_dependency
|
27
|
+
spec.add_development_dependency "generator_spec"
|
28
|
+
spec.add_development_dependency "sqlite3"
|
29
|
+
spec.add_development_dependency "activerecord", ">= 3.2"
|
28
30
|
end
|
data/lib/form_object.rb
CHANGED
@@ -78,6 +78,14 @@ module FormObject
|
|
78
78
|
result
|
79
79
|
end
|
80
80
|
|
81
|
+
# implement update as per ActiveRecord::Persistence
|
82
|
+
def update(attrs)
|
83
|
+
assign_attibutes(attrs)
|
84
|
+
save
|
85
|
+
end
|
86
|
+
|
87
|
+
alias update_attributes update
|
88
|
+
|
81
89
|
module DelegateEverything
|
82
90
|
def method_missing(method, *args, &block)
|
83
91
|
if resource.respond_to?(method)
|
data/lib/kitestrings/version.rb
CHANGED
data/lib/page_and_sort_helper.rb
CHANGED
@@ -88,11 +88,11 @@ module PageAndSortHelper
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
else
|
94
|
-
# apply kaminari pagination
|
91
|
+
# apply kaminari pagination
|
92
|
+
if scope.respond_to?(:page) && !options[:skip_pagination]
|
95
93
|
scope.page(params[:page])
|
94
|
+
else
|
95
|
+
scope
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'page_and_sort_helper'
|
3
|
-
require 'active_record'
|
4
|
-
|
5
3
|
|
6
4
|
describe PageAndSortHelper do
|
7
5
|
|
8
|
-
# TODO: This spec file needs a test database to talk to. We don't have one set up for this gem yet.
|
9
|
-
|
10
6
|
class Record < ActiveRecord::Base
|
7
|
+
def self.order_by_genre(direction)
|
8
|
+
order("CASE genre_id WHEN 1 THEN 2 ELSE 3 END #{direction == :asc ? 'ASC' : 'DESC'}")
|
9
|
+
end
|
11
10
|
end
|
12
11
|
|
13
12
|
context "page_and_sort" do
|
@@ -32,15 +31,15 @@ describe PageAndSortHelper do
|
|
32
31
|
let(:params) { {sort: "name", sort_direction: "asc"} }
|
33
32
|
it "on Record.scoped" do
|
34
33
|
scope = subject.page_and_sort(scope_of(Record))
|
35
|
-
expect(scope.to_sql).to include("ORDER BY
|
34
|
+
expect(scope.to_sql).to include("ORDER BY \"records\".\"name\" ASC")
|
36
35
|
end
|
37
36
|
it "on Record" do
|
38
37
|
scope = subject.page_and_sort(Record)
|
39
|
-
expect(scope.to_sql).to include("ORDER BY
|
38
|
+
expect(scope.to_sql).to include("ORDER BY \"records\".\"name\" ASC")
|
40
39
|
end
|
41
40
|
it "on Record.where" do
|
42
41
|
scope = subject.page_and_sort(Record.where("a = b"))
|
43
|
-
expect(scope.to_sql).to include("ORDER BY
|
42
|
+
expect(scope.to_sql).to include("ORDER BY \"records\".\"name\" ASC")
|
44
43
|
expect(scope.to_sql).to include("a = b")
|
45
44
|
end
|
46
45
|
end
|
@@ -48,20 +47,20 @@ describe PageAndSortHelper do
|
|
48
47
|
let(:params) { {sort: "name", sort_direction: "desc"} }
|
49
48
|
it "on Record.scoped" do
|
50
49
|
scope = subject.page_and_sort(scope_of(Record))
|
51
|
-
expect(scope.to_sql).to include("ORDER BY
|
50
|
+
expect(scope.to_sql).to include("ORDER BY \"records\".\"name\" DESC")
|
52
51
|
end
|
53
52
|
it "on Record" do
|
54
53
|
scope = subject.page_and_sort(Record)
|
55
|
-
expect(scope.to_sql).to include("ORDER BY
|
54
|
+
expect(scope.to_sql).to include("ORDER BY \"records\".\"name\" DESC")
|
56
55
|
end
|
57
56
|
it "on Record.where" do
|
58
57
|
scope = subject.page_and_sort(Record.where("a = b"))
|
59
|
-
expect(scope.to_sql).to include("ORDER BY
|
58
|
+
expect(scope.to_sql).to include("ORDER BY \"records\".\"name\" DESC")
|
60
59
|
expect(scope.to_sql).to include("a = b")
|
61
60
|
end
|
62
61
|
end
|
63
62
|
context "record sort asc" do
|
64
|
-
let(:params) { {sort: "
|
63
|
+
let(:params) { {sort: "genre", sort_direction: "asc"} }
|
65
64
|
it "on Record.scoped" do
|
66
65
|
scope = subject.page_and_sort(scope_of(Record))
|
67
66
|
expect(scope.to_sql).to match(/ORDER BY CASE genre_id .* END ASC/)
|
@@ -77,7 +76,7 @@ describe PageAndSortHelper do
|
|
77
76
|
end
|
78
77
|
end
|
79
78
|
context "record sort desc" do
|
80
|
-
let(:params) { {sort: "
|
79
|
+
let(:params) { {sort: "genre", sort_direction: "desc"} }
|
81
80
|
it "on Record.scoped" do
|
82
81
|
scope = subject.page_and_sort(scope_of(Record))
|
83
82
|
expect(scope.to_sql).to match(/ORDER BY CASE genre_id .* END DESC/)
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
puts "creating in memory sql lite database"
|
4
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
5
|
+
|
6
|
+
ActiveRecord::Migration.create_table :record do |t|
|
7
|
+
t.string :name
|
8
|
+
t.integer :genre_id
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
class Record < ActiveRecord::Base
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitestrings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ridget
|
8
|
+
- Matt Connolly
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rails
|
@@ -94,15 +95,45 @@ dependencies:
|
|
94
95
|
- - ">="
|
95
96
|
- !ruby/object:Gem::Version
|
96
97
|
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: sqlite3
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: activerecord
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '3.2'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '3.2'
|
97
126
|
description: ''
|
98
127
|
email:
|
99
128
|
- tom.ridge@tworedkites.com
|
129
|
+
- matt.connolly@tworedkites.com
|
100
130
|
executables: []
|
101
131
|
extensions: []
|
102
132
|
extra_rdoc_files: []
|
103
133
|
files:
|
104
134
|
- ".gitignore"
|
105
135
|
- ".rspec"
|
136
|
+
- CHANGELOG.md
|
106
137
|
- Gemfile
|
107
138
|
- LICENSE.txt
|
108
139
|
- README.md
|
@@ -147,6 +178,7 @@ files:
|
|
147
178
|
- spec/lib/page_and_sort_helper_spec.rb
|
148
179
|
- spec/lib/size_validator_spec.rb
|
149
180
|
- spec/spec_helper.rb
|
181
|
+
- spec/support/active_record.rb
|
150
182
|
homepage: ''
|
151
183
|
licenses:
|
152
184
|
- MIT
|
@@ -179,3 +211,4 @@ test_files:
|
|
179
211
|
- spec/lib/page_and_sort_helper_spec.rb
|
180
212
|
- spec/lib/size_validator_spec.rb
|
181
213
|
- spec/spec_helper.rb
|
214
|
+
- spec/support/active_record.rb
|