fesplugas-typus 0.9.5 → 0.9.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/README.rdoc CHANGED
@@ -70,9 +70,10 @@ Typus and blog about Typus.
70
70
  - Anthony Underwood (Code) http://github.com/aunderwo
71
71
  - Felipe Talavera (Code) http://github.com/flype
72
72
  - Erik Tigerholm (Code) http://github.com/eriktigerholm
73
- - George Guimarães (Translation pt-br and code) http://github.com/georgeguimaraes
73
+ - George Guimarães (Portuguese translation and code) http://github.com/georgeguimaraes
74
74
  - José Valim (Code) http://github.com/josevalim
75
75
  - Luqman Amjad (Code) http://github.com/snake
76
+ - Alexey Noskov (Russian translation and code) http://github.com/alno
76
77
 
77
78
  == Acknowledgments
78
79
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.5
1
+ 0.9.6
@@ -47,6 +47,8 @@ class Admin::MasterController < ApplicationController
47
47
 
48
48
  @conditions, @joins = @resource[:class].build_conditions(params)
49
49
 
50
+ check_ownership_of_items if @resource[:class].typus_options_for(:only_user_items)
51
+
50
52
  respond_to do |format|
51
53
  format.html { generate_html }
52
54
  @resource[:class].typus_export_formats.each do |f|
@@ -256,6 +258,21 @@ private
256
258
 
257
259
  end
258
260
 
261
+ def check_ownership_of_items
262
+
263
+ # If current_user is a root user, by-pass.
264
+ return if @current_user.is_root?
265
+
266
+ # If current user is not root and @resource has a foreign_key which
267
+ # is related to the logged user (Typus.user_fk) we only show the user
268
+ # related items.
269
+ if @resource[:class].columns.map { |u| u.name }.include?(Typus.user_fk)
270
+ condition = { Typus.user_fk => @current_user }
271
+ @conditions = @resource[:class].merge_conditions(@conditions, condition)
272
+ end
273
+
274
+ end
275
+
259
276
  def set_fields
260
277
  @fields = case params[:action]
261
278
  when 'index'
@@ -68,9 +68,10 @@ module Admin::FormHelper
68
68
  end
69
69
 
70
70
  def typus_boolean_field(attribute, klass = @resource[:class])
71
+ attribute_name = attribute.gsub(/\?$/,'')
71
72
  <<-HTML
72
- <li><label for="item_#{attribute}">#{klass.human_attribute_name(attribute)}</label>
73
- #{check_box :item, attribute} #{_('Checked if active')}</li>
73
+ <li><label for="item_#{attribute_name}">#{klass.human_attribute_name(attribute)}</label>
74
+ #{check_box :item, attribute_name} #{_('Checked if active')}</li>
74
75
  HTML
75
76
  end
76
77
 
@@ -210,7 +210,7 @@ module Admin::TableHelper
210
210
  item.class.typus_options_for(:nil) # Content is nil, so we show nil.
211
211
  end
212
212
 
213
- options = { :controller => item.class.name.tableize, :action => 'toggle', :field => attribute, :id => item.id }
213
+ options = { :controller => item.class.name.tableize, :action => 'toggle', :field => attribute.gsub(/\?$/,''), :id => item.id }
214
214
 
215
215
  content = if item.class.typus_options_for(:toggle) && !item.send(attribute).nil?
216
216
  link_to link_text, params.merge(options), :confirm => _("Change {{attribute}}?", :attribute => item.class.human_attribute_name(attribute).downcase)
@@ -90,7 +90,7 @@ module TypusHelper
90
90
  options = args.extract_options!
91
91
  template = [ 'admin', options[:resource], options[:location], "_#{options[:partial]}.html.erb" ].compact.join('/')
92
92
 
93
- exists = ActionController::Base.view_paths.map { |vp| File.exists?("#{vp}/#{template}") }
93
+ exists = ActionController::Base.view_paths.map { |vp| File.exists?("#{Rails.root}/#{vp}/#{template}") }
94
94
 
95
95
  return unless exists.include?(true)
96
96
  render :partial => template.gsub('/_', '/')
@@ -9,6 +9,11 @@ es:
9
9
  typus_user: "Typus user"
10
10
 
11
11
  pt-BR:
12
+ activerecord:
13
+ models:
14
+ typus_user: "Typus user"
15
+
16
+ ru:
12
17
  activerecord:
13
18
  models:
14
19
  typus_user: "Typus user"
@@ -15,12 +15,14 @@ Typus::Configuration.options[:app_name] = '<%= application %>'
15
15
 
16
16
  # Model options which can also be defined by model on the yaml files.
17
17
 
18
- # Typus::Configuration.options[:index_after_save] = true
18
+ # Typus::Configuration.options[:default_action_on_item] = 'edit'
19
19
  # Typus::Configuration.options[:end_year] = Time.now.year + 1
20
20
  # Typus::Configuration.options[:form_rows] = 10
21
21
  # Typus::Configuration.options[:icon_on_boolean] = false
22
+ # Typus::Configuration.options[:index_after_save] = true
22
23
  # Typus::Configuration.options[:minute_step] = 5
23
24
  # Typus::Configuration.options[:nil] = 'nil'
25
+ # Typus::Configuration.options[:only_user_items] = false
24
26
  # Typus::Configuration.options[:per_page] = 15
25
27
  # Typus::Configuration.options[:sidebar_selector] = 5
26
28
  # Typus::Configuration.options[:start_year] = Time.now.year - 10
@@ -35,6 +35,7 @@
35
35
  # index_after_save: false
36
36
  # minute_step: 15
37
37
  # nil: 'nil'
38
+ # only_user_items: false
38
39
  # per_page: 5
39
40
  # sidebar_selector: 5
40
41
  # start_year: 1990
@@ -67,7 +67,7 @@ class TypusGenerator < Rails::Generator::Base
67
67
  model.reflect_on_all_associations(relationship).map { |i| i.name.to_s }
68
68
  end.flatten.sort
69
69
 
70
- configuration[:base] << <<-CODE
70
+ configuration[:base] << <<-RAW
71
71
  #{model}:
72
72
  fields:
73
73
  list: #{list.join(', ')}
@@ -89,15 +89,15 @@ class TypusGenerator < Rails::Generator::Base
89
89
  application: #{application}
90
90
  description:
91
91
 
92
- CODE
92
+ RAW
93
93
 
94
- configuration[:roles] << <<-CODE
94
+ configuration[:roles] << <<-RAW
95
95
  #{model}: create, read, update, delete
96
- CODE
96
+ RAW
97
97
 
98
98
  end
99
99
 
100
- Dir["#{Typus.root}/generators/typus/templates/config/typus/*"].each do |f|
100
+ Dir["#{Typus.path}/generators/typus/templates/config/typus/*"].each do |f|
101
101
  base = File.basename(f)
102
102
  m.template "config/typus/#{base}", "#{config_folder}/#{base}",
103
103
  :assigns => { :configuration => configuration }
@@ -124,7 +124,7 @@ class TypusGenerator < Rails::Generator::Base
124
124
  m.file 'public/stylesheets/admin/reset.css', 'public/stylesheets/admin/reset.css'
125
125
  m.file 'public/javascripts/admin/application.js', 'public/javascripts/admin/application.js'
126
126
 
127
- Dir["#{Typus.root}/generators/typus/templates/public/images/admin/*"].each do |f|
127
+ Dir["#{Typus.path}/generators/typus/templates/public/images/admin/*"].each do |f|
128
128
  base = File.basename(f)
129
129
  m.file "public/images/admin/#{base}", "public/images/admin/#{base}"
130
130
  end
@@ -5,7 +5,7 @@ class TypusUpdateSchemaTo01Generator < Rails::Generator::Base
5
5
  record do |m|
6
6
 
7
7
  config_folder = Typus::Configuration.options[:config_folder]
8
- Dir["#{Typus.root}/generators/typus_update_schema_to_01/templates/config/*"].each do |f|
8
+ Dir["#{Typus.path}/generators/typus_update_schema_to_01/templates/config/*"].each do |f|
9
9
  base = File.basename(f)
10
10
  m.template "config/#{base}", "#{config_folder}/#{base}"
11
11
  end
@@ -49,7 +49,6 @@ module Typus
49
49
  when /file_name/: attribute_type = :file
50
50
  when /password/: attribute_type = :password
51
51
  when 'position': attribute_type = :position
52
- when /\?/: attribute_type = :boolean
53
52
  end
54
53
 
55
54
  if reflect_on_association(field)
@@ -185,9 +184,9 @@ module Typus
185
184
  # We are able to define how to display dates on Typus
186
185
  #
187
186
  def typus_date_format(attribute = :default)
188
- date_format = Typus::Configuration.config[name]['fields']['options']['date_formats'][attribute.to_s] rescue nil
187
+ date_format = Typus::Configuration.config[name]['fields']['options']['date_formats'][attribute.to_s].to_sym rescue nil
189
188
  date_format = :db if date_format.nil?
190
- return date_format.to_sym
189
+ return date_format
191
190
  end
192
191
 
193
192
  ##
@@ -246,7 +245,7 @@ module Typus
246
245
  condition = { key => value }
247
246
  conditions = merge_conditions(conditions, condition)
248
247
  when :has_and_belongs_to_many
249
- condition = { key => { :id => value } }
248
+ condition = { key => { :id => value } }
250
249
  conditions = merge_conditions(conditions, condition)
251
250
  joins << key.to_sym
252
251
  end
@@ -3,7 +3,18 @@ module Typus
3
3
  module Configuration
4
4
 
5
5
  ##
6
- # Default Typus options which can be overwritten from the initializer.
6
+ # Default Typus options which can be overwritten from the
7
+ # initializer. Example:
8
+ #
9
+ # Typus::Configuration.options[:recover_password]
10
+ #
11
+ # Special cases:
12
+ #
13
+ # Typus::Configuration.options[:user_fk]
14
+ # Typus.user_fk
15
+ #
16
+ # Typus::Configuration.options[:user_class_name]
17
+ # Typus.user_class
7
18
  #
8
19
  typus_options = { :app_name => 'Typus',
9
20
  :config_folder => 'config/typus',
@@ -17,7 +28,10 @@ module Typus
17
28
  :user_fk => 'typus_user_id' }
18
29
 
19
30
  ##
20
- # Default model options which can be overwritten from the initializer.
31
+ # Default model options which can be overwritten from the
32
+ # initializer. Example:
33
+ #
34
+ # Model.typus_options_for(:default_action_on_item)
21
35
  #
22
36
  model_options = { :default_action_on_item => 'edit',
23
37
  :end_year => nil,
@@ -26,6 +40,7 @@ module Typus
26
40
  :index_after_save => false,
27
41
  :minute_step => 5,
28
42
  :nil => 'nil',
43
+ :only_user_items => false,
29
44
  :per_page => 15,
30
45
  :sidebar_selector => 5,
31
46
  :start_year => nil,
@@ -9,7 +9,7 @@ module Typus
9
9
  Dir.mkdir(admin_controllers_folder) unless File.directory?(admin_controllers_folder)
10
10
 
11
11
  # Get a list of all available app/controllers/admin
12
- admin_controllers = Dir["#{Rails.root}/vendor/plugins/*/app/controllers/admin/*.rb", "#{Rails.root}/app/controllers/admin/*.rb"]
12
+ admin_controllers = Dir["#{Rails.root}/vendor/plugins/*/app/controllers/admin/*.rb", "#{admin_controllers_folder}/*.rb"]
13
13
  admin_controllers = admin_controllers.map { |i| File.basename(i) }
14
14
 
15
15
  # Create app/views/admin if doesn't exist.
@@ -17,13 +17,13 @@ module Typus
17
17
  Dir.mkdir(admin_views_folder) unless File.directory?(admin_views_folder)
18
18
 
19
19
  # Create test/functional/admin if doesn't exist.
20
+ admin_controller_tests_folder = "#{Rails.root}/test/functional/admin"
20
21
  if File.directory?("#{Rails.root}/test")
21
- admin_controller_tests_folder = "#{Rails.root}/test/functional/admin"
22
22
  Dir.mkdir(admin_controller_tests_folder) unless File.directory?(admin_controller_tests_folder)
23
23
  end
24
24
 
25
25
  # Get a list of all available functional test for admin.
26
- admin_controller_tests = Dir["#{Rails.root}/vendor/plugins/*/test/functional/admin/*.rb", "#{Rails.root}/test/functional/admin/*.rb"]
26
+ admin_controller_tests = Dir["#{Rails.root}/vendor/plugins/*/test/functional/admin/*.rb", "#{admin_controller_tests_folder}/*.rb"]
27
27
  admin_controller_tests = admin_controller_tests.map { |i| File.basename(i) }
28
28
 
29
29
  # Generate unexisting controllers for resources which are not tied to
data/lib/typus.rb CHANGED
@@ -3,10 +3,10 @@ module Typus
3
3
  class << self
4
4
 
5
5
  def version
6
- @@version ||= File.read("#{root}/VERSION").strip
6
+ @@version ||= File.read("#{path}/VERSION").strip
7
7
  end
8
8
 
9
- def root
9
+ def path
10
10
  File.dirname(__FILE__) + '/../'
11
11
  end
12
12
 
data/rails/init.rb CHANGED
@@ -1,14 +1,11 @@
1
1
  require 'typus'
2
- require 'sha1'
3
2
 
4
3
  if Typus.testing?
5
4
  Typus::Configuration.options[:config_folder] = 'vendor/plugins/typus/test/config/working'
6
5
  end
7
6
 
8
7
  ##
9
- # Typus.enable and run the generator unless we are testing the plugin.
10
- # Do not Typus.enable or generate files if we are running a rails
11
- # generator.
8
+ # Do not Typus.enable or Typus.generate if we are running a generator.
12
9
  #
13
10
 
14
11
  scripts = %w( script/generate script/destroy )
@@ -105,13 +105,13 @@ class Admin::CommentsControllerTest < ActionController::TestCase
105
105
 
106
106
  def test_should_generate_csv
107
107
 
108
- expected = <<-CSV
108
+ expected = <<-RAW
109
109
  Email,Post
110
110
  john@example.com,1
111
111
  me@example.com,1
112
112
  john@example.com,
113
113
  me@example.com,1
114
- CSV
114
+ RAW
115
115
 
116
116
  get :index, :format => 'csv'
117
117
  assert_equal expected, @response.body
@@ -215,25 +215,6 @@ class Admin::PostsControllerTest < ActionController::TestCase
215
215
  assert_match /datepicker_template_published_at/, @response.body
216
216
  end
217
217
 
218
- =begin
219
-
220
- # FIXME
221
-
222
- def test_should_add_back_to_params_for_comment_items
223
-
224
- post_ = posts(:published)
225
- get :edit, { :id => post_.id }
226
- assert_response :success
227
- back_to = "/posts/#{post_.id}/edit"
228
- re = /<a href="\/typus\/assets\/1\/edit(.*)">This is the caption\.<\/a>/
229
- params = re.match(@response.body)
230
-
231
- assert_equal params[1], "?back_to=%2Ftypus%2Fposts%2F1%2Fedit&amp;resource=posts&amp;resource_id=#{post_.id}"
232
-
233
- end
234
-
235
- =end
236
-
237
218
  def test_should_verify_root_can_edit_any_record
238
219
  Post.find(:all).each do |post|
239
220
  get :edit, { :id => post.id }
data/test/helper.rb CHANGED
@@ -3,6 +3,12 @@ ENV['RAILS_ENV'] = 'test'
3
3
  require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
4
4
  require 'test_help'
5
5
  require 'mocha'
6
+ require 'time'
7
+
8
+ def Time.today
9
+ t = now()
10
+ mktime( t.year, t.mon, t.day )
11
+ end unless Time.respond_to?(:today)
6
12
 
7
13
  begin
8
14
  require 'redgreen'
@@ -69,9 +69,16 @@ class Admin::SidebarHelperTest < ActiveSupport::TestCase
69
69
  self.expects(:params).at_least_once.returns(params)
70
70
 
71
71
  output = export
72
- expected = ["<a href=\"http://test.host/admin/custom_users.csv\">CSV</a>"]
73
72
 
74
- assert_equal expected, output
73
+ # FIXME or OPTIMIZE
74
+
75
+ begin
76
+ expected = ["<a href=\"http://test.host/admin/custom_users.csv\">CSV</a>"]
77
+ assert_equal expected, output
78
+ rescue
79
+ expected = ["<a href=\"http://test.host/admin/custom_users?format=csv\">CSV</a>"]
80
+ assert_equal expected, output
81
+ end
75
82
 
76
83
  end
77
84
 
@@ -185,22 +185,6 @@ class Admin::TableHelperTest < ActiveSupport::TestCase
185
185
 
186
186
  end
187
187
 
188
- =begin
189
-
190
- # FIXME
191
-
192
- def test_typus_table_position_field
193
-
194
- category = categories(:first)
195
- output = typus_table_position_field('position', category)
196
- expected = ""
197
-
198
- assert_equal expected, output
199
-
200
- end
201
-
202
- =end
203
-
204
188
  def test_typus_table_datetime_field
205
189
 
206
190
  post = posts(:published)
@@ -235,7 +219,7 @@ class Admin::TableHelperTest < ActiveSupport::TestCase
235
219
  Typus::Configuration.stubs(:options).returns(options)
236
220
 
237
221
  post = posts(:published)
238
- output = typus_table_boolean_field(:status, post)
222
+ output = typus_table_boolean_field('status', post)
239
223
  expected = <<-HTML
240
224
  <td align="center">True</td>
241
225
  HTML
@@ -243,7 +227,7 @@ class Admin::TableHelperTest < ActiveSupport::TestCase
243
227
  assert_equal expected, output
244
228
 
245
229
  post = posts(:unpublished)
246
- output = typus_table_boolean_field(:status, post)
230
+ output = typus_table_boolean_field('status', post)
247
231
  expected = <<-HTML
248
232
  <td align="center">False</td>
249
233
  HTML
@@ -24,12 +24,14 @@ class ConfigurationTest < ActiveSupport::TestCase
24
24
  def test_should_verify_model_configuration_options
25
25
  initializer = "#{Rails.root}/config/initializers/typus.rb"
26
26
  return if File.exists?(initializer)
27
+ assert_equal 'edit', Typus::Configuration.options[:default_action_on_item]
27
28
  assert_equal nil, Typus::Configuration.options[:end_year]
28
29
  assert_equal 10, Typus::Configuration.options[:form_rows]
29
30
  assert_equal true, Typus::Configuration.options[:icon_on_boolean]
30
31
  assert_equal false, Typus::Configuration.options[:index_after_save]
31
32
  assert_equal 5, Typus::Configuration.options[:minute_step]
32
33
  assert_equal 'nil', Typus::Configuration.options[:nil]
34
+ assert_equal false, Typus::Configuration.options[:only_user_items]
33
35
  assert_equal 15, Typus::Configuration.options[:per_page]
34
36
  assert_equal 5, Typus::Configuration.options[:sidebar_selector]
35
37
  assert_equal nil, Typus::Configuration.options[:start_year]
@@ -64,7 +66,7 @@ class ConfigurationTest < ActiveSupport::TestCase
64
66
  options = { :config_folder => 'vendor/plugins/typus/test/config/ordered' }
65
67
  Typus::Configuration.stubs(:options).returns(options)
66
68
  files = Dir["#{Rails.root}/#{Typus::Configuration.options[:config_folder]}/*_roles.yml"]
67
- expected = files.collect { |file| File.basename(file) }
69
+ expected = files.collect { |file| File.basename(file) }.sort
68
70
  assert_equal expected, ['001_roles.yml', '002_roles.yml']
69
71
  expected = { 'admin' => { 'categories' => 'read' } }
70
72
  assert_equal expected, Typus::Configuration.roles!
@@ -68,15 +68,4 @@ class RoutesTest < ActiveSupport::TestCase
68
68
 
69
69
  end
70
70
 
71
- =begin
72
-
73
- # FIXME
74
-
75
- def test_should_verify_generated_routes_for_resource_controller
76
- assert_routing '/admin/watch_dog', :controller => 'admin/watch_dog', :action => 'index'
77
- assert_routing '/admin/watch_dog/cleanup', { :controller => 'admin/watch_dog', :action => 'cleanup' }
78
- end
79
-
80
- =end
81
-
82
71
  end
@@ -2,6 +2,16 @@ require 'test/helper'
2
2
 
3
3
  class TypusTest < ActiveSupport::TestCase
4
4
 
5
+ def test_should_return_version
6
+ assert Typus.respond_to?(:version)
7
+ assert Typus.version.kind_of?(String)
8
+ end
9
+
10
+ def test_should_return_path
11
+ expected = Dir.pwd + '/lib/../'
12
+ assert_equal expected, Typus.path
13
+ end
14
+
5
15
  def test_should_return_locales
6
16
  initializer = "#{Rails.root}/config/initializers/typus.rb"
7
17
  return if File.exists?(initializer)
@@ -36,17 +46,6 @@ class TypusTest < ActiveSupport::TestCase
36
46
  assert Typus.respond_to?(:parent)
37
47
  end
38
48
 
39
- =begin
40
-
41
- # FIXME
42
-
43
- def test_should_verify_parent_for_module
44
- assert Typus.parent(TypusUser.name, 'module').kind_of?(String)
45
- assert_equal 'Typus', Typus.parent(TypusUser.name, 'module')
46
- end
47
-
48
- =end
49
-
50
49
  def test_should_verify_parent_for_application
51
50
  assert Typus.parent(TypusUser, 'application').kind_of?(String)
52
51
  assert_equal 'Typus', Typus.parent(TypusUser, 'application')
@@ -25,10 +25,10 @@ class TypusUserTest < ActiveSupport::TestCase
25
25
  end
26
26
 
27
27
  def test_should_verify_email_is_not_valid
28
- email = <<-END
28
+ email = <<-RAW
29
29
  this_is_chelm@example.com
30
30
  <script>location.href="http://spammersite.com"</script>
31
- END
31
+ RAW
32
32
  @typus_user.email = email
33
33
  assert @typus_user.invalid?
34
34
  assert @typus_user.errors.invalid?(:email)
@@ -101,17 +101,6 @@ END
101
101
  assert @typus_user.invalid?
102
102
  assert @typus_user.errors.invalid?(:password)
103
103
 
104
- =begin
105
-
106
- # FIXME
107
-
108
- @typus_user.password = '12345678'
109
- @typus_user.password_confirmation = nil
110
- assert @typus_user.invalid?
111
- assert @typus_user.errors.invalid?(:password)
112
-
113
- =end
114
-
115
104
  @typus_user.password = '12345678'
116
105
  @typus_user.password_confirmation = ''
117
106
  assert @typus_user.invalid?
@@ -1,7 +1,5 @@
1
1
  require 'test/helper'
2
2
 
3
- # require 'paginator'
4
-
5
3
  class PaginatorTest < ActiveSupport::TestCase
6
4
 
7
5
  PER_PAGE = 10
data/typus.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{typus}
5
- s.version = "0.9.5"
5
+ s.version = "0.9.6"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Francesc Esplugas"]
9
- s.date = %q{2009-05-25}
9
+ s.date = %q{2009-05-30}
10
10
  s.description = %q{Effortless backend interface for Ruby on Rails applications. (Admin scaffold generator.)}
11
11
  s.email = %q{francesc@intraducibles.com}
12
12
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fesplugas-typus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesc Esplugas
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-25 00:00:00 -07:00
12
+ date: 2009-05-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15