tiny_core_accounts 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/lib/tiny_core/acts/account.rb +51 -0
  2. data/lib/tiny_core/acts/user_account.rb +54 -0
  3. data/lib/tiny_core/controllers/accounts.rb +62 -0
  4. data/lib/tiny_core/controllers/admin_accounts.rb +37 -0
  5. data/lib/tiny_core/controllers/application.rb +21 -0
  6. data/lib/tiny_core/controllers/user_accounts.rb +52 -0
  7. data/lib/tiny_core/has/accounts.rb +45 -0
  8. data/lib/tiny_core_accounts.rb +9 -0
  9. data/rails_generators/tiny_account/templates/account.rb +3 -0
  10. data/rails_generators/tiny_account/templates/account_test.rb +7 -0
  11. data/rails_generators/tiny_account/templates/accounts/_form.html.erb +11 -0
  12. data/rails_generators/tiny_account/templates/accounts/_info.html.erb +4 -0
  13. data/rails_generators/tiny_account/templates/accounts/_no_account.de.html.erb +5 -0
  14. data/rails_generators/tiny_account/templates/accounts/_no_account.html.erb +4 -0
  15. data/rails_generators/tiny_account/templates/accounts/_tabs.html.erb +4 -0
  16. data/rails_generators/tiny_account/templates/accounts/edit.html.erb +5 -0
  17. data/rails_generators/tiny_account/templates/accounts/index.html.erb +33 -0
  18. data/rails_generators/tiny_account/templates/accounts/new.html.erb +5 -0
  19. data/rails_generators/tiny_account/templates/accounts/show.html.erb +46 -0
  20. data/rails_generators/tiny_account/templates/accounts_controller.rb +3 -0
  21. data/rails_generators/tiny_account/templates/accounts_controller_test.rb +7 -0
  22. data/rails_generators/tiny_account/templates/add_current_account_id_to_users.rb +9 -0
  23. data/rails_generators/tiny_account/templates/admin/accounts/_index.html.erb +22 -0
  24. data/rails_generators/tiny_account/templates/admin/accounts/_tabs.html.erb +4 -0
  25. data/rails_generators/tiny_account/templates/admin/accounts/edit.html.erb +14 -0
  26. data/rails_generators/tiny_account/templates/admin/accounts/index.html.erb +11 -0
  27. data/rails_generators/tiny_account/templates/admin/accounts/show.html.erb +17 -0
  28. data/rails_generators/tiny_account/templates/admin_accounts_controller.rb +3 -0
  29. data/rails_generators/tiny_account/templates/admin_accounts_controller_test.rb +7 -0
  30. data/rails_generators/tiny_account/templates/create_accounts.rb +12 -0
  31. data/rails_generators/tiny_account/templates/create_user_accounts.rb +13 -0
  32. data/rails_generators/tiny_account/templates/user_account.rb +3 -0
  33. data/rails_generators/tiny_account/templates/user_account_test.rb +7 -0
  34. data/rails_generators/tiny_account/templates/user_accounts_controller.rb +3 -0
  35. data/rails_generators/tiny_account/templates/user_accounts_controller_test.rb +7 -0
  36. data/rails_generators/tiny_account/tiny_account_generator.rb +41 -0
  37. metadata +102 -0
@@ -0,0 +1,51 @@
1
+ module TinyCore
2
+ module Acts
3
+ module Account
4
+ module ActsMethods
5
+ def acts_as_account
6
+ validates_presence_of :name
7
+
8
+ has_many :user_accounts
9
+ has_many :users, :through => :user_accounts
10
+
11
+ named_scope :ordered_by_name, :order => 'name ASC'
12
+
13
+ extend ClassMethods
14
+ include InstanceMethods
15
+ end
16
+ end
17
+
18
+ module ClassMethods
19
+ def paginate_for_list(filter, options = {})
20
+ with_search_scope(filter) do
21
+ paginate(options.merge(:order => 'accounts.name ASC'))
22
+ end
23
+ end
24
+
25
+ def from_param!(param)
26
+ find(param)
27
+ end
28
+
29
+ protected
30
+ def with_search_scope(filter, &block)
31
+ conditions = filter.empty? ? nil : ['accounts.name LIKE ?', "%#{filter.query}%"]
32
+ with_scope :find => { :conditions => conditions } do
33
+ yield
34
+ end
35
+ end
36
+ end
37
+
38
+ module InstanceMethods
39
+ def user_accounts_with_users
40
+ user_accounts.find(:all, :include => :user, :order => 'users.full_name ASC')
41
+ end
42
+ end
43
+
44
+ def self.included(receiver)
45
+ receiver.extend ActsMethods
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ ActiveRecord::Base.send :include, TinyCore::Acts::Account
@@ -0,0 +1,54 @@
1
+ module TinyCore
2
+ module Acts
3
+ module UserAccount
4
+ module ActsMethods
5
+ def acts_as_user_account(options = {})
6
+ belongs_to :user
7
+ belongs_to :account
8
+
9
+ validates_uniqueness_of :user_id, :scope => :account_id
10
+
11
+ attr_accessor :email
12
+ cattr_accessor :available_roles
13
+ self.available_roles = options[:roles] || ['admin', 'user', 'observer']
14
+
15
+ before_validation_on_create :set_user_from_email
16
+
17
+ include InstanceMethods
18
+ extend ClassMethods
19
+ end
20
+ end
21
+
22
+ module ClassMethods
23
+ def available_roles_for_select
24
+ available_roles.collect { |role| [I18n.t("account.role.#{role}"), role] }
25
+ end
26
+ end
27
+
28
+ module InstanceMethods
29
+ def after_initialize
30
+ extend "::Role::Account::#{self.role.classify}".constantize
31
+ end
32
+
33
+ protected
34
+ def set_user_from_email
35
+ return if email.blank?
36
+
37
+ user_from_email = ::User.find_by_email(self.email)
38
+ if user_from_email.nil?
39
+ errors.add(:email, I18n.t('activerecord.errors.models.user_account.attributes.email.not_found'))
40
+ false
41
+ else
42
+ self.user = user_from_email
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.included(receiver)
48
+ receiver.extend ActsMethods
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ ActiveRecord::Base.send :include, TinyCore::Acts::UserAccount
@@ -0,0 +1,62 @@
1
+ module TinyCore
2
+ module Controllers
3
+ module Accounts
4
+ def index
5
+ @accounts = current_user.accounts.ordered_by_name
6
+ end
7
+
8
+ def new
9
+ @account = Account.new
10
+ end
11
+
12
+ def show
13
+ @account = Account.find(params[:id])
14
+ can_see_account!(@account)
15
+ end
16
+
17
+ def edit
18
+ @account = Account.find(params[:id])
19
+ can_edit_account!(@account)
20
+ end
21
+
22
+ def create
23
+ @account = Account.new(params[:account])
24
+ if @account.save
25
+ current_user.accounts << @account
26
+ current_user.set_role_for_account(@account, 'admin')
27
+ current_user.switch_to_account @account
28
+ flash[:notice] = I18n.t('flash.notice.created_account', :account => @account.name)
29
+ redirect_to root_path
30
+ else
31
+ render :action => 'new'
32
+ end
33
+ end
34
+
35
+ def update
36
+ @account = Account.find(params[:id])
37
+ can_edit_account!(@account) do
38
+ if @account.update_attributes(params[:account])
39
+ flash[:notice] = I18n.t('flash.notice.updated_account', :account => @account.name)
40
+ redirect_to account_path(@account)
41
+ else
42
+ render :action => 'edit'
43
+ end
44
+ end
45
+ end
46
+
47
+ def switch
48
+ @account = Account.find(params[:id])
49
+ can_switch_to_account!(@account) do
50
+ current_user.switch_to_account(@account)
51
+ flash[:notice] = I18n.t('flash.notice.switched_account', :account => @account.name)
52
+ redirect_to root_path
53
+ end
54
+ end
55
+
56
+ def self.included(receiver)
57
+ receiver.before_filter :login_required
58
+ receiver.before_filter :can_see_account_details!
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,37 @@
1
+ module TinyCore
2
+ module Controllers
3
+ module AdminAccounts
4
+ def self.included(receiver)
5
+ receiver.before_filter :login_required
6
+ receiver.before_filter :can_see_all_accounts!
7
+ receiver.before_filter :can_edit_all_accounts!, :only => [ :edit, :update ]
8
+ end
9
+
10
+ def index
11
+ @search_filter = SearchFilter.new(params[:search_filter])
12
+ @accounts = Account.paginate_for_list(@search_filter, :page => params[:page])
13
+ render :update do |page|
14
+ page.replace_html 'accounts', :partial => 'index'
15
+ end if request.xhr?
16
+ end
17
+
18
+ def show
19
+ @account = Account.find(params[:id])
20
+ end
21
+
22
+ def edit
23
+ @account = Account.find(params[:id])
24
+ end
25
+
26
+ def update
27
+ @account = Account.find(params[:id])
28
+ if @account.update_attributes_without_attr_protected(params[:account])
29
+ flash[:notice] = I18n.t("flash.notice.updated_account", :account => @account.name)
30
+ redirect_to admin_accounts_path
31
+ else
32
+ render :action => 'edit'
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ module TinyCore
2
+ module Controllers
3
+ module Application
4
+ protected
5
+ def find_account
6
+ @account = params[:account_id] ? Account.find(params[:account_id]) : current_user.current_account
7
+ if @account
8
+ can_see_account!(@account) do
9
+ if current_user.current_account != @account
10
+ flash[:notice] = I18n.t('flash.notice.switched_account', :account => @account.name)
11
+ current_user.switch_to_account(@account)
12
+ end
13
+ end
14
+ else
15
+ flash[:error] = I18n.t("flash.error.create_account_first")
16
+ redirect_to new_account_path
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,52 @@
1
+ module TinyCore
2
+ module Controllers
3
+ module UserAccounts
4
+ def self.included(receiver)
5
+ receiver.before_filter :find_account
6
+ end
7
+
8
+ def index
9
+ redirect_to account_path(@account)
10
+ end
11
+
12
+ def new
13
+ can_add_user_to_account!(@account) do
14
+ @user_account = @account.user_accounts.build
15
+ end
16
+ end
17
+
18
+ def create
19
+ can_add_user_to_account!(@account) do
20
+ @user_account = @account.user_accounts.build(params[:user_account])
21
+ if @user_account.save
22
+ flash[:notice] = I18n.t('flash.notice.created_user_account')
23
+ redirect_to new_account_user_account_path(@account)
24
+ else
25
+ render :action => 'new'
26
+ end
27
+ end
28
+ end
29
+
30
+ def update
31
+ @user_account = UserAccount.find(params[:id])
32
+ can_assign_role_for_user_and_account!(@user_account.user, @account) do
33
+ if @user_account.update_attributes(params[:user_account])
34
+ flash[:notice] = I18n.t('flash.notice.assign_roles')
35
+ else
36
+ flash[:error] = I18n.t('flash.error.assign_roles')
37
+ end
38
+ redirect_to account_path(@account)
39
+ end
40
+ end
41
+
42
+ def destroy
43
+ @user_account = @account.user_accounts.find(params[:id])
44
+ can_remove_user_from_account!(@user_account.user, @account) do
45
+ @user_account.destroy
46
+ flash[:notice] = I18n.t('flash.notice.removed_user_account')
47
+ redirect_to account_path(@account)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
1
+ module TinyCore
2
+ module Has
3
+ module Accounts
4
+ module HasMethods
5
+ def has_accounts
6
+ has_many :user_accounts
7
+ has_many :accounts, :through => :user_accounts
8
+
9
+ belongs_to :current_account, :class_name => 'Account'
10
+
11
+ include InstanceMethods
12
+ end
13
+ end
14
+
15
+ module ClassMethods
16
+
17
+ end
18
+
19
+ module InstanceMethods
20
+ def switch_to_account(account)
21
+ update_attribute(:current_account_id, account.id)
22
+ end
23
+
24
+ def set_role_for_account(account, role)
25
+ user_account_for(account).update_attribute(:role, role)
26
+ end
27
+
28
+ def user_account_for(account)
29
+ UserAccount.find_by_user_id_and_account_id(self.id, account.id)
30
+ end
31
+
32
+ def shares_accounts_with?(user)
33
+ # This can probably be done more efficiently
34
+ !(self.accounts & user.accounts).empty?
35
+ end
36
+ end
37
+
38
+ def self.included(receiver)
39
+ receiver.extend HasMethods
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ ActiveRecord::Base.send :include, TinyCore::Has::Accounts
@@ -0,0 +1,9 @@
1
+ # require all necessary files here
2
+
3
+ require File.dirname(__FILE__) + '/tiny_core/acts/account'
4
+ require File.dirname(__FILE__) + '/tiny_core/acts/user_account'
5
+ require File.dirname(__FILE__) + '/tiny_core/controllers/accounts'
6
+ require File.dirname(__FILE__) + '/tiny_core/controllers/application'
7
+ require File.dirname(__FILE__) + '/tiny_core/controllers/admin_accounts'
8
+ require File.dirname(__FILE__) + '/tiny_core/controllers/user_accounts'
9
+ require File.dirname(__FILE__) + '/tiny_core/has/accounts'
@@ -0,0 +1,3 @@
1
+ class Account < ActiveRecord::Base
2
+ acts_as_account
3
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class AccountTest < ActiveSupport::TestCase
4
+ test "the truth" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ <% form_for @account, :html => { :class => 'form' } do |f| %>
2
+ <%= f.error_messages :header_message => t('.could_not_create_account') %>
3
+
4
+ <p class="form_item">
5
+ <span class="label"><%= f.label :name, t('.name'), :class => 'required' %></span>
6
+ <span class="desc"><%= t(".name_hint") %></span>
7
+ <%= f.text_field :name %>
8
+ </p>
9
+
10
+ <p><%= f.submit t('.save_account') %></p>
11
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <dl>
2
+ <dt><%= t(".name") %></dt>
3
+ <dd><%= @account.name %></dd>
4
+ </dl>
@@ -0,0 +1,5 @@
1
+ <p>
2
+ Sie sind keinem Konto zugeordnet. Sie können entweder ein neues Konto erstellen, oder den Administrator eines
3
+ bestehenden Kontos bitten, Sie dem Konto hinzuzufügen. Falls Sie Ihr eigenes Konto erstellen können Sie selbst
4
+ weitere Benutzer hinzufügen.
5
+ </p>
@@ -0,0 +1,4 @@
1
+ <p>
2
+ You are not assigned to any account. Either create a new account, or ask the admin of an existing account
3
+ to add you. If you want to create a new account, you can add more users to it, once the account is set up.
4
+ </p>
@@ -0,0 +1,4 @@
1
+ <% tabs(:selected => selected) do |t| %>
2
+ <% t.tab :information, t(".information"), account_path(@account) %>
3
+ <% t.tab :edit, t(".edit"), edit_account_path(@account) %>
4
+ <% end %>
@@ -0,0 +1,5 @@
1
+ <h2><%= t('.edit_account') %></h2>
2
+
3
+ <%= render :partial => "tabs", :locals => { :selected => :edit } %>
4
+
5
+ <%= render :partial => "form" %>
@@ -0,0 +1,33 @@
1
+ <% if @accounts.blank? %>
2
+ <%= render :partial => "no_account" %>
3
+ <% else %>
4
+ <table>
5
+ <thead>
6
+ <tr>
7
+ <th><%= t('.name') %></th>
8
+ <th><%= t('.options') %></th>
9
+ </tr>
10
+ </thead>
11
+ <tbody>
12
+ <% @accounts.each do |account| %>
13
+ <tr>
14
+ <td>
15
+ <% if current_user.can_switch_to_account?(account) %>
16
+ <%= link_to account.name, switch_account_path(account), :method => :post %>
17
+ <% else %>
18
+ <%= account.name %>
19
+ <% end %>
20
+ </td>
21
+ <td>
22
+ <% action_list do |a| %>
23
+ <% a.link_to t('.details'), account_path(account) %>
24
+ <% a.link_to t('.edit'), edit_account_path(account) if current_user.can_edit_account?(account) %>
25
+ <% end %>
26
+ </td>
27
+ </tr>
28
+ <% end %>
29
+ </tbody>
30
+ </table>
31
+ <% end %>
32
+
33
+ <p><%= link_to t('.new_account'), new_account_path %></p>
@@ -0,0 +1,5 @@
1
+ <h2><%= t('.new_account') %></h2>
2
+
3
+ <%= render :partial => "no_account" if current_user.accounts.empty? %>
4
+
5
+ <%= render :partial => "form" %>
@@ -0,0 +1,46 @@
1
+ <h2><%= t('.account', :account => @account.name) %></h2>
2
+
3
+ <%= render :partial => "tabs", :locals => { :selected => :information } %>
4
+
5
+ <%= render :partial => "info" %>
6
+
7
+ <h3><%= t(".users") %></h3>
8
+
9
+ <table>
10
+ <thead>
11
+ <tr>
12
+ <th><%= t('.name') %></th>
13
+ <th><%= t('.role') %></th>
14
+ <th><%= t('.options') %></th>
15
+ </tr>
16
+ </thead>
17
+ <tbody>
18
+ <% @account.user_accounts_with_users.each do |user_account| %>
19
+ <tr>
20
+ <td><%= link_to user_account.user.full_name, user_path(user_account.user) %></td>
21
+ <% if current_user.can_assign_role_for_user_and_account?(user_account.user, @account) %>
22
+ <td>
23
+ <% form_for [@account, user_account] do |f| %>
24
+ <%= f.select :role, UserAccount.available_roles_for_select %>
25
+ <%= f.submit t('.change') %>
26
+ <% end %>
27
+ </td>
28
+ <% else%>
29
+ <td><strong><%= t("account.role.#{user_account.role}") %></strong></td>
30
+ <% end %>
31
+ <% if current_user.can_remove_user_from_account?(user_account.user, @account) %>
32
+ <td><%= link_to t('.remove'), account_user_account_path(@account, user_account), :method => :delete, :confirm => t('.really_remove_user_from_account') %></td>
33
+ <% end %>
34
+ </tr>
35
+ <% end %>
36
+ </tbody>
37
+ </table>
38
+
39
+ <% if current_user.can_add_user_to_account?(@account) %>
40
+ <p>
41
+ <% action_list do |a| %>
42
+ <% a.link_to t('.add_existing'), new_account_user_account_path(@account) %>
43
+ <% a.link_to t('.add_new'), new_user_path if @account == current_user.current_account %>
44
+ <% end %>
45
+ </p>
46
+ <% end %>
@@ -0,0 +1,3 @@
1
+ class AccountsController < ApplicationController
2
+ include TinyCore::Controllers::Accounts
3
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class AccountsControllerTest < ActionController::TestCase
4
+ test "the truth" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class AddCurrentAccountIdToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :current_account_id, :integer
4
+ end
5
+
6
+ def self.down
7
+ remove_column :users, :current_account_id
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ <%= will_paginate @accounts %>
2
+
3
+ <table class="list">
4
+ <thead>
5
+ <tr>
6
+ <th><%= t('.name') %></th>
7
+ <th><%= t('.users') %></th>
8
+ <th><%= t('.options') %></th>
9
+ </tr>
10
+ </thead>
11
+ <tbody>
12
+ <% @accounts.each do |account| %>
13
+ <tr>
14
+ <td><%= link_to highlight(account.name, @search_filter.query), admin_account_path(account) %></td>
15
+ <td><%= account.users.count %></td>
16
+ <td><%= link_to t(".edit"), edit_admin_account_path(account) %></td>
17
+ </tr>
18
+ <% end %>
19
+ </tbody>
20
+ </table>
21
+
22
+ <%= will_paginate @accounts %>
@@ -0,0 +1,4 @@
1
+ <% tabs(:selected => selected) do |t| %>
2
+ <% t.tab :information, t(".information"), admin_account_path(@account) %>
3
+ <% t.tab :edit, t(".edit"), edit_admin_account_path(@account) %>
4
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <h2><%= t('.edit_account') %></h2>
2
+
3
+ <%= render :partial => "tabs", :locals => { :selected => :edit } %>
4
+
5
+ <% form_for [:admin, @account], :html => { :class => 'form' } do |f| %>
6
+ <%= f.error_messages :header_message => t('.could_not_update_account') %>
7
+
8
+ <p class="form_item">
9
+ <span class="label"><%= f.label :name, t('.name'), :class => 'required' %></span>
10
+ <%= f.text_field :name %>
11
+ </p>
12
+
13
+ <p><%= f.submit t('.save_account') %></p>
14
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <h2><%= t('.all_accounts') %></h2>
2
+
3
+ <% if @accounts.empty? %>
4
+ <p><%= t('.no_accounts') %></p>
5
+ <% else %>
6
+ <%= render :partial => "/shared/filter", :locals => { :url => admin_accounts_path } %>
7
+
8
+ <div id="accounts">
9
+ <%= render :partial => "index" %>
10
+ </div>
11
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <h2><%= t('.account', :account => @account.name) %></h2>
2
+
3
+ <%= render :partial => "tabs", :locals => { :selected => :information } %>
4
+
5
+ <%= render :partial => "/accounts/info" %>
6
+
7
+ <h3><%= t(".users") %></h3>
8
+
9
+ <% if @account.users.empty? %>
10
+ <p><%= t('.no_users') %></p>
11
+ <% else %>
12
+ <ul class="asterisk">
13
+ <% @account.users.each do |user| %>
14
+ <li><%= link_to user.full_name, user_path(user) %> (<%= t("account.role.#{user.user_account_for(@account).role}") %>)</li>
15
+ <% end %>
16
+ </ul>
17
+ <% end %>
@@ -0,0 +1,3 @@
1
+ class Admin::AccountsController < ApplicationController
2
+ include TinyCore::Controllers::AdminAccounts
3
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ class Admin::AccountsControllerTest < ActionController::TestCase
4
+ test "the truth" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ class CreateAccounts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :accounts do |t|
4
+ t.string :name
5
+ t.timestamps
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :accounts
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ class CreateUserAccounts < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :user_accounts do |t|
4
+ t.integer :user_id
5
+ t.integer :account_id
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :user_accounts
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class UserAccount < ActiveRecord::Base
2
+ acts_as_user_account
3
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class UserAccountTest < ActiveSupport::TestCase
4
+ test "the truth" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class UserAccountsController < ApplicationController
2
+ include TinyCore::Controllers::UserAccounts
3
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
+
3
+ class UserAccountsControllerTest < ActionController::TestCase
4
+ test "the truth" do
5
+ assert true
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ class TinyAccountGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions "Account", "AccountTest", "AccountController", "AccountControllerTest", "Admin::AccountController", "Admin::AccountControllerTest"
6
+
7
+ # Model, controller, view and test directories.
8
+ m.directory 'app/models'
9
+ m.directory 'app/controllers'
10
+ m.directory 'app/controllers/admin'
11
+ m.directory 'app/views/accounts'
12
+ m.directory 'app/views/admin/accounts'
13
+ m.directory 'test/unit'
14
+ m.directory 'test/functional'
15
+
16
+ # Classes and tests.
17
+ m.file "account.rb", 'app/models/account.rb'
18
+ m.file "user_account.rb", 'app/models/user_account.rb'
19
+ m.file "account_test.rb", 'test/unit/account_test.rb'
20
+ m.file "user_account_test.rb", 'test/unit/user_account_test.rb'
21
+ m.file "accounts_controller.rb", 'app/controllers/accounts_controller.rb'
22
+ m.file "user_accounts_controller.rb", 'app/controllers/user_accounts_controller.rb'
23
+ m.file "admin_accounts_controller.rb", 'app/controllers/admin/accounts_controller.rb'
24
+ m.file "accounts_controller_test.rb", 'test/functional/accounst_controller_test.rb'
25
+ m.file "user_accounts_controller_test.rb", 'test/functional/user_accounst_controller_test.rb'
26
+ m.file "admin_accounts_controller_test.rb", 'test/functional/admin_accounts_controller_test.rb'
27
+
28
+ # Views
29
+ base_dir = File.dirname(__FILE__) + '/templates'
30
+ Dir.glob("#{base_dir}/**/*.html.erb") do |template|
31
+ relative_path = template.gsub("#{base_dir}/", '')
32
+ m.file relative_path, "app/views/#{relative_path}"
33
+ end
34
+
35
+ # Migrations
36
+ m.migration_template 'create_accounts.rb', 'db/migrate', :migration_file_name => 'create_accounts.rb'
37
+ m.migration_template 'create_user_accounts.rb', 'db/migrate', :migration_file_name => 'create_user_accounts.rb'
38
+ m.migration_template 'add_current_account_id_to_users.rb', 'db/migrate', :migration_file_name => 'add_current_account_id_to_users.rb'
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiny_core_accounts
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Thomas Kadauke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-27 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: tkadauke@imedo.de
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/tiny_core/acts/account.rb
32
+ - lib/tiny_core/acts/user_account.rb
33
+ - lib/tiny_core/controllers/accounts.rb
34
+ - lib/tiny_core/controllers/admin_accounts.rb
35
+ - lib/tiny_core/controllers/application.rb
36
+ - lib/tiny_core/controllers/user_accounts.rb
37
+ - lib/tiny_core/has/accounts.rb
38
+ - lib/tiny_core_accounts.rb
39
+ - rails_generators/tiny_account/templates/account.rb
40
+ - rails_generators/tiny_account/templates/account_test.rb
41
+ - rails_generators/tiny_account/templates/accounts/_form.html.erb
42
+ - rails_generators/tiny_account/templates/accounts/_info.html.erb
43
+ - rails_generators/tiny_account/templates/accounts/_no_account.de.html.erb
44
+ - rails_generators/tiny_account/templates/accounts/_no_account.html.erb
45
+ - rails_generators/tiny_account/templates/accounts/_tabs.html.erb
46
+ - rails_generators/tiny_account/templates/accounts/edit.html.erb
47
+ - rails_generators/tiny_account/templates/accounts/index.html.erb
48
+ - rails_generators/tiny_account/templates/accounts/new.html.erb
49
+ - rails_generators/tiny_account/templates/accounts/show.html.erb
50
+ - rails_generators/tiny_account/templates/accounts_controller.rb
51
+ - rails_generators/tiny_account/templates/accounts_controller_test.rb
52
+ - rails_generators/tiny_account/templates/add_current_account_id_to_users.rb
53
+ - rails_generators/tiny_account/templates/admin/accounts/_index.html.erb
54
+ - rails_generators/tiny_account/templates/admin/accounts/_tabs.html.erb
55
+ - rails_generators/tiny_account/templates/admin/accounts/edit.html.erb
56
+ - rails_generators/tiny_account/templates/admin/accounts/index.html.erb
57
+ - rails_generators/tiny_account/templates/admin/accounts/show.html.erb
58
+ - rails_generators/tiny_account/templates/admin_accounts_controller.rb
59
+ - rails_generators/tiny_account/templates/admin_accounts_controller_test.rb
60
+ - rails_generators/tiny_account/templates/create_accounts.rb
61
+ - rails_generators/tiny_account/templates/create_user_accounts.rb
62
+ - rails_generators/tiny_account/templates/user_account.rb
63
+ - rails_generators/tiny_account/templates/user_account_test.rb
64
+ - rails_generators/tiny_account/templates/user_accounts_controller.rb
65
+ - rails_generators/tiny_account/templates/user_accounts_controller_test.rb
66
+ - rails_generators/tiny_account/tiny_account_generator.rb
67
+ has_rdoc: true
68
+ homepage:
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.7
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Insert description here
101
+ test_files: []
102
+