paid_up 0.6.5 → 0.7.0

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.
@@ -2,8 +2,10 @@ module PaidUp::Mixins
2
2
  module PaidFor
3
3
  extend ActiveSupport::Concern
4
4
  class_methods do
5
+ def feature
6
+ PaidUp::Feature.find_by_slug(table_name)
7
+ end
5
8
  def paid_for
6
- feature = PaidUp::Feature.find_by_slug(table_name)
7
9
  if feature.nil?
8
10
  raise :feature_not_found_feature.l feature: table_name
9
11
  else
@@ -18,6 +20,54 @@ module PaidUp::Mixins
18
20
  raise :value_is_not_a_valid_setting_type.l(value: feature.setting_type)
19
21
  end
20
22
  end
23
+
24
+ send(:define_method, :owners) do
25
+ User.with_role(:owner, self)
26
+ end
27
+
28
+ send(:define_method, :save_with_owner) do |owner|
29
+ result = save
30
+ if result
31
+ owner.add_role :owner, self
32
+ result
33
+ end
34
+ end
35
+
36
+ send(:define_method, :owners_enabled_count) do
37
+ setting = 0
38
+ for subscriber in owners
39
+ setting += subscriber.plan.feature_setting(self.class.table_name)
40
+ end
41
+ setting
42
+ end
43
+
44
+ send(:define_method, :owners_records) do
45
+ ids = []
46
+ for subscriber in owners
47
+ case self.class.feature.setting_type
48
+ when 'table_rows'
49
+ ids += subscriber.send(self.class.table_name).pluck(:id)
50
+ when 'rolify_rows'
51
+ ids += self.class.with_role(:owner, subscriber).pluck(:id)
52
+ else
53
+ raise :no_features_associated_with_table.l(table: self.class.table_name)
54
+ end
55
+ end
56
+ self.class.where(id: ids)
57
+ end
58
+
59
+ send(:define_method, :owners_records_count) do
60
+ owners_records.count
61
+ end
62
+
63
+ send(:define_method, :enabled?) do
64
+ if owners_enabled_count >= owners_records_count
65
+ true
66
+ else
67
+ enabled_records = owners_records.order('created_at ASC').limit(owners_enabled_count)
68
+ enabled_records.include? self
69
+ end
70
+ end
21
71
  end
22
72
  end
23
73
  end
@@ -51,6 +51,7 @@ module PaidUp::Mixins
51
51
  end
52
52
  end
53
53
  if result
54
+ Rails.cache.delete("#{stripe_id}/stripe_data")
54
55
  reload
55
56
  return true
56
57
  else
@@ -127,7 +128,11 @@ module PaidUp::Mixins
127
128
  end
128
129
  working_stripe_id = stripe_id
129
130
  end
130
- @customer_stripe_data = Stripe::Customer.retrieve working_stripe_id
131
+
132
+ @customer_stripe_data = Rails.cache.fetch("#{working_stripe_id}/stripe_data", expires_in: 12.hours) do
133
+ Stripe::Customer.retrieve working_stripe_id
134
+ end
135
+
131
136
  if @customer_stripe_data.nil?
132
137
  raise :could_not_load_subscription.l
133
138
  end
data/paid_up.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: paid_up 0.6.5 ruby lib
5
+ # stub: paid_up 0.7.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "paid_up"
9
- s.version = "0.6.5"
9
+ s.version = "0.7.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Karen Lundgren"]
14
- s.date = "2015-05-28"
14
+ s.date = "2015-06-03"
15
15
  s.description = "Allows a model of your choosing (such as users) to subscribe to a plan, which enables features."
16
16
  s.email = "karen.e.lundgren@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -148,9 +148,11 @@ Gem::Specification.new do |s|
148
148
  "spec/dummy/public/assets/bootstrap/glyphicons-halflings-regular-e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456.ttf",
149
149
  "spec/dummy/public/assets/bootstrap/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff2",
150
150
  "spec/dummy/public/favicon.ico",
151
+ "spec/factories/group.rb",
151
152
  "spec/factories/plan.rb",
152
153
  "spec/factories/plan_feature_setting.rb",
153
154
  "spec/factories/user.rb",
155
+ "spec/models/group_spec.rb",
154
156
  "spec/models/paid_up/feature_spec.rb",
155
157
  "spec/models/paid_up/plan_feature_setting_spec.rb",
156
158
  "spec/models/paid_up/plan_spec.rb",
@@ -162,6 +164,7 @@ Gem::Specification.new do |s|
162
164
  "spec/spec_helper.rb",
163
165
  "spec/support/controller_macros.rb",
164
166
  "spec/support/factory_girl.rb",
167
+ "spec/support/groups.rb",
165
168
  "spec/support/plans_and_features.rb",
166
169
  "spec/support/stripe.rb",
167
170
  "spec/support/subscribers.rb",
Binary file
@@ -1,7 +1,7 @@
1
1
  class CreateGroupsTable < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :groups do |t|
4
- t.string :name
4
+ t.string :title
5
5
  t.text :description
6
6
 
7
7
  t.timestamps
@@ -22,7 +22,7 @@ ActiveRecord::Schema.define(version: 20150523010840) do
22
22
  add_index "doodads", ["user_id"], name: "index_doodads_on_user_id"
23
23
 
24
24
  create_table "groups", force: :cascade do |t|
25
- t.string "name"
25
+ t.string "title"
26
26
  t.text "description"
27
27
  t.datetime "created_at"
28
28
  t.datetime "updated_at"
Binary file
@@ -3538,3 +3538,244 @@ SQLite3::IOException: disk I/O error: INSERT INTO "schema_migrations" (version)
3538
3538
   (82.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20150406154440')
3539
3539
   (82.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20150523010837')
3540
3540
   (107.2ms) INSERT INTO "schema_migrations" (version) VALUES ('20150523010827')
3541
+  (85.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
3542
+  (0.2ms) select sqlite_version(*)
3543
+  (103.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3544
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
3545
+ Migrating to CreateUsersTable (20150406154440)
3546
+  (0.1ms) begin transaction
3547
+  (0.4ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar)
3548
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150406154440"]]
3549
+  (103.5ms) commit transaction
3550
+ Migrating to CreateGroupsTable (20150517175135)
3551
+  (0.1ms) begin transaction
3552
+ DEPRECATION WARNING: `#timestamp` was called without specifying an option for `null`. In Rails 5, this behavior will change to `null: false`. You should manually specify `null: true` to prevent the behavior of your existing migrations from changing. (called from block in change at /home/work/Gems/paid_up/spec/dummy/db/migrate/20150517175135_create_groups_table.rb:7)
3553
+  (0.5ms) CREATE TABLE "groups" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar, "description" text, "created_at" datetime, "updated_at" datetime)
3554
+ SQL (0.2ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150517175135"]]
3555
+  (95.2ms) commit transaction
3556
+ Migrating to CreateDoodadsTable (20150517175136)
3557
+  (0.1ms) begin transaction
3558
+  (0.3ms) CREATE TABLE "doodads" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" varchar, "name" varchar, "description" text)
3559
+  (0.1ms) CREATE INDEX "index_doodads_on_user_id" ON "doodads" ("user_id")
3560
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150517175136"]]
3561
+  (110.6ms) commit transaction
3562
+ Migrating to AddDeviseToUsers (20150523010827)
3563
+  (0.1ms) begin transaction
3564
+  (0.3ms) ALTER TABLE "users" ADD "email" varchar DEFAULT '' NOT NULL
3565
+  (0.2ms) ALTER TABLE "users" ADD "encrypted_password" varchar DEFAULT '' NOT NULL
3566
+  (0.2ms) ALTER TABLE "users" ADD "reset_password_token" varchar
3567
+  (0.2ms) ALTER TABLE "users" ADD "reset_password_sent_at" datetime
3568
+  (0.2ms) ALTER TABLE "users" ADD "remember_created_at" datetime
3569
+  (0.1ms) ALTER TABLE "users" ADD "sign_in_count" integer DEFAULT 0 NOT NULL
3570
+  (0.1ms) ALTER TABLE "users" ADD "current_sign_in_at" datetime
3571
+  (0.1ms) ALTER TABLE "users" ADD "last_sign_in_at" datetime
3572
+  (0.1ms) ALTER TABLE "users" ADD "current_sign_in_ip" varchar
3573
+  (0.1ms) ALTER TABLE "users" ADD "last_sign_in_ip" varchar
3574
+  (0.1ms) CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")
3575
+  (0.1ms) SELECT sql
3576
+ FROM sqlite_master
3577
+ WHERE name='index_users_on_email' AND type='index'
3578
+ UNION ALL
3579
+ SELECT sql
3580
+ FROM sqlite_temp_master
3581
+ WHERE name='index_users_on_email' AND type='index'
3582
+
3583
+  (0.1ms) CREATE UNIQUE INDEX "index_users_on_reset_password_token" ON "users" ("reset_password_token")
3584
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150523010827"]]
3585
+  (381.7ms) commit transaction
3586
+ Migrating to RolifyCreateRoles (20150523010837)
3587
+  (0.1ms) begin transaction
3588
+ DEPRECATION WARNING: `#timestamp` was called without specifying an option for `null`. In Rails 5, this behavior will change to `null: false`. You should manually specify `null: true` to prevent the behavior of your existing migrations from changing. (called from block in change at /home/work/Gems/paid_up/spec/dummy/db/migrate/20150523010837_rolify_create_roles.rb:7)
3589
+  (0.2ms) CREATE TABLE "roles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "resource_id" integer, "resource_type" varchar, "created_at" datetime, "updated_at" datetime) 
3590
+  (0.1ms) CREATE TABLE "users_roles" ("user_id" integer, "role_id" integer)
3591
+  (0.1ms) CREATE INDEX "index_roles_on_name" ON "roles" ("name")
3592
+  (0.1ms) SELECT sql
3593
+ FROM sqlite_master
3594
+ WHERE name='index_roles_on_name' AND type='index'
3595
+ UNION ALL
3596
+ SELECT sql
3597
+ FROM sqlite_temp_master
3598
+ WHERE name='index_roles_on_name' AND type='index'
3599
+
3600
+  (0.1ms) CREATE INDEX "index_roles_on_name_and_resource_type_and_resource_id" ON "roles" ("name", "resource_type", "resource_id")
3601
+  (0.2ms) CREATE INDEX "index_users_roles_on_user_id_and_role_id" ON "users_roles" ("user_id", "role_id")
3602
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150523010837"]]
3603
+  (119.8ms) commit transaction
3604
+ Migrating to CreatePaidUpPlanFeatureSettingsTable (20150523010838)
3605
+  (0.1ms) begin transaction
3606
+  (0.3ms) CREATE TABLE "paid_up_plan_feature_settings" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "plan_id" integer, "feature" varchar, "setting" integer)
3607
+  (0.2ms) CREATE INDEX "index_paid_up_plan_feature_settings_on_plan_id" ON "paid_up_plan_feature_settings" ("plan_id")
3608
+  (0.1ms) SELECT sql
3609
+ FROM sqlite_master
3610
+ WHERE name='index_paid_up_plan_feature_settings_on_plan_id' AND type='index'
3611
+ UNION ALL
3612
+ SELECT sql
3613
+ FROM sqlite_temp_master
3614
+ WHERE name='index_paid_up_plan_feature_settings_on_plan_id' AND type='index'
3615
+
3616
+  (0.2ms) CREATE INDEX "index_paid_up_plan_feature_settings_on_feature" ON "paid_up_plan_feature_settings" ("feature")
3617
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150523010838"]]
3618
+  (125.0ms) commit transaction
3619
+ Migrating to CreatePaidUpPlansTable (20150523010839)
3620
+  (0.1ms) begin transaction
3621
+ DEPRECATION WARNING: `#timestamp` was called without specifying an option for `null`. In Rails 5, this behavior will change to `null: false`. You should manually specify `null: true` to prevent the behavior of your existing migrations from changing. (called from block in change at /home/work/Gems/paid_up/spec/dummy/db/migrate/20150523010839_create_paid_up_plans_table.paid_up.rb:10)
3622
+  (0.4ms) CREATE TABLE "paid_up_plans" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "stripe_id" varchar, "title" varchar, "description" text, "sort_order" integer, "created_at" datetime, "updated_at" datetime) 
3623
+  (0.2ms) CREATE UNIQUE INDEX "index_paid_up_plans_on_title" ON "paid_up_plans" ("title")
3624
+  (0.1ms)  SELECT sql
3625
+ FROM sqlite_master
3626
+ WHERE name='index_paid_up_plans_on_title' AND type='index'
3627
+ UNION ALL
3628
+ SELECT sql
3629
+ FROM sqlite_temp_master
3630
+ WHERE name='index_paid_up_plans_on_title' AND type='index'
3631
+ 
3632
+  (0.2ms) CREATE UNIQUE INDEX "index_paid_up_plans_on_stripe_id" ON "paid_up_plans" ("stripe_id")
3633
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150523010839"]]
3634
+  (135.4ms) commit transaction
3635
+ Migrating to AddStripeIdColumnToUsers (20150523010840)
3636
+  (0.1ms) begin transaction
3637
+  (0.4ms) ALTER TABLE "users" ADD "stripe_id" varchar
3638
+ SQL (0.1ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150523010840"]]
3639
+  (104.5ms) commit transaction
3640
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
3641
+  (0.1ms) SELECT sql
3642
+ FROM sqlite_master
3643
+ WHERE name='index_doodads_on_user_id' AND type='index'
3644
+ UNION ALL
3645
+ SELECT sql
3646
+ FROM sqlite_temp_master
3647
+ WHERE name='index_doodads_on_user_id' AND type='index'
3648
+
3649
+  (0.1ms)  SELECT sql
3650
+ FROM sqlite_master
3651
+ WHERE name='index_paid_up_plan_feature_settings_on_feature' AND type='index'
3652
+ UNION ALL
3653
+ SELECT sql
3654
+ FROM sqlite_temp_master
3655
+ WHERE name='index_paid_up_plan_feature_settings_on_feature' AND type='index'
3656
+ 
3657
+  (0.1ms) SELECT sql
3658
+ FROM sqlite_master
3659
+ WHERE name='index_paid_up_plan_feature_settings_on_plan_id' AND type='index'
3660
+ UNION ALL
3661
+ SELECT sql
3662
+ FROM sqlite_temp_master
3663
+ WHERE name='index_paid_up_plan_feature_settings_on_plan_id' AND type='index'
3664
+
3665
+  (0.1ms)  SELECT sql
3666
+ FROM sqlite_master
3667
+ WHERE name='index_paid_up_plans_on_stripe_id' AND type='index'
3668
+ UNION ALL
3669
+ SELECT sql
3670
+ FROM sqlite_temp_master
3671
+ WHERE name='index_paid_up_plans_on_stripe_id' AND type='index'
3672
+ 
3673
+  (0.1ms) SELECT sql
3674
+ FROM sqlite_master
3675
+ WHERE name='index_paid_up_plans_on_title' AND type='index'
3676
+ UNION ALL
3677
+ SELECT sql
3678
+ FROM sqlite_temp_master
3679
+ WHERE name='index_paid_up_plans_on_title' AND type='index'
3680
+
3681
+  (0.1ms)  SELECT sql
3682
+ FROM sqlite_master
3683
+ WHERE name='index_roles_on_name_and_resource_type_and_resource_id' AND type='index'
3684
+ UNION ALL
3685
+ SELECT sql
3686
+ FROM sqlite_temp_master
3687
+ WHERE name='index_roles_on_name_and_resource_type_and_resource_id' AND type='index'
3688
+ 
3689
+  (0.1ms) SELECT sql
3690
+ FROM sqlite_master
3691
+ WHERE name='index_roles_on_name' AND type='index'
3692
+ UNION ALL
3693
+ SELECT sql
3694
+ FROM sqlite_temp_master
3695
+ WHERE name='index_roles_on_name' AND type='index'
3696
+
3697
+  (0.1ms)  SELECT sql
3698
+ FROM sqlite_master
3699
+ WHERE name='index_users_on_reset_password_token' AND type='index'
3700
+ UNION ALL
3701
+ SELECT sql
3702
+ FROM sqlite_temp_master
3703
+ WHERE name='index_users_on_reset_password_token' AND type='index'
3704
+ 
3705
+  (0.1ms) SELECT sql
3706
+ FROM sqlite_master
3707
+ WHERE name='index_users_on_email' AND type='index'
3708
+ UNION ALL
3709
+ SELECT sql
3710
+ FROM sqlite_temp_master
3711
+ WHERE name='index_users_on_email' AND type='index'
3712
+
3713
+  (0.1ms)  SELECT sql
3714
+ FROM sqlite_master
3715
+ WHERE name='index_users_roles_on_user_id_and_role_id' AND type='index'
3716
+ UNION ALL
3717
+ SELECT sql
3718
+ FROM sqlite_temp_master
3719
+ WHERE name='index_users_roles_on_user_id_and_role_id' AND type='index'
3720
+ 
3721
+  (104.4ms) CREATE TABLE "doodads" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" varchar, "name" varchar, "description" text) 
3722
+  (0.2ms) select sqlite_version(*)
3723
+  (105.7ms) CREATE INDEX "index_doodads_on_user_id" ON "doodads" ("user_id")
3724
+  (114.7ms) CREATE TABLE "groups" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar, "description" text, "created_at" datetime, "updated_at" datetime)
3725
+  (114.5ms) CREATE TABLE "paid_up_plan_feature_settings" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "plan_id" integer, "feature" varchar, "setting" integer) 
3726
+  (98.2ms) CREATE INDEX "index_paid_up_plan_feature_settings_on_feature" ON "paid_up_plan_feature_settings" ("feature")
3727
+  (0.3ms)  SELECT sql
3728
+ FROM sqlite_master
3729
+ WHERE name='index_paid_up_plan_feature_settings_on_feature' AND type='index'
3730
+ UNION ALL
3731
+ SELECT sql
3732
+ FROM sqlite_temp_master
3733
+ WHERE name='index_paid_up_plan_feature_settings_on_feature' AND type='index'
3734
+ 
3735
+  (113.8ms) CREATE INDEX "index_paid_up_plan_feature_settings_on_plan_id" ON "paid_up_plan_feature_settings" ("plan_id")
3736
+  (107.8ms) CREATE TABLE "paid_up_plans" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "stripe_id" varchar, "title" varchar, "description" text, "sort_order" integer, "created_at" datetime, "updated_at" datetime) 
3737
+  (90.0ms) CREATE UNIQUE INDEX "index_paid_up_plans_on_stripe_id" ON "paid_up_plans" ("stripe_id")
3738
+  (0.2ms)  SELECT sql
3739
+ FROM sqlite_master
3740
+ WHERE name='index_paid_up_plans_on_stripe_id' AND type='index'
3741
+ UNION ALL
3742
+ SELECT sql
3743
+ FROM sqlite_temp_master
3744
+ WHERE name='index_paid_up_plans_on_stripe_id' AND type='index'
3745
+ 
3746
+  (89.1ms) CREATE UNIQUE INDEX "index_paid_up_plans_on_title" ON "paid_up_plans" ("title")
3747
+  (90.0ms) CREATE TABLE "roles" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "resource_id" integer, "resource_type" varchar, "created_at" datetime, "updated_at" datetime) 
3748
+  (98.3ms) CREATE INDEX "index_roles_on_name_and_resource_type_and_resource_id" ON "roles" ("name", "resource_type", "resource_id")
3749
+  (0.3ms)  SELECT sql
3750
+ FROM sqlite_master
3751
+ WHERE name='index_roles_on_name_and_resource_type_and_resource_id' AND type='index'
3752
+ UNION ALL
3753
+ SELECT sql
3754
+ FROM sqlite_temp_master
3755
+ WHERE name='index_roles_on_name_and_resource_type_and_resource_id' AND type='index'
3756
+ 
3757
+  (122.0ms) CREATE INDEX "index_roles_on_name" ON "roles" ("name")
3758
+  (126.6ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "email" varchar DEFAULT '' NOT NULL, "encrypted_password" varchar DEFAULT '' NOT NULL, "reset_password_token" varchar, "reset_password_sent_at" datetime, "remember_created_at" datetime, "sign_in_count" integer DEFAULT 0 NOT NULL, "current_sign_in_at" datetime, "last_sign_in_at" datetime, "current_sign_in_ip" varchar, "last_sign_in_ip" varchar, "stripe_id" varchar) 
3759
+  (122.5ms) CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")
3760
+  (0.3ms)  SELECT sql
3761
+ FROM sqlite_master
3762
+ WHERE name='index_users_on_email' AND type='index'
3763
+ UNION ALL
3764
+ SELECT sql
3765
+ FROM sqlite_temp_master
3766
+ WHERE name='index_users_on_email' AND type='index'
3767
+ 
3768
+  (130.2ms) CREATE UNIQUE INDEX "index_users_on_reset_password_token" ON "users" ("reset_password_token")
3769
+  (106.8ms) CREATE TABLE "users_roles" ("user_id" integer, "role_id" integer) 
3770
+  (106.4ms) CREATE INDEX "index_users_roles_on_user_id_and_role_id" ON "users_roles" ("user_id", "role_id")
3771
+  (95.7ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
3772
+  (91.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
3773
+  (0.3ms) SELECT version FROM "schema_migrations"
3774
+  (106.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20150523010840')
3775
+  (115.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20150523010838')
3776
+  (115.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20150523010839')
3777
+  (115.5ms) INSERT INTO "schema_migrations" (version) VALUES ('20150517175136')
3778
+  (115.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20150517175135')
3779
+  (115.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20150406154440')
3780
+  (173.7ms) INSERT INTO "schema_migrations" (version) VALUES ('20150523010837')
3781
+  (107.4ms) INSERT INTO "schema_migrations" (version) VALUES ('20150523010827')
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :group do
3
+ title 'Test Title'
4
+ end
5
+ end
@@ -0,0 +1,54 @@
1
+ require 'rails_helper'
2
+ require "cancan/matchers"
3
+
4
+ describe Group do
5
+ include_context 'groups'
6
+
7
+ describe '#owners' do
8
+ subject { first_group.owners }
9
+ it { should include group_leader_subscriber }
10
+ it { should_not include professional_subscriber }
11
+ end
12
+
13
+ describe '#save_with_owner' do
14
+ subject {
15
+ new_group = Group.new({title: 'Saved Group'})
16
+ new_group.save_with_owner(professional_subscriber)
17
+ new_group.reload.owners
18
+ }
19
+ it { should include professional_subscriber }
20
+ end
21
+
22
+ describe '#owners_enabled_count' do
23
+ describe 'when limited' do
24
+ subject { first_group.owners_enabled_count }
25
+ it { should eq 1 }
26
+ end
27
+ describe 'when unlimited' do
28
+ subject { second_group.owners_enabled_count }
29
+ it { should eq PaidUp::Unlimited.to_i }
30
+ end
31
+ end
32
+
33
+ describe '#owners_records' do
34
+ subject { second_group.owners_records }
35
+ it { should include third_group }
36
+ it { should_not include first_group }
37
+ end
38
+
39
+ describe '#owners_records_count' do
40
+ subject { second_group.owners_records_count }
41
+ it { should eq 2 }
42
+ end
43
+
44
+ describe '#enabled?' do
45
+ describe 'when true' do
46
+ subject { first_group.enabled? }
47
+ it { should eq true }
48
+ end
49
+ describe 'when false' do
50
+ subject { disabled_group.enabled? }
51
+ it { should eq false }
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,34 @@
1
+ shared_context 'groups' do
2
+ include_context 'subscribers'
3
+
4
+ let!(:first_group) {
5
+ FactoryGirl.create(
6
+ :group,
7
+ title: 'First Group'
8
+ )
9
+ }
10
+ let!(:second_group) {
11
+ FactoryGirl.create(
12
+ :group,
13
+ title: 'Second Group'
14
+ )
15
+ }
16
+ let!(:third_group) {
17
+ FactoryGirl.create(
18
+ :group,
19
+ title: 'Third Group'
20
+ )
21
+ }
22
+ let!(:disabled_group) {
23
+ FactoryGirl.create(
24
+ :group,
25
+ title: 'Disabled Group'
26
+ )
27
+ }
28
+ before do
29
+ group_leader_subscriber.add_role(:owner, first_group)
30
+ group_leader_subscriber.add_role(:owner, disabled_group)
31
+ professional_subscriber.add_role(:owner, second_group)
32
+ professional_subscriber.add_role(:owner, third_group)
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paid_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karen Lundgren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -414,9 +414,11 @@ files:
414
414
  - spec/dummy/public/assets/bootstrap/glyphicons-halflings-regular-e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456.ttf
415
415
  - spec/dummy/public/assets/bootstrap/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff2
416
416
  - spec/dummy/public/favicon.ico
417
+ - spec/factories/group.rb
417
418
  - spec/factories/plan.rb
418
419
  - spec/factories/plan_feature_setting.rb
419
420
  - spec/factories/user.rb
421
+ - spec/models/group_spec.rb
420
422
  - spec/models/paid_up/feature_spec.rb
421
423
  - spec/models/paid_up/plan_feature_setting_spec.rb
422
424
  - spec/models/paid_up/plan_spec.rb
@@ -428,6 +430,7 @@ files:
428
430
  - spec/spec_helper.rb
429
431
  - spec/support/controller_macros.rb
430
432
  - spec/support/factory_girl.rb
433
+ - spec/support/groups.rb
431
434
  - spec/support/plans_and_features.rb
432
435
  - spec/support/stripe.rb
433
436
  - spec/support/subscribers.rb