crudify 0.0.5 → 0.0.6

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  .bundle
2
2
  .DS_Store
3
3
  *.gem
4
+ Gemfile.lock
4
5
  pkg/*
5
6
  test/dummy/log
6
7
  test/dummy/tmp
data/Gemfile CHANGED
@@ -1,4 +1,2 @@
1
1
  source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in crudify.gemspec
4
2
  gemspec
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crudify (0.0.5)
4
+ crudify (0.0.6)
5
5
  meta_search (>= 1.0.1)
6
6
  rails (>= 3.0.0)
7
7
  will_paginate (>= 2.3.15)
@@ -10,32 +10,32 @@ GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
12
  abstract (1.0.0)
13
- actionmailer (3.0.5)
14
- actionpack (= 3.0.5)
13
+ actionmailer (3.0.7)
14
+ actionpack (= 3.0.7)
15
15
  mail (~> 2.2.15)
16
- actionpack (3.0.5)
17
- activemodel (= 3.0.5)
18
- activesupport (= 3.0.5)
16
+ actionpack (3.0.7)
17
+ activemodel (= 3.0.7)
18
+ activesupport (= 3.0.7)
19
19
  builder (~> 2.1.2)
20
20
  erubis (~> 2.6.6)
21
- i18n (~> 0.4)
21
+ i18n (~> 0.5.0)
22
22
  rack (~> 1.2.1)
23
- rack-mount (~> 0.6.13)
23
+ rack-mount (~> 0.6.14)
24
24
  rack-test (~> 0.5.7)
25
25
  tzinfo (~> 0.3.23)
26
- activemodel (3.0.5)
27
- activesupport (= 3.0.5)
26
+ activemodel (3.0.7)
27
+ activesupport (= 3.0.7)
28
28
  builder (~> 2.1.2)
29
- i18n (~> 0.4)
30
- activerecord (3.0.5)
31
- activemodel (= 3.0.5)
32
- activesupport (= 3.0.5)
29
+ i18n (~> 0.5.0)
30
+ activerecord (3.0.7)
31
+ activemodel (= 3.0.7)
32
+ activesupport (= 3.0.7)
33
33
  arel (~> 2.0.2)
34
34
  tzinfo (~> 0.3.23)
35
- activeresource (3.0.5)
36
- activemodel (= 3.0.5)
37
- activesupport (= 3.0.5)
38
- activesupport (3.0.5)
35
+ activeresource (3.0.7)
36
+ activemodel (= 3.0.7)
37
+ activesupport (= 3.0.7)
38
+ activesupport (3.0.7)
39
39
  arel (2.0.9)
40
40
  builder (2.1.2)
41
41
  capybara (0.4.1.2)
@@ -47,22 +47,21 @@ GEM
47
47
  rack-test (>= 0.5.4)
48
48
  selenium-webdriver (>= 0.0.27)
49
49
  xpath (~> 0.1.3)
50
- celerity (0.8.8)
51
- childprocess (0.1.7)
52
- ffi (~> 0.6.3)
50
+ celerity (0.8.9)
51
+ childprocess (0.1.9)
52
+ ffi (~> 1.0.6)
53
53
  culerity (0.2.15)
54
54
  erubis (2.6.6)
55
55
  abstract (>= 1.0.0)
56
- ffi (0.6.3)
57
- rake (>= 0.8.7)
56
+ ffi (1.0.8)
58
57
  i18n (0.5.0)
59
58
  json_pure (1.5.1)
60
- mail (2.2.15)
59
+ mail (2.2.19)
61
60
  activesupport (>= 2.3.6)
62
61
  i18n (>= 0.4.0)
63
62
  mime-types (~> 1.16)
64
63
  treetop (~> 1.4.8)
65
- meta_search (1.0.1)
64
+ meta_search (1.0.5)
66
65
  actionpack (~> 3.0.2)
67
66
  activerecord (~> 3.0.2)
68
67
  activesupport (~> 3.0.2)
@@ -70,29 +69,29 @@ GEM
70
69
  mime-types (1.16)
71
70
  nokogiri (1.4.4)
72
71
  polyglot (0.3.1)
73
- rack (1.2.1)
74
- rack-mount (0.6.13)
72
+ rack (1.2.2)
73
+ rack-mount (0.6.14)
75
74
  rack (>= 1.0.0)
76
75
  rack-test (0.5.7)
77
76
  rack (>= 1.0)
78
- rails (3.0.5)
79
- actionmailer (= 3.0.5)
80
- actionpack (= 3.0.5)
81
- activerecord (= 3.0.5)
82
- activeresource (= 3.0.5)
83
- activesupport (= 3.0.5)
77
+ rails (3.0.7)
78
+ actionmailer (= 3.0.7)
79
+ actionpack (= 3.0.7)
80
+ activerecord (= 3.0.7)
81
+ activeresource (= 3.0.7)
82
+ activesupport (= 3.0.7)
84
83
  bundler (~> 1.0)
85
- railties (= 3.0.5)
86
- railties (3.0.5)
87
- actionpack (= 3.0.5)
88
- activesupport (= 3.0.5)
84
+ railties (= 3.0.7)
85
+ railties (3.0.7)
86
+ actionpack (= 3.0.7)
87
+ activesupport (= 3.0.7)
89
88
  rake (>= 0.8.7)
90
89
  thor (~> 0.14.4)
91
90
  rake (0.8.7)
92
91
  rubyzip (0.9.4)
93
- selenium-webdriver (0.1.3)
94
- childprocess (~> 0.1.5)
95
- ffi (~> 0.6.3)
92
+ selenium-webdriver (0.2.0)
93
+ childprocess (>= 0.1.7)
94
+ ffi (>= 1.0.7)
96
95
  json_pure
97
96
  rubyzip
98
97
  shoulda (2.11.3)
@@ -102,9 +101,9 @@ GEM
102
101
  thor (0.14.6)
103
102
  treetop (1.4.9)
104
103
  polyglot (>= 0.3.1)
105
- tzinfo (0.3.25)
104
+ tzinfo (0.3.27)
106
105
  will_paginate (2.3.15)
107
- xpath (0.1.3)
106
+ xpath (0.1.4)
108
107
  nokogiri (~> 1.3)
109
108
 
110
109
  PLATFORMS
data/README.md CHANGED
@@ -45,7 +45,7 @@ Here's what lines #45-59 in `lib/crudify/class_methods.rb` will produce in our J
45
45
  :position => ((Jelly.maximum(:position, :conditions => "")||-1) + 1)
46
46
  })
47
47
  end
48
- @instance = @jelly = Jelly.create(params[:jelly])
48
+ @instance = @jelly = Jelly.new(params[:jelly])
49
49
  before_create
50
50
  if @instance.valid? && @instance.save
51
51
  successful_create
@@ -102,9 +102,9 @@ Or an after-action hook:
102
102
 
103
103
  ### To find out more about crudify, read the source! Here's some helpful links:
104
104
 
105
- * For available options: [Crudify::Base](https://github.com/citrus/crudify/blob/master/lib/crudify/base.rb)
106
- * For available hooks: [Crudify::HookMethods](https://github.com/citrus/crudify/blob/master/lib/crudify/hook_methods.rb)
107
- * To see which hooks go where: [Cruidfy::ClassMethods](https://github.com/citrus/crudify/blob/master/lib/crudify/class_methods.rb)
105
+ * For available **options**: [Crudify::Base](https://github.com/citrus/crudify/blob/master/lib/crudify/base.rb)
106
+ * For available **hooks**: [Crudify::HookMethods](https://github.com/citrus/crudify/blob/master/lib/crudify/hook_methods.rb)
107
+ * To see **which hooks go where**: [Cruidfy::ClassMethods](https://github.com/citrus/crudify/blob/master/lib/crudify/class_methods.rb)
108
108
 
109
109
  Or check out the demo app in `test/dummy`...
110
110
 
@@ -123,7 +123,10 @@ Shoulda and Capybara/Selenium tests can be run by cloning the repo and running `
123
123
  To Do
124
124
  -----
125
125
 
126
- * Documentation & Examples
126
+ There's a few things to be done still...
127
+
128
+ * Tests for search
129
+ * More Documentation & Examples
127
130
  * Nested set tests and demo (haven't even tried this yet :/)
128
131
  * Generally more thorough tests
129
132
  * Refactoring/Optimizing
@@ -132,7 +135,7 @@ To Do
132
135
  License
133
136
  -------
134
137
 
135
- Crudify is released under [Resolve Digital](http://www.resolvedigital.com)'s original license since portions of the code was extracted from [refinerycms](http://github.com/resolve/refinerycms).
138
+ Although many things have been rewritten, crudify is released under [Resolve Digital's](http://www.resolvedigital.com) original license since portions code were extracted from their [refinerycms](http://github.com/resolve/refinerycms) project.
136
139
 
137
140
  ### MIT License
138
141
 
@@ -3,6 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
  require "crudify/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
+
6
7
  s.name = "crudify"
7
8
  s.version = Crudify::VERSION
8
9
  s.platform = Gem::Platform::RUBY
@@ -5,11 +5,13 @@
5
5
  # the splendid fellows at Resolve Digital for their
6
6
  # awesome refinerycms project.
7
7
  #
8
+
8
9
  module Crudify
9
10
 
10
11
  module ClassMethods
11
12
 
12
13
  def crudify(model_name, options = {})
14
+
13
15
  options = ::Crudify::Base.default_options(model_name).merge(options)
14
16
 
15
17
  singular_name = model_name.to_s
@@ -28,7 +30,7 @@ module Crudify
28
30
  prepend_before_filter :set_crud_options
29
31
 
30
32
  def set_crud_options
31
- @crud_options = #{options}
33
+ @crud_options = #{options.inspect}
32
34
  end
33
35
 
34
36
  def set_what
@@ -56,8 +58,9 @@ module Crudify
56
58
  :position => ((#{class_name}.maximum(:position, :conditions => #{options[:conditions].inspect})||-1) + 1)
57
59
  })
58
60
  end
59
- @instance = @#{singular_name} = #{class_name}.create(params[:#{singular_name}])
60
- before_create
61
+ @instance = @#{singular_name} = #{class_name}.new(params[:#{singular_name}])
62
+ ok = before_create
63
+ return ok unless ok === true
61
64
  if @instance.valid? && @instance.save
62
65
  successful_create
63
66
  else
@@ -70,7 +73,8 @@ module Crudify
70
73
  end
71
74
 
72
75
  def update
73
- before_update
76
+ ok = before_update
77
+ return ok unless ok === true
74
78
  if @#{singular_name}.update_attributes(params[:#{singular_name}])
75
79
  successful_update
76
80
  else
@@ -79,8 +83,9 @@ module Crudify
79
83
  end
80
84
 
81
85
  def destroy
82
- before_destroy
83
86
  set_what
87
+ ok = before_destroy
88
+ return ok unless ok === true
84
89
  # object gets found by find_#{singular_name} function
85
90
  if @#{singular_name}.destroy
86
91
  successful_destroy
@@ -103,9 +108,8 @@ module Crudify
103
108
  def scope_with_options(scope)
104
109
  scope.includes(
105
110
  #{options[:include].map(&:to_sym).inspect}
106
- ).order("#{options[:order]}")
111
+ )
107
112
  end
108
-
109
113
 
110
114
  # Finds one single result based on the id params.
111
115
  def find_#{singular_name}
@@ -131,7 +135,7 @@ module Crudify
131
135
 
132
136
  # Seems will_paginate doesn't always use the implicit method.
133
137
  if #{class_name}.methods.map(&:to_sym).include?(:per_page)
134
- paginate_options.update({:per_page => #{class_name}.per_page})
138
+ paginate_options.update(:per_page => #{class_name}.per_page)
135
139
  end
136
140
 
137
141
  set_collection(@#{plural_name}.paginate(paginate_options), false)
@@ -139,6 +143,8 @@ module Crudify
139
143
 
140
144
  # Returns results based on the query specified by the user.
141
145
  def search_all_#{plural_name}
146
+ params[:search] ||= {}
147
+ params[:search][:meta_sort] ||= #{options[:order].to_s.downcase.gsub(' ', '.').inspect}
142
148
  @search ||= find_all_#{plural_name}.search(params[:search])
143
149
  set_collection(@search, false)
144
150
  end
@@ -25,7 +25,7 @@ module Crudify
25
25
  def before_action
26
26
  # just a hook!
27
27
  puts "> Crud::before_action" if @crud_options[:log]
28
- #true
28
+ true
29
29
  end
30
30
 
31
31
 
@@ -61,10 +61,12 @@ module Crudify
61
61
  redirect_to @redirect_to_url
62
62
  elsif params[:commit].to_s.match(/continue/)
63
63
  if params[:action] == 'create'
64
- redirect_to request.referer.sub(/(\/?(new)?\/?)$/, '') + "/#{@instance.to_param}"
64
+ url = request.referer.sub(/(\/?(new)?\/?)$/, '') + "/#{@instance.to_param}"
65
+ url += "/edit" if params[:commit].to_s.match(/edit/)
65
66
  else
66
- redirect_to request.referer
67
- end
67
+ url = request.referer
68
+ end
69
+ redirect_to url
68
70
  else
69
71
  url = eval(@crud_options[:redirect_to_url])
70
72
  if defined?(redirect_back_or_default)
@@ -1,3 +1,3 @@
1
1
  module Crudify
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -0,0 +1,150 @@
1
+ require 'helper'
2
+
3
+ module HookAssertions
4
+
5
+ # We'll store things we want to assert here for now,
6
+ # then run the assertions at teardown
7
+ #
8
+ # assertions << [ :assert, true, "True is true!" ]
9
+ # assertions << [ :assert_not_nil, 1, "1 is not nil" ]
10
+ #
11
+ def assertions
12
+ @assertions ||= []
13
+ end
14
+
15
+
16
+ private
17
+
18
+ def before_create
19
+ assertions << [ :assert_not_nil, @jelly, "Jelly should be assigned" ]
20
+ assertions << [ :assert, @jelly.new_record?, "Jelly should be a new record" ]
21
+ super
22
+ end
23
+
24
+ def before_update
25
+ assertions << [ :assert_not_nil, @jelly, "Jelly should be assigned" ]
26
+ assertions << [ :assert, !@jelly.new_record?, "Jelly should not be a new record" ]
27
+ super
28
+ end
29
+
30
+ ## not sure what to check for here...
31
+ #def before_action
32
+ # assertions << [ :assert, true ]
33
+ # super
34
+ #end
35
+
36
+ def successful_create
37
+ assertions << [ :assert, !@jelly.new_record?, "Jelly should not be a new record" ]
38
+ super
39
+ end
40
+
41
+ def successful_update
42
+ assertions << [ :assert_equal, @jelly.name, "Controlafresh" ]
43
+ assertions << [ :assert, !@jelly.changed?, "Should be clean" ]
44
+ super
45
+ end
46
+
47
+ def successful_destroy
48
+ @old_jelly = Jelly.find(@jelly.id) rescue nil
49
+ assertions << [ :assert, @old_jelly.nil? ]
50
+ super
51
+ end
52
+
53
+ def after_success
54
+ assertions << [ :assert_not_nil, flash[:notice], "Should have a notice" ]
55
+ assertions << [ :assert, flash[:error].nil?, "Should not have an error message" ]
56
+ super
57
+ end
58
+
59
+ def failed_create
60
+ assertions << [ :assert, !@jelly.errors.empty?, "Jelly has errors" ]
61
+ super
62
+ end
63
+
64
+ def failed_update
65
+ assertions << [ :assert, @jelly.changed?, "Jelly has unsaved updates" ]
66
+ super
67
+ end
68
+
69
+ def failed_destroy
70
+ @old_jelly = Jelly.find(@jelly.id) rescue nil
71
+ assertions << [ :assert_not_nil, @old_jelly ]
72
+ super
73
+ end
74
+
75
+ def after_fail
76
+ assertions << [ :assert_not_nil, flash[:error].nil?, "Should have an error message" ]
77
+ assertions << [ :assert, flash[:notice].nil?, "Should not have a notice" ]
78
+ super
79
+ end
80
+
81
+ end
82
+
83
+
84
+ class ControllerHooksTest < ActionController::TestCase
85
+
86
+ def setup
87
+ # assertions will be created in the included module
88
+ JelliesController.send(:include, HookAssertions)
89
+ @controller = JelliesController.new
90
+ end
91
+
92
+ def teardown
93
+ # fire any assertions we saved in the controller
94
+ @controller.assertions.each do |args|
95
+ send(*args)
96
+ end
97
+ end
98
+
99
+ should "post to create" do
100
+ post :create, :jelly => { :title => "Controller Jelly", :name => "Controlaberry" }
101
+ end
102
+
103
+ should "post to create and fail" do
104
+ post :create, :jelly => { :title => "", :name => "" }
105
+ end
106
+
107
+ context "with a jelly" do
108
+
109
+ setup do
110
+ @jelly = Jelly.create(:title => "Controller Jelly", :name => "Controlaberry")
111
+ end
112
+
113
+ should "put update" do
114
+ put :update, :id => @jelly.id, :jelly => { :title => "Updated Controller Jelly", :name => "Controlafresh" }
115
+ end
116
+
117
+ should "put update and fail" do
118
+ put :update, :id => @jelly.id, :jelly => { :title => "", :name => "" }
119
+ end
120
+
121
+ should "delete, destroy and maybe conquer" do
122
+ delete :destroy, :id => @jelly.id
123
+ end
124
+
125
+ should "delete but not destroy" do
126
+ # overwrite the default destroy method..
127
+ # is there a better way to do this?
128
+ Jelly.class_eval do
129
+
130
+ alias :aliased_destroy :destroy
131
+
132
+ def destroy
133
+ false
134
+ end
135
+ end
136
+
137
+ delete :destroy, :id => @jelly.id
138
+
139
+ # rewrite to the old method
140
+ Jelly.class_eval do
141
+ def destroy
142
+ aliased_destroy
143
+ end
144
+ end
145
+
146
+ end
147
+
148
+ end
149
+
150
+ end
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crudify
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.5
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 6
9
+ version: 0.0.6
6
10
  platform: ruby
7
11
  authors:
8
12
  - Spencer Steffen
@@ -10,7 +14,7 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-03-16 00:00:00 -07:00
17
+ date: 2011-05-14 00:00:00 -07:00
14
18
  default_executable:
15
19
  dependencies:
16
20
  - !ruby/object:Gem::Dependency
@@ -21,6 +25,10 @@ dependencies:
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 0
24
32
  version: 3.0.0
25
33
  type: :runtime
26
34
  version_requirements: *id001
@@ -32,6 +40,10 @@ dependencies:
32
40
  requirements:
33
41
  - - ">="
34
42
  - !ruby/object:Gem::Version
43
+ segments:
44
+ - 2
45
+ - 3
46
+ - 15
35
47
  version: 2.3.15
36
48
  type: :runtime
37
49
  version_requirements: *id002
@@ -43,6 +55,10 @@ dependencies:
43
55
  requirements:
44
56
  - - ">="
45
57
  - !ruby/object:Gem::Version
58
+ segments:
59
+ - 1
60
+ - 0
61
+ - 1
46
62
  version: 1.0.1
47
63
  type: :runtime
48
64
  version_requirements: *id003
@@ -54,6 +70,10 @@ dependencies:
54
70
  requirements:
55
71
  - - ">="
56
72
  - !ruby/object:Gem::Version
73
+ segments:
74
+ - 2
75
+ - 11
76
+ - 3
57
77
  version: 2.11.3
58
78
  type: :development
59
79
  version_requirements: *id004
@@ -65,6 +85,10 @@ dependencies:
65
85
  requirements:
66
86
  - - ">="
67
87
  - !ruby/object:Gem::Version
88
+ segments:
89
+ - 1
90
+ - 3
91
+ - 3
68
92
  version: 1.3.3
69
93
  type: :development
70
94
  version_requirements: *id005
@@ -76,6 +100,10 @@ dependencies:
76
100
  requirements:
77
101
  - - ">="
78
102
  - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ - 4
106
+ - 1
79
107
  version: 0.4.1
80
108
  type: :development
81
109
  version_requirements: *id006
@@ -87,6 +115,10 @@ dependencies:
87
115
  requirements:
88
116
  - - ">="
89
117
  - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ - 1
121
+ - 3
90
122
  version: 0.1.3
91
123
  type: :development
92
124
  version_requirements: *id007
@@ -163,6 +195,7 @@ files:
163
195
  - test/dummy/public/javascripts/rails.js
164
196
  - test/dummy/public/stylesheets/styles.css
165
197
  - test/dummy/script/rails
198
+ - test/functional/controller_hooks_test.rb
166
199
  - test/functional/jellies_controller_test.rb
167
200
  - test/helper.rb
168
201
  - test/integration/demo_test.rb
@@ -181,17 +214,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
214
  requirements:
182
215
  - - ">="
183
216
  - !ruby/object:Gem::Version
217
+ segments:
218
+ - 0
184
219
  version: "0"
185
220
  required_rubygems_version: !ruby/object:Gem::Requirement
186
221
  none: false
187
222
  requirements:
188
223
  - - ">="
189
224
  - !ruby/object:Gem::Version
225
+ segments:
226
+ - 0
190
227
  version: "0"
191
228
  requirements: []
192
229
 
193
230
  rubyforge_project:
194
- rubygems_version: 1.6.2
231
+ rubygems_version: 1.3.7
195
232
  signing_key:
196
233
  specification_version: 3
197
234
  summary: Crudify is a dynamic resource controller for Rails 3.
@@ -246,6 +283,7 @@ test_files:
246
283
  - test/dummy/public/javascripts/rails.js
247
284
  - test/dummy/public/stylesheets/styles.css
248
285
  - test/dummy/script/rails
286
+ - test/functional/controller_hooks_test.rb
249
287
  - test/functional/jellies_controller_test.rb
250
288
  - test/helper.rb
251
289
  - test/integration/demo_test.rb