bento 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +62 -42
- data/lib/bento/controllers/account_scopable.rb +31 -2
- data/lib/bento/controllers/helpers.rb +13 -9
- data/lib/bento/models/account.rb +18 -37
- data/lib/bento/models/modules/trial.rb +15 -0
- data/lib/bento/models/modules/user_accessors.rb +26 -0
- data/lib/bento/models/modules/user_association.rb +13 -0
- data/lib/bento/models/modules/validations.rb +14 -0
- data/lib/bento/rails/routes.rb +24 -0
- data/lib/bento/rails.rb +2 -0
- data/lib/bento/version.rb +1 -1
- data/lib/generators/active_record/bento_generator.rb +1 -1
- data/lib/generators/active_record/templates/add_migration.rb +2 -2
- data/lib/generators/active_record/templates/create_migration.rb +4 -5
- data/lib/generators/bento/bento_generator.rb +4 -0
- data/lib/generators/bento/orm_helpers.rb +1 -1
- data/spec/bento/controllers/helpers_spec.rb +24 -0
- data/spec/bento/models/account_spec.rb +5 -95
- data/spec/bento/models/modules/trial_spec.rb +22 -0
- data/spec/bento/models/modules/user_accessors_spec.rb +48 -0
- data/spec/bento/models/modules/user_association_spec.rb +16 -0
- data/spec/bento/models/modules/validations_spec.rb +27 -0
- data/spec/bento/rails/routes_spec.rb +27 -0
- data/spec/bento_spec.rb +4 -0
- data/spec/controllers/bento_for_routes_spec.rb +55 -0
- data/spec/rails_app/app/controllers/custom_accounts_controller.rb +7 -1
- data/spec/rails_app/app/models/account.rb +1 -1
- data/spec/rails_app/app/models/site.rb +8 -0
- data/spec/rails_app/app/models/user.rb +1 -0
- data/spec/rails_app/app/views/custom_accounts/index.html.erb +14 -0
- data/spec/rails_app/app/views/custom_accounts/new.html.erb +11 -7
- data/spec/rails_app/app/views/custom_accounts/show.html.erb +12 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +3 -2
- data/spec/rails_app/app/views/projects/_all_projects.html.erb +1 -0
- data/spec/rails_app/app/views/projects/show.html.erb +1 -0
- data/spec/rails_app/config/routes.rb +6 -1
- data/spec/rails_app/db/development.sqlite3 +0 -0
- data/spec/rails_app/db/migrate/20101029122256_bento_create_sites.rb +14 -0
- data/spec/rails_app/db/migrate/20101029122257_bento_add_site_id_to_sites.rb +9 -0
- data/spec/rails_app/db/schema.rb +10 -1
- data/spec/rails_app/db/test.sqlite3 +0 -0
- data/spec/rails_app/log/development.log +50 -1220
- data/spec/rails_app/{db/production.sqlite3 → log/production.log} +0 -0
- data/spec/rails_app/log/server.log +0 -0
- data/spec/rails_app/log/test.log +32539 -21983
- data/spec/spec_helper.rb +1 -1
- data/spec/support/blueprints.rb +4 -0
- metadata +24 -6
- data/spec/rails_app/tmp/pids/server.pid +0 -1
data/README.rdoc
CHANGED
@@ -1,62 +1,82 @@
|
|
1
1
|
= Bento
|
2
2
|
Bento is a Rails account management engine.
|
3
3
|
|
4
|
-
==
|
5
|
-
|
4
|
+
== Installation
|
5
|
+
Install the gem with bundler:
|
6
|
+
gem install bundler
|
7
|
+
add gem 'bento' to your Gemfile
|
8
|
+
bundle install
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
When you are done, you are ready to add Bento to any of your models using the generator:
|
11
|
+
rails generate bento MODEL
|
12
|
+
rake db:migrate
|
13
|
+
Replace MODEL by the class name you want to use as your account-like model, like Account, Site, etc.
|
14
|
+
This will create a model (if one does not exist) and configure it with default Bento options.
|
15
|
+
The generator will also create a migration file (if you're running ActiveRecord) and configure your routes.
|
13
16
|
|
14
|
-
==
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
class MyController < ApplicationController
|
17
|
+
== Getting started
|
18
|
+
=== Model
|
19
|
+
This is a walkthrough with all steps you need to setup a Bento resource, including model, migration and route files.
|
20
|
+
Bento must be set up within the model (or models) you want to use. Bento routes must be created inside your config/routes.rb file.
|
21
|
+
We're assuming here you want a Account model with the default Bento options.
|
22
|
+
class Account < ActiveRecord::Base
|
23
|
+
bento
|
24
|
+
end
|
25
|
+
Bento doesn't use attr_accessible or attr_protected inside its modules, so be sure to define attributes as accessible or protected in your model.
|
26
|
+
|
27
|
+
=== Routes
|
28
|
+
Configure your routes after setting up your model. Open your config/routes.rb file and add:
|
29
|
+
bento_for :accounts
|
30
|
+
This will use your Account model to create a set of needed routes (you can see them by running `rake routes`).
|
31
|
+
|
32
|
+
This will add bento_for :accounts to your routes file. If you want to add another model just rename or add the argument(s) to bento_for.
|
33
|
+
bento_for :accounts, :sites
|
34
|
+
|
35
|
+
=== Controllers
|
36
|
+
You can tell your controllers to scope your resource to the current account.
|
37
|
+
class AccountsController < Bento::AccountsController
|
36
38
|
scoped_to_account
|
37
39
|
end
|
40
|
+
If you're defining your own controller you must generate views as described below.
|
41
|
+
If your current_user respond to admin? All the actions will only be accessible by users that respond with true.
|
38
42
|
|
39
|
-
===
|
40
|
-
Bento
|
43
|
+
=== Views
|
44
|
+
Bento gives you a complete CRUD for managing accounts. To customize the views use:
|
41
45
|
rails generate bento:views
|
42
|
-
If your current_user respond to admin? These actions will only be accessible by users that respond with true.
|
43
|
-
|
44
|
-
== Configuring controllers
|
45
46
|
|
46
|
-
|
47
|
+
=== Helpers
|
48
|
+
Bento will create the following helpers to use inside your controllers and views:
|
49
|
+
current_account
|
50
|
+
Where account would be anything your model is named.
|
51
|
+
The helper depends on a current_user-helper being defined (as is the case if you're using Devise).
|
47
52
|
|
48
|
-
|
49
|
-
|
53
|
+
=== Override specific pieces
|
54
|
+
The default behavior is to redirect to the accounts show view after creation.
|
55
|
+
This can be changed by overriding the after_create_url method:
|
56
|
+
class AccountsController < Bento::AccountsController
|
57
|
+
protected
|
58
|
+
def after_create_url
|
59
|
+
account_path(resource)
|
50
60
|
end
|
61
|
+
end
|
51
62
|
|
52
|
-
|
53
|
-
|
63
|
+
== Navigating the source
|
64
|
+
The gem has a basic set of cucumber features along with a rails app.
|
65
|
+
Check them out to see some examples on how to use Bento in your application.
|
54
66
|
|
55
|
-
|
67
|
+
== Disclaimer
|
68
|
+
* The gem is still in early beta, be careful.
|
69
|
+
* Forces you to have a User-model.
|
70
|
+
* Only works with Rails 3 and ActiveRecord.
|
56
71
|
|
57
72
|
== Credits and contributors
|
58
|
-
|
59
73
|
* The contributors of the awesome Devise gem from which I've borrowed a lot of ideas and patterns.
|
60
74
|
* Elabs for sponsoring
|
61
75
|
* Jonas Nicklas for helping me boot strap the engine.
|
62
76
|
* All the gems that this gem depends on.
|
77
|
+
|
78
|
+
== TODO:
|
79
|
+
* Be able to nest other routes in bento_for.
|
80
|
+
* Remove the requirement to generate view files when overriding the accounts controller.
|
81
|
+
* Make is possible to have another user model then User.
|
82
|
+
* Make it possible for a user to belong to more then one account.
|
@@ -7,11 +7,40 @@ module Bento
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module InstanceMethods
|
10
|
+
private
|
11
|
+
|
10
12
|
def begin_of_association_chain
|
11
|
-
|
13
|
+
@account ||= current_account
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_account
|
17
|
+
if not_responding_to_admin? or admin?
|
18
|
+
account_by_param_or_session
|
19
|
+
else
|
20
|
+
current_user.account
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def admin?
|
25
|
+
respond_to_admin? and current_user.admin?
|
26
|
+
end
|
27
|
+
|
28
|
+
def not_responding_to_admin?
|
29
|
+
(not respond_to_admin?)
|
30
|
+
end
|
31
|
+
|
32
|
+
def respond_to_admin?
|
33
|
+
current_user.respond_to?(:admin?)
|
12
34
|
end
|
13
35
|
|
14
|
-
|
36
|
+
def account_by_param_or_session
|
37
|
+
if account_id then Account.find(account_id) else current_user.account end
|
38
|
+
end
|
39
|
+
|
40
|
+
def account_id
|
41
|
+
key, value = params.find { |key, value| key.to_s.ends_with?("account_id") }
|
42
|
+
value
|
43
|
+
end
|
15
44
|
end
|
16
45
|
end
|
17
46
|
end
|
@@ -1,17 +1,21 @@
|
|
1
1
|
module Bento
|
2
2
|
module Controllers
|
3
3
|
module Helpers
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
mattr_accessor :resource_names
|
5
|
+
@@resource_names = []
|
6
|
+
|
7
|
+
def self.define_helpers(resource_name)
|
8
|
+
@@resource_names << resource_name.to_s.singularize
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
ActiveSupport.on_load(:action_controller) do
|
11
|
+
@@resource_names.uniq.each do |name|
|
12
|
+
define_method("current_#{name}") do
|
13
|
+
current_user.send(name) if current_user
|
14
|
+
end
|
15
|
+
helper_method "current_#{name}"
|
16
|
+
end
|
17
|
+
end
|
10
18
|
end
|
11
19
|
end
|
12
20
|
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class ActionController::Base
|
16
|
-
include Bento::Controllers::Helpers
|
17
21
|
end
|
data/lib/bento/models/account.rb
CHANGED
@@ -1,53 +1,34 @@
|
|
1
|
+
Dir["#{File.expand_path(File.dirname(__FILE__))}/modules/*.rb"].each {|f| require f}
|
2
|
+
|
1
3
|
module Bento
|
2
4
|
module Models
|
3
5
|
module Account
|
6
|
+
DEFAULT_MODULES = %w[validations user_association]
|
7
|
+
ALL_MODULES = DEFAULT_MODULES + %w[trial user_accessors]
|
8
|
+
|
4
9
|
def self.included(base)
|
5
10
|
base.extend(ClassMethods)
|
6
11
|
end
|
7
12
|
|
8
13
|
module ClassMethods
|
9
|
-
|
10
|
-
|
11
|
-
def bento_account(*options)
|
12
|
-
if extend_with_validations?(options)
|
13
|
-
validates_presence_of :name
|
14
|
-
end
|
15
|
-
|
16
|
-
if extend_with_user_accessors?(options)
|
17
|
-
attr_accessor *USER_ACCESSORS
|
18
|
-
end
|
19
|
-
|
20
|
-
if extend_with_user_association?(options)
|
21
|
-
has_many :users
|
22
|
-
end
|
23
|
-
|
24
|
-
if extend_with_trial?(options)
|
25
|
-
define_method("trial_days_remaining") do
|
26
|
-
created_at.advance(:days => 30).to_date - Date.today
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
if extend_with_user_association?(options) and extend_with_user_accessors?(options)
|
31
|
-
before_validation :build_user, :on => :create
|
32
|
-
|
33
|
-
define_method("build_user") do
|
34
|
-
user_attributes = USER_ACCESSORS.inject({}) { |h, key| h.merge(key => send(key)) }
|
35
|
-
if user_attributes.values.any?
|
36
|
-
@user ||= users.build(user_attributes)
|
37
|
-
@user.tap(&:valid?).errors.each { |attribute, message| errors.add(attribute, message) }
|
38
|
-
@user
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
14
|
+
def bento(*modules)
|
15
|
+
module_names(modules).each { |name| include account_module(name) }
|
42
16
|
end
|
43
17
|
|
44
18
|
private
|
45
19
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
20
|
+
def module_names(modules)
|
21
|
+
if modules.include?(:all)
|
22
|
+
ALL_MODULES
|
23
|
+
elsif modules.empty?
|
24
|
+
DEFAULT_MODULES
|
25
|
+
else
|
26
|
+
modules
|
27
|
+
end
|
28
|
+
end
|
49
29
|
|
50
|
-
|
30
|
+
def account_module(name)
|
31
|
+
"Bento::Models::Modules::#{name.to_s.camelcase}".constantize
|
51
32
|
end
|
52
33
|
end
|
53
34
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bento
|
2
|
+
module Models
|
3
|
+
module Modules
|
4
|
+
module Trial
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
define_method("trial_days_remaining") do
|
8
|
+
created_at.advance(:days => 30).to_date - Date.today
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Bento
|
2
|
+
module Models
|
3
|
+
module Modules
|
4
|
+
module UserAccessors
|
5
|
+
USER_ACCESSORS = [:first_name, :last_name, :email, :password, :password_confirmation]
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.class_eval do
|
9
|
+
include ::Bento::Models::Modules::UserAssociation
|
10
|
+
attr_accessor *USER_ACCESSORS
|
11
|
+
before_validation :build_user, :on => :create
|
12
|
+
|
13
|
+
define_method("build_user") do
|
14
|
+
user_attributes = USER_ACCESSORS.inject({}) { |h, key| h.merge(key => send(key)) }
|
15
|
+
if user_attributes.values.any?
|
16
|
+
@user ||= users.build(user_attributes)
|
17
|
+
@user.tap(&:valid?).errors.each { |attribute, message| errors.add(attribute, message) }
|
18
|
+
@user
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
def bento_for(*resource_names)
|
4
|
+
resource_names.map!(&:to_sym)
|
5
|
+
resource_names.each do |resource_name|
|
6
|
+
Bento::Controllers::Helpers.define_helpers(resource_name)
|
7
|
+
|
8
|
+
resources(resource_name, :controller => account_controller(resource_name)) do
|
9
|
+
collection { get :sign_up }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def account_controller(resource_name)
|
17
|
+
if resource_name == :accounts and not overridden_accounts_contoller? then "bento/accounts" else nil end
|
18
|
+
end
|
19
|
+
|
20
|
+
def overridden_accounts_contoller?
|
21
|
+
File.exist?(Rails.root.join("app", "controllers", "accounts_controller.rb"))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/bento/rails.rb
CHANGED
data/lib/bento/version.rb
CHANGED
@@ -15,7 +15,7 @@ module ActiveRecord
|
|
15
15
|
|
16
16
|
def copy_bento_migration
|
17
17
|
migration_template "create_migration.rb", "db/migrate/bento_create_#{table_name}"
|
18
|
-
migration_template "add_migration.rb", "db/migrate/
|
18
|
+
migration_template "add_migration.rb", "db/migrate/bento_add_#{name}_id_to_#{table_name}"
|
19
19
|
end
|
20
20
|
|
21
21
|
def inject_bento_content
|
@@ -1,6 +1,6 @@
|
|
1
|
-
class
|
1
|
+
class BentoAdd<%= name.classify %>IdTo<%= name.classify %>s < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
add_column :users,
|
3
|
+
add_column :users, :<%= name %>_id, :integer
|
4
4
|
end
|
5
5
|
|
6
6
|
def self.down
|
@@ -1,18 +1,17 @@
|
|
1
|
-
class
|
1
|
+
class BentoCreate<%= name.classify %>s < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
|
-
create_table
|
3
|
+
create_table :<%= name.pluralize %> do |t|
|
4
4
|
t.string :name
|
5
|
-
t.string :plan
|
6
5
|
<% for attribute in attributes -%>
|
7
6
|
t.<%= attribute.type %> :<%= attribute.name %>
|
8
7
|
<% end -%>
|
9
8
|
t.timestamps
|
10
9
|
end
|
11
10
|
|
12
|
-
add_index
|
11
|
+
add_index :<%= name.pluralize %>, :name, :unique => true
|
13
12
|
end
|
14
13
|
|
15
14
|
def self.down
|
16
|
-
drop_table
|
15
|
+
drop_table :<%= name.pluralize %>
|
17
16
|
end
|
18
17
|
end
|
@@ -1,4 +1,28 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class AccountController < ActionController::Base; end
|
4
|
+
|
3
5
|
describe Bento::Controllers::Helpers do
|
6
|
+
subject { AccountController.new }
|
7
|
+
let(:account) { Account.make }
|
8
|
+
let(:site) { Site.make }
|
9
|
+
let(:user) { User.make(:account => account, :site => site) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
AccountController.send(:include, Bento::Controllers::Helpers)
|
13
|
+
subject.stubs(:current_user).returns(user)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ".define_helpers" do
|
17
|
+
it "defines the method current_<resource>" do
|
18
|
+
Bento::Controllers::Helpers.define_helpers(:site)
|
19
|
+
subject.current_site.should == site
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#current_account" do
|
24
|
+
it "returns the current users account" do
|
25
|
+
subject.current_account.should == account
|
26
|
+
end
|
27
|
+
end
|
4
28
|
end
|
@@ -1,23 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
class Bento::AccountTest < ActiveRecord::Base
|
4
|
-
|
5
|
-
|
6
|
-
end
|
7
|
-
class NoOptionsTestAccount < Bento::AccountTest; bento_account; end
|
8
|
-
class AllTestAccount < Bento::AccountTest; bento_account(:all); end
|
9
|
-
class ValidationsTestAccount < Bento::AccountTest; bento_account(:validations); end
|
10
|
-
class UserAccessorsTestAccount < Bento::AccountTest; bento_account(:user_accessors); end
|
11
|
-
class UserAssociationTestAccount < Bento::AccountTest; bento_account(:user_association); end
|
12
|
-
class AllUserTestAccount < Bento::AccountTest; bento_account(:user_accessors, :user_association); end
|
13
|
-
class ServeralOptionsAccessorsTestAccount < Bento::AccountTest; bento_account(:user_accessors, :validations); end
|
14
|
-
class TrialTestAccount < Bento::AccountTest; bento_account(:trial); end
|
3
|
+
class Bento::AccountTest < ActiveRecord::Base; set_table_name("accounts"); end
|
4
|
+
class NoOptionsTestAccount < Bento::AccountTest; bento; end
|
5
|
+
class AllTestAccount < Bento::AccountTest; bento(:all); end
|
6
|
+
class ServeralOptionsAccessorsTestAccount < Bento::AccountTest; bento(:trial, :validations); end
|
15
7
|
|
16
8
|
describe Bento::Models::Account do
|
17
|
-
let(:account_params) do
|
18
|
-
{ :name => "Hashrocket", :first_name => "Obie", :last_name => "Fernandez", :email => "obie@hashrocket.com", :password => "test1234" }
|
19
|
-
end
|
20
|
-
|
21
9
|
context "all" do
|
22
10
|
subject { AllTestAccount.new }
|
23
11
|
it { should be_invalid_without(:name) }
|
@@ -25,64 +13,13 @@ describe Bento::Models::Account do
|
|
25
13
|
it { should respond_to(:users) }
|
26
14
|
it { should respond_to(:trial_days_remaining) }
|
27
15
|
it { should respond_to(:build_user) }
|
28
|
-
|
29
|
-
describe ".build_user" do
|
30
|
-
context "all user attributes are blank" do
|
31
|
-
it "creates the account without the user" do
|
32
|
-
account = AllTestAccount.new(:name => "Elabs")
|
33
|
-
account.save.should be_true
|
34
|
-
User.find_by_account_id(account.id).should be_nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "at least one user attributes is present" do
|
39
|
-
context "successfully creating a user" do
|
40
|
-
subject do
|
41
|
-
account = AllTestAccount.create!(account_params)
|
42
|
-
account.users.first
|
43
|
-
end
|
44
|
-
|
45
|
-
its(:email) { should == "obie@hashrocket.com" }
|
46
|
-
its(:first_name) { should == "Obie" }
|
47
|
-
its(:last_name) { should == "Fernandez" }
|
48
|
-
end
|
49
|
-
|
50
|
-
context "unsuccessfully creating a user" do
|
51
|
-
subject { AllTestAccount.new(account_params.merge(:email => "")).tap(&:valid?) }
|
52
|
-
it { subject.errors.should include(:email) }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "#trial_days_remaining" do
|
58
|
-
subject { TrialTestAccount.create!(:name => "Account", :created_at => 6.days.ago).trial_days_remaining }
|
59
|
-
it("returns the number of days that are left in the trial") { should == 24 }
|
60
|
-
end
|
61
16
|
end
|
62
17
|
|
63
18
|
context "no options" do
|
64
19
|
subject { NoOptionsTestAccount.new }
|
65
20
|
it { should be_invalid_without(:name) }
|
66
|
-
it { should have_user_accessors }
|
67
|
-
it { should respond_to(:users) }
|
68
|
-
it { should respond_to(:trial_days_remaining) }
|
69
|
-
it { should respond_to(:build_user) }
|
70
|
-
end
|
71
|
-
|
72
|
-
context "validations" do
|
73
|
-
subject { ValidationsTestAccount.new }
|
74
|
-
it { should be_invalid_without(:name) }
|
75
21
|
it { should_not have_user_accessors }
|
76
|
-
it {
|
77
|
-
it { should_not respond_to(:trial_days_remaining) }
|
78
|
-
it { should_not respond_to(:build_user) }
|
79
|
-
end
|
80
|
-
|
81
|
-
context "user accessors" do
|
82
|
-
subject { UserAccessorsTestAccount.new }
|
83
|
-
it { should_not be_invalid_without(:name) }
|
84
|
-
it { should have_user_accessors }
|
85
|
-
it { should_not respond_to(:users) }
|
22
|
+
it { should respond_to(:users) }
|
86
23
|
it { should_not respond_to(:trial_days_remaining) }
|
87
24
|
it { should_not respond_to(:build_user) }
|
88
25
|
end
|
@@ -90,36 +27,9 @@ describe Bento::Models::Account do
|
|
90
27
|
context "several options" do
|
91
28
|
subject { ServeralOptionsAccessorsTestAccount.new }
|
92
29
|
it { should be_invalid_without(:name) }
|
93
|
-
it { should have_user_accessors }
|
94
|
-
it { should_not respond_to(:users) }
|
95
|
-
it { should_not respond_to(:trial_days_remaining) }
|
96
|
-
it { should_not respond_to(:build_user) }
|
97
|
-
end
|
98
|
-
|
99
|
-
context "user association" do
|
100
|
-
subject { UserAssociationTestAccount.new }
|
101
|
-
it { should_not be_invalid_without(:name) }
|
102
|
-
it { should_not have_user_accessors }
|
103
|
-
it { should respond_to(:users) }
|
104
|
-
it { should_not respond_to(:trial_days_remaining) }
|
105
|
-
it { should_not respond_to(:build_user) }
|
106
|
-
end
|
107
|
-
|
108
|
-
context "trial" do
|
109
|
-
subject { TrialTestAccount.new }
|
110
|
-
it { should_not be_invalid_without(:name) }
|
111
30
|
it { should_not have_user_accessors }
|
112
31
|
it { should_not respond_to(:users) }
|
113
32
|
it { should respond_to(:trial_days_remaining) }
|
114
33
|
it { should_not respond_to(:build_user) }
|
115
34
|
end
|
116
|
-
|
117
|
-
context "user accessors and user association" do
|
118
|
-
subject { AllUserTestAccount.new }
|
119
|
-
it { should_not be_invalid_without(:name) }
|
120
|
-
it { should have_user_accessors }
|
121
|
-
it { should respond_to(:users) }
|
122
|
-
it { should_not respond_to(:trial_days_remaining) }
|
123
|
-
it { should respond_to(:build_user) }
|
124
|
-
end
|
125
35
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class TrialTestAccount < ActiveRecord::Base
|
4
|
+
set_table_name("accounts")
|
5
|
+
attr_accessible :name, :created_at
|
6
|
+
bento(:trial)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Bento::Models::Modules::Trial do
|
10
|
+
subject { TrialTestAccount.new }
|
11
|
+
it { should_not be_invalid_without(:name) }
|
12
|
+
it { should_not have_user_accessors }
|
13
|
+
it { should_not respond_to(:users) }
|
14
|
+
it { should respond_to(:trial_days_remaining) }
|
15
|
+
it { should_not respond_to(:build_user) }
|
16
|
+
|
17
|
+
describe "#trial_days_remaining" do
|
18
|
+
subject { TrialTestAccount.create!(:name => "Account", :created_at => 6.days.ago).trial_days_remaining }
|
19
|
+
it("returns the number of days that are left in the trial") { should == 24 }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|