typus 3.0.8 → 3.0.9

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.
Files changed (102) hide show
  1. data/Gemfile +8 -1
  2. data/README.md +2 -2
  3. data/Rakefile +6 -14
  4. data/app/controllers/admin/base_controller.rb +1 -1
  5. data/app/controllers/admin/dashboard_controller.rb +0 -1
  6. data/app/controllers/admin/resources_controller.rb +8 -11
  7. data/app/controllers/admin/session_controller.rb +5 -4
  8. data/app/helpers/admin/base_helper.rb +9 -2
  9. data/app/helpers/admin/dashboard_helper.rb +0 -6
  10. data/app/helpers/admin/display_helper.rb +1 -0
  11. data/app/helpers/admin/file_preview_helper.rb +0 -2
  12. data/app/helpers/admin/filters_helper.rb +6 -3
  13. data/app/helpers/admin/form_helper.rb +2 -4
  14. data/app/helpers/admin/list_helper.rb +1 -3
  15. data/app/helpers/admin/relationships_helper.rb +2 -4
  16. data/app/helpers/admin/resources_helper.rb +0 -2
  17. data/app/helpers/admin/search_helper.rb +0 -2
  18. data/app/helpers/admin/sidebar_helper.rb +0 -2
  19. data/app/helpers/admin/table_helper.rb +3 -6
  20. data/app/views/admin/account/forgot_password.html.erb +2 -2
  21. data/app/views/admin/account/new.html.erb +3 -7
  22. data/app/views/admin/{helpers/dashboard → dashboard}/_applications.html.erb +0 -0
  23. data/app/views/admin/dashboard/_sidebar.html.erb +1 -1
  24. data/app/views/admin/dashboard/show.html.erb +7 -1
  25. data/app/views/admin/helpers/base/_apps.html.erb +1 -1
  26. data/app/views/admin/helpers/base/_login_info.html.erb +2 -2
  27. data/app/views/admin/helpers/filters/_filters.html.erb +3 -1
  28. data/app/views/admin/resources/_form.html.erb +5 -2
  29. data/app/views/admin/resources/edit.html.erb +1 -1
  30. data/app/views/admin/resources/index.html.erb +1 -1
  31. data/app/views/admin/resources/show.html.erb +2 -2
  32. data/app/views/admin/session/new.html.erb +3 -7
  33. data/app/views/admin/templates/_belongs_to.html.erb +8 -1
  34. data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +1 -1
  35. data/app/views/admin/templates/_relate_form.html.erb +1 -1
  36. data/app/views/admin/templates/_relate_form_with_autocomplete.html.erb +3 -1
  37. data/app/views/admin/templates/_string.html.erb +1 -1
  38. data/app/views/admin/templates/_text.html.erb +1 -1
  39. data/app/views/layouts/admin/base.html.erb +2 -0
  40. data/app/views/layouts/admin/headless.html.erb +2 -0
  41. data/app/views/layouts/admin/session.html.erb +6 -0
  42. data/config/routes.rb +4 -1
  43. data/lib/support/active_record.rb +0 -10
  44. data/lib/support/fake_user.rb +4 -6
  45. data/lib/support/object.rb +4 -0
  46. data/lib/support/string.rb +0 -8
  47. data/lib/typus.rb +2 -3
  48. data/lib/typus/authentication/base.rb +0 -1
  49. data/lib/typus/authentication/session.rb +22 -29
  50. data/lib/typus/orm/active_record.rb +5 -5
  51. data/lib/typus/orm/active_record/admin_user_v1.rb +93 -0
  52. data/lib/typus/orm/active_record/admin_user_v2.rb +49 -0
  53. data/lib/typus/orm/active_record/class_methods.rb +23 -143
  54. data/lib/typus/orm/active_record/user/instance_methods.rb +64 -0
  55. data/lib/typus/orm/base.rb +170 -0
  56. data/lib/typus/orm/mongo/class_methods.rb +11 -0
  57. data/lib/typus/resources.rb +2 -1
  58. data/lib/typus/version.rb +1 -1
  59. data/test/app/controllers/admin/account_controller_test.rb +4 -2
  60. data/test/app/controllers/admin/assets_controller_test.rb +12 -12
  61. data/test/app/controllers/admin/categories_controller_test.rb +5 -12
  62. data/test/app/controllers/admin/comments_controller_test.rb +1 -1
  63. data/test/app/controllers/admin/image_holders_controller_test.rb +1 -1
  64. data/test/app/controllers/admin/invoices_controller_test.rb +1 -1
  65. data/test/app/controllers/admin/posts_controller_test.rb +32 -32
  66. data/test/app/controllers/admin/projects_controller_test.rb +1 -1
  67. data/test/app/controllers/admin/typus_users_controller_test.rb +13 -17
  68. data/test/app/controllers/admin/users_controller_test.rb +9 -9
  69. data/test/app/helpers/admin/list_helper_test.rb +17 -0
  70. data/test/app/models/admin_user_test.rb +5 -0
  71. data/test/app/models/typus_user_roles_test.rb +1 -0
  72. data/test/app/models/typus_user_test.rb +45 -11
  73. data/test/factories.rb +1 -1
  74. data/test/fixtures/rails_app/app/controllers/admin/hits_controller.rb +40 -0
  75. data/test/fixtures/rails_app/app/controllers/admin_user.rb +3 -0
  76. data/test/fixtures/rails_app/app/models/asset.rb +0 -6
  77. data/test/fixtures/rails_app/app/models/hit.rb +27 -0
  78. data/test/fixtures/rails_app/app/views/admin/hits/_edit.html.erb +7 -0
  79. data/test/fixtures/rails_app/app/views/admin/hits/_index.html.erb +3 -0
  80. data/test/fixtures/rails_app/app/views/admin/hits/index.html.erb +28 -0
  81. data/test/fixtures/rails_app/config/boot.rb +3 -10
  82. data/test/fixtures/rails_app/config/deploy.rb +1 -1
  83. data/test/fixtures/rails_app/config/mongoid.yml +20 -0
  84. data/test/fixtures/rails_app/config/typus/crud_extended.yml +2 -0
  85. data/test/fixtures/rails_app/config/typus/mongo_db.yml +4 -0
  86. data/test/fixtures/rails_app/config/typus/mongo_db_roles.yml +2 -0
  87. data/test/fixtures/rails_app/db/schema.rb +11 -0
  88. data/test/lib/support/fake_user_test.rb +4 -0
  89. data/test/lib/support/string_test.rb +0 -18
  90. data/test/lib/typus/orm/active_record/class_methods_test.rb +14 -2
  91. data/test/lib/typus/orm/active_record/search_test.rb +1 -1
  92. data/test/lib/typus_test.rb +2 -1
  93. data/typus.gemspec +1 -1
  94. metadata +32 -45
  95. data/lib/typus/orm/active_record/instance_methods.rb +0 -13
  96. data/lib/typus/orm/active_record/user.rb +0 -157
  97. data/test/fixtures/rails_app/public/javascripts/application.js +0 -2
  98. data/test/fixtures/rails_app/public/javascripts/controls.js +0 -965
  99. data/test/fixtures/rails_app/public/javascripts/dragdrop.js +0 -974
  100. data/test/fixtures/rails_app/public/javascripts/effects.js +0 -1123
  101. data/test/fixtures/rails_app/public/javascripts/prototype.js +0 -6001
  102. data/test/fixtures/rails_app/public/javascripts/rails.js +0 -175
@@ -19,7 +19,7 @@ class Admin::UsersControllerTest < ActionController::TestCase
19
19
  end
20
20
 
21
21
  should_eventually "be able to destroy items" do
22
- get :destroy, { :id => @user.id, :method => :delete }
22
+ get :destroy, :id => @user.id, :method => :delete
23
23
 
24
24
  assert_response :redirect
25
25
  assert_equal "User successfully removed.", flash[:notice]
@@ -36,10 +36,10 @@ class Admin::UsersControllerTest < ActionController::TestCase
36
36
  end
37
37
 
38
38
  should "filter by projects" do
39
- get :index, { 'projects' => @project_1.id }
39
+ get :index, :projects => @project_1.id
40
40
  assert_equal [@user_1], assigns(:items)
41
41
 
42
- get :index, { 'projects' => @project_2.id }
42
+ get :index, :projects => @project_2.id
43
43
  assert_not_equal [@user_1], assigns(:items)
44
44
  end
45
45
 
@@ -61,10 +61,10 @@ class Admin::UsersControllerTest < ActionController::TestCase
61
61
 
62
62
  should "work" do
63
63
  assert_difference('@project.collaborators.count', -1) do
64
- post :unrelate, { :id => @user.id,
65
- :resource => 'Project',
66
- :resource_id => @project.id,
67
- :association_name => "collaborators" }
64
+ post :unrelate, :id => @user.id,
65
+ :resource => 'Project',
66
+ :resource_id => @project.id,
67
+ :association_name => "collaborators"
68
68
  end
69
69
  assert_response :redirect
70
70
  assert_redirected_to @request.env['HTTP_REFERER']
@@ -92,11 +92,11 @@ class Admin::UsersControllerTest < ActionController::TestCase
92
92
  post = User.first
93
93
  post.update_attributes(:name => "fesplugas")
94
94
 
95
- get :autocomplete, { :term => "jmeiss" }
95
+ get :autocomplete, :term => "jmeiss"
96
96
  assert_response :success
97
97
  assert_equal 0, assigns(:items).size
98
98
 
99
- get :autocomplete, { :term => "fesplugas" }
99
+ get :autocomplete, :term => "fesplugas"
100
100
  assert_response :success
101
101
  assert_equal 1, assigns(:items).size
102
102
  end
@@ -25,6 +25,23 @@ class Admin::ListHelperTest < ActiveSupport::TestCase
25
25
  assert list_actions.empty?
26
26
  end
27
27
 
28
+ should "not include actions that a role cannot perform" do
29
+ @resource = mock
30
+ @resource.stubs(:name).returns("resource")
31
+
32
+ self.stubs(:link_to).returns("some_link")
33
+ sample_action = ["a body", {:action => :some_action}, {}]
34
+ self.stubs(:resources_actions).returns([sample_action] * 3)
35
+
36
+ admin_user = mock
37
+ admin_user.stubs(:can?).returns(true, false, true)
38
+ self.stubs(:admin_user).returns(admin_user)
39
+ self.stubs(:params).returns({:action => 'some_other_action'})
40
+
41
+ results = list_actions.split("/")
42
+ assert_equal 2, results.size
43
+ end
44
+
28
45
  should_eventually "return an array with our custom actions"
29
46
 
30
47
  end
@@ -0,0 +1,5 @@
1
+ require "test_helper"
2
+
3
+ class AdminUserTest < ActiveSupport::TestCase
4
+
5
+ end
@@ -22,6 +22,7 @@ class TypusUserRolesTest < ActiveSupport::TestCase
22
22
  "Dog",
23
23
  "Entry",
24
24
  "Git",
25
+ "Hit",
25
26
  "ImageHolder",
26
27
  "Invoice",
27
28
  "Order",
@@ -8,22 +8,38 @@ class TypusUserTest < ActiveSupport::TestCase
8
8
  'test@example',
9
9
  'test@example.c',
10
10
  'testexample.com' ].each do |value|
11
- should_not allow_value(value).for(:email)
11
+ should "not allow #{value}" do
12
+ assert !Factory.build(:typus_user, :email => value).valid?
13
+ end
12
14
  end
13
15
 
14
16
  [ 'test+filter@example.com',
15
17
  'test.filter@example.com',
16
18
  'test@example.co.uk',
17
19
  'test@example.es' ].each do |value|
18
- should allow_value(value).for(:email)
20
+ should "allow #{value}" do
21
+ assert Factory.build(:typus_user, :email => value).valid?
22
+ end
19
23
  end
20
24
 
21
- should validate_presence_of :email
22
- should validate_presence_of :role
25
+ should "validate_presence_of :email" do
26
+ assert !Factory.build(:typus_user, :email => nil).valid?
27
+ end
23
28
 
24
- should_not allow_mass_assignment_of :status
29
+ should "validate_presence_of :role" do
30
+ assert !Factory.build(:typus_user, :role => nil).valid?
31
+ end
25
32
 
26
- should ensure_length_of(:password).is_at_least(6).is_at_most(40)
33
+ should "validate password length" do
34
+ assert !Factory.build(:typus_user, :password => "0"*5).valid?, "5"
35
+ assert Factory.build(:typus_user, :password => "0"*6).valid?, "6"
36
+ assert Factory.build(:typus_user, :password => "0"*40).valid?, "40"
37
+ assert !Factory.build(:typus_user, :password => "0"*41).valid?, "41"
38
+ end
39
+
40
+ should "not allow_mass_assignment_of :status" do
41
+ assert TypusUser.attr_protected.include?("status")
42
+ end
27
43
 
28
44
  should "verify columns" do
29
45
  expected = %w(id first_name last_name email role status salt crypted_password token preferences created_at updated_at).sort
@@ -52,6 +68,11 @@ class TypusUserTest < ActiveSupport::TestCase
52
68
  assert TypusUser.generate(options).valid?
53
69
  end
54
70
 
71
+ should "have set a default locale" do
72
+ options = { :email => 'demo@example.com', :role => 'admin' }
73
+ assert_equal :en, TypusUser.generate(options).locale
74
+ end
75
+
55
76
  end
56
77
 
57
78
  context "TypusUser" do
@@ -61,27 +82,27 @@ class TypusUserTest < ActiveSupport::TestCase
61
82
  end
62
83
 
63
84
  should "return email" do
64
- assert_equal @typus_user.email, @typus_user.name
85
+ assert_equal @typus_user.email, @typus_user.to_label
65
86
  end
66
87
 
67
88
  should "return first_name" do
68
89
  @typus_user.first_name = "John"
69
- assert_equal "John", @typus_user.name
90
+ assert_equal "John", @typus_user.to_label
70
91
  end
71
92
 
72
93
  should "return last_name" do
73
94
  @typus_user.last_name = "Locke"
74
- assert_equal "Locke", @typus_user.name
95
+ assert_equal "Locke", @typus_user.to_label
75
96
  end
76
97
 
77
98
  should "return name when first_name and last_name are set" do
78
99
  @typus_user.first_name, @typus_user.last_name = "John", "Locke"
79
- assert_equal "John Locke", @typus_user.name
100
+ assert_equal "John Locke", @typus_user.to_label
80
101
  end
81
102
 
82
103
  should "return name when first_name and last_name are set to nil" do
83
104
  @typus_user.first_name, @typus_user.last_name = nil
84
- assert_equal @typus_user.email, @typus_user.name
105
+ assert_equal @typus_user.email, @typus_user.to_label
85
106
  end
86
107
 
87
108
  should "verify salt never changes" do
@@ -191,4 +212,17 @@ class TypusUserTest < ActiveSupport::TestCase
191
212
 
192
213
  end
193
214
 
215
+ should "owns a resource" do
216
+ typus_user = Factory(:typus_user)
217
+ resource = Factory(:post, :typus_user_id => typus_user.id)
218
+ assert typus_user.owns?(resource)
219
+ end
220
+
221
+ should "not own a resource" do
222
+ typus_user = Factory(:typus_user)
223
+ typus_user_2 = Factory(:typus_user)
224
+ resource = Factory(:post, :typus_user_id => typus_user_2.id)
225
+ assert !typus_user.owns?(resource)
226
+ end
227
+
194
228
  end
@@ -46,7 +46,7 @@ Factory.define :post do |f|
46
46
  end
47
47
 
48
48
  Factory.define :typus_user do |f|
49
- f.sequence(:email) { |n| "admin+#{n}@example.com" }
49
+ f.sequence(:email) { |n| "user+#{n}@example.com" }
50
50
  f.role "admin"
51
51
  f.status true
52
52
  f.token "1A2B3C4D5E6F"
@@ -0,0 +1,40 @@
1
+ class Admin::HitsController < Admin::ResourcesController
2
+
3
+ def index
4
+ @items = Hit.paginate(:per_page => 15, :page => params[:page])
5
+ add_resource_action("Edit", {:action => 'edit'}, {})
6
+ add_resource_action("Trash", {:action => "destroy"}, {:confirm => "#{Typus::I18n.t("Trash")}?", :method => 'delete'})
7
+ end
8
+
9
+ def new
10
+ @item = Hit.new
11
+ end
12
+
13
+ def create
14
+ @item = Hit.new(params[:hit])
15
+ if @item.save
16
+ flash[:notice] = Typus::I18n::t("Hit was successfully created.")
17
+ redirect_to :action => 'edit', :id => @item.id
18
+ else
19
+ render :action => 'new'
20
+ end
21
+ end
22
+
23
+ def edit
24
+ @item = Hit.find(params[:id])
25
+ end
26
+
27
+ def update
28
+ @item = Hit.find(params[:id])
29
+ if @item.update_attributes(params[:entry])
30
+ flash[:notice] = Typus::I18n::t("Hit was successfully updated.")
31
+ redirect_to :action => 'edit', :id => @item.id
32
+ else
33
+ render :action => "edit"
34
+ end
35
+ end
36
+
37
+ def set_scope; end
38
+ private :set_scope
39
+
40
+ end
@@ -0,0 +1,3 @@
1
+ class AdminUser < ActiveRecord::Base
2
+ has_admin
3
+ end
@@ -9,12 +9,6 @@
9
9
 
10
10
  class Asset < ActiveRecord::Base
11
11
 
12
- ##
13
- # Validations
14
- #
15
-
16
- validates :caption, :presence => true
17
-
18
12
  ##
19
13
  # Dragonfly Stuff
20
14
  #
@@ -0,0 +1,27 @@
1
+ require "typus/orm/mongo/class_methods"
2
+
3
+ class Hit
4
+
5
+ extend Typus::Orm::Mongo::ClassMethods
6
+
7
+ if defined?(Mongoid)
8
+ include Mongoid::Document
9
+
10
+ field :name
11
+ field :description
12
+
13
+ validates_presence_of :name
14
+ validates_uniqueness_of :name
15
+ else
16
+ extend ActiveModel::Naming
17
+ end
18
+
19
+ def self.typus_fields_for(*args)
20
+ [[:name, :string], [:description, :text]]
21
+ end
22
+
23
+ def self.model_fields
24
+ [[:name, :string], [:description, :text]]
25
+ end
26
+
27
+ end
@@ -0,0 +1,7 @@
1
+ <div class="notice">
2
+ This is the MongoDB document.
3
+ </div>
4
+
5
+ <pre>
6
+ <%= @item.inspect %>
7
+ </pre>
@@ -0,0 +1,3 @@
1
+ <div class="notice">
2
+ This model uses the document-oriented database <strong>MongoDB</strong>.
3
+ </div>
@@ -0,0 +1,28 @@
1
+ <%
2
+ page_title = @resource.model_name.human.pluralize
3
+ title(page_title)
4
+ %>
5
+
6
+ <% content_for :sidebar, build_sidebar %>
7
+
8
+ <h2>
9
+ <%= page_title %>
10
+ <small><%= list_actions %></small>
11
+ </h2>
12
+
13
+ <%= display_flash_message %>
14
+
15
+ <%= render 'index' %>
16
+
17
+ <ul class="predefined_filters">
18
+ <% predefined_filters.each do |filter, action, scope| %>
19
+ <li><%= link_to Typus::I18n.t(filter), params.dup.cleanup.merge(:action => action) %> (<%= @resource.send(scope).count %>)</li>
20
+ <% end %>
21
+ </ul>
22
+
23
+ <% if @items.any? -%>
24
+ <%= build_list(@resource, fields, @items) %>
25
+ <%= will_paginate(@items, Typus.pagination) %>
26
+ <% else %>
27
+ <p><%= Typus::I18n.t("No %{resources} found.", :resources => @resource.model_name.human.downcase.pluralize) %></p>
28
+ <% end %>
@@ -1,13 +1,6 @@
1
1
  require 'rubygems'
2
2
 
3
3
  # Set up gems listed in the Gemfile.
4
- gemfile = File.expand_path('../../../../../Gemfile', __FILE__)
5
- begin
6
- ENV['BUNDLE_GEMFILE'] = gemfile
7
- require 'bundler'
8
- Bundler.setup
9
- rescue Bundler::GemNotFound => e
10
- STDERR.puts e.message
11
- STDERR.puts "Try running `bundle install`."
12
- exit!
13
- end if File.exist?(gemfile)
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -9,7 +9,7 @@ set :repository, "git://github.com/fesplugas/typus.git"
9
9
  set :deploy_via, :remote_cache
10
10
  set :keep_releases, 2
11
11
 
12
- # Override default :bundle_flags because I don't provice a Gemfile.lock.
12
+ # Override default `:bundle_flags` because I don't provide a Gemfile.lock.
13
13
  set :bundle_flags, "--quiet"
14
14
 
15
15
  set :domain, "demo.typuscms.com"
@@ -0,0 +1,20 @@
1
+ defaults: &defaults
2
+ host: localhost
3
+ # slaves:
4
+ # - host: slave1.local
5
+ # port: 27018
6
+ # - host: slave2.local
7
+ # port: 27019
8
+
9
+ development:
10
+ <<: *defaults
11
+ database: rails_app_development
12
+
13
+ test:
14
+ <<: *defaults
15
+ database: rails_app_test
16
+
17
+ # set these environment variables on your prod server
18
+ production:
19
+ <<: *defaults
20
+ database: rails_app_production
@@ -2,6 +2,8 @@ Asset:
2
2
  fields:
3
3
  default: caption, dragonfly, dragonfly_required
4
4
  special: caption, dragonfly, dragonfly_required, original_file_name
5
+ form: caption, dragonfly, dragonfly_required, original_file_name
6
+ new: dragonfly_required
5
7
  application: CRUD Extended
6
8
 
7
9
  Category:
@@ -0,0 +1,4 @@
1
+ Hit:
2
+ fields:
3
+ default: name, description
4
+ application: MongoDB
@@ -2,6 +2,17 @@ ActiveRecord::Migration.verbose = false
2
2
 
3
3
  ActiveRecord::Schema.define do
4
4
 
5
+ create_table :admin_users, :force => true do |t|
6
+ t.string :first_name
7
+ t.string :last_name
8
+ t.string :role, :null => false
9
+ t.string :email, :null => false
10
+ t.string :password_digest, :null => false
11
+ t.string :preferences
12
+ t.boolean :status, :default => false
13
+ t.timestamps
14
+ end
15
+
5
16
  create_table :articles, :force => true do |t|
6
17
  t.string :title
7
18
  t.text :body
@@ -56,4 +56,8 @@ class FakeUserTest < ActiveSupport::TestCase
56
56
  assert !@fake_user.respond_to?(:resources)
57
57
  end
58
58
 
59
+ should "always be the owner of a resource" do
60
+ assert @fake_user.owns?('a')
61
+ end
62
+
59
63
  end
@@ -49,24 +49,6 @@ class StringTest < ActiveSupport::TestCase
49
49
 
50
50
  end
51
51
 
52
- context "action_mapper" do
53
-
54
- should "return list for index" do
55
- assert_equal :list, 'index'.action_mapper
56
- end
57
-
58
- should "return form for new, create, edit and update" do
59
- %w(new create edit update).each do |action|
60
- assert_equal :form, action.action_mapper
61
- end
62
- end
63
-
64
- should "return the same action for everything else" do
65
- assert_equal 'undefined', 'undefined'.action_mapper
66
- end
67
-
68
- end
69
-
70
52
  context "acl_action_mapper" do
71
53
 
72
54
  should "return create" do