canary_labs 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcc3e97ef937abda44424f0306fd91b39fadca6092ee66bede1bee079eab3782
4
- data.tar.gz: 34686ffa127d03fcf80b18dfe8b37cc19f6097f47b6f67f10551f695282a982c
3
+ metadata.gz: '078f2fad26d4635f85ac16816ec3c3a06a4e9ef514dfc4d001619aab7b55fcfe'
4
+ data.tar.gz: 6eb10e300a0f83434d26d3a928fdc1efc8e185b493fc93ba581933c7e6a8be88
5
5
  SHA512:
6
- metadata.gz: 1da21a288385eaad82fd85677ce272f31d5637884ae16bb3bc40c3bd3d142807f3d31128a7980691d342890c45d5113091d09b609e140810d9528016f2f033b4
7
- data.tar.gz: 9ad8fde29b0f793b54e396336451496b694740572615a5cd17ff62f01f4d12f709d2562800818c7a819afbff6d6823938f0c4d88e58308351a9688b8b1b56d50
6
+ metadata.gz: d49bb7c90d22730e15bfe9a2fe57205f7548021e7287b88c8323af8412683d99f367fbf89db2aeec727090ed3c6e9b3e1993f8e591081368a33890fead4012ac
7
+ data.tar.gz: '0846f61ad177c82548302eb1477cf364613c11f79cc440c207ebda1ac33a324d538817b792c336cd09075a9bd4b9539c6f03c6778c1b9835aea28ff5aa913f61'
data/lib/canary_labs.rb CHANGED
@@ -1,2 +1,28 @@
1
1
  module CanaryLabs
2
+ mattr_accessor :default_participation
3
+
4
+ def self.setup default_participation: true
5
+ @@experiments = {}
6
+ @@default_participation = default_participation
7
+ end
8
+
9
+ def self.participating? feat_name, id
10
+ experiment = @@experiments[feat_name]
11
+
12
+ return @@default_participation if experiment.nil?
13
+
14
+ experiment.participating? id
15
+ end
16
+
17
+ def self.add name, desc, resolver
18
+ @@experiments[name] = Feature.new name, desc, resolver
19
+ end
20
+
21
+ def self.find name
22
+ @@experiments[name]
23
+ end
24
+
25
+ def self.all
26
+ @@experiments.values
27
+ end
2
28
  end
@@ -1,3 +1,3 @@
1
1
  module CanaryLabs
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+ require 'feature'
3
+ require 'resolvers/group'
4
+
5
+ class CanaryLabsTest < ActiveSupport::TestCase
6
+ setup do
7
+ CanaryLabs.setup
8
+ end
9
+
10
+ test "truth" do
11
+ assert_kind_of Module, CanaryLabs
12
+ end
13
+
14
+ def test_add_feature
15
+ CanaryLabs.add :added_feat, '', CanaryLabs::Resolvers::Group.new([])
16
+
17
+ assert_includes(
18
+ CanaryLabs.all,
19
+ Feature.new(:added_feat, '', CanaryLabs::Resolvers::Group.new([])),
20
+ )
21
+ end
22
+
23
+ def test_find_feature_by_name
24
+ CanaryLabs.add :feat_to_find, '', CanaryLabs::Resolvers::Group.new([])
25
+
26
+ assert_equal(
27
+ Feature.new(:feat_to_find, '', CanaryLabs::Resolvers::Group.new([])),
28
+ CanaryLabs.find(:feat_to_find),
29
+ )
30
+ end
31
+
32
+ def test_participating_by_name
33
+ CanaryLabs.add :feat, '', CanaryLabs::Resolvers::Group.new(['my_id'])
34
+
35
+ assert CanaryLabs.participating? :feat, 'my_id'
36
+ end
37
+
38
+ def test_participating_with_bad_name
39
+ assert CanaryLabs.participating? :bad_name, 'my_id'
40
+ end
41
+
42
+ def test_list_all_feats
43
+ CanaryLabs.add :feat_a, '', CanaryLabs::Resolvers::Group.new([])
44
+
45
+ all_feats = CanaryLabs.all
46
+
47
+ assert_includes all_feats, Feature.new(:feat_a, '', CanaryLabs::Resolvers::Group.new([]))
48
+ end
49
+ end
@@ -0,0 +1,46 @@
1
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
2
+  (1.3ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
3
+  (0.0ms) select sqlite_version(*)
4
+  (0.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
5
+  (0.1ms) SELECT version FROM "schema_migrations"
6
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
7
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
8
+  (0.1ms) begin transaction
9
+ --------------------------------
10
+ CanaryLabsTest: test_add_feature
11
+ --------------------------------
12
+  (0.0ms) rollback transaction
13
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
14
+  (1.1ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
15
+  (0.1ms) select sqlite_version(*)
16
+  (0.9ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
17
+  (0.1ms) SELECT version FROM "schema_migrations"
18
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
19
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
20
+  (0.1ms) begin transaction
21
+ --------------------------------
22
+ CanaryLabsTest: test_add_feature
23
+ --------------------------------
24
+  (0.0ms) rollback transaction
25
+  (0.0ms) begin transaction
26
+ -----------------------------------------
27
+ CanaryLabsTest: test_find_feature_by_name
28
+ -----------------------------------------
29
+  (0.0ms) rollback transaction
30
+  (0.0ms) begin transaction
31
+ --------------------------
32
+ CanaryLabsTest: test_truth
33
+ --------------------------
34
+  (0.0ms) rollback transaction
35
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
36
+  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
37
+  (0.0ms) select sqlite_version(*)
38
+  (0.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
39
+  (0.1ms) SELECT version FROM "schema_migrations"
40
+  (0.7ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
41
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
42
+  (0.1ms) begin transaction
43
+ ------------------------------------------
44
+ CanaryLabsTest: test_participating_by_name
45
+ ------------------------------------------
46
+  (0.0ms) rollback transaction
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canary_labs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davis Kimoto
@@ -50,7 +50,6 @@ files:
50
50
  - Rakefile
51
51
  - lib/canary_labs.rb
52
52
  - lib/canary_labs/version.rb
53
- - lib/experiment_repo.rb
54
53
  - lib/feature.rb
55
54
  - lib/generators/initializer/USAGE
56
55
  - lib/generators/initializer/initializer_generator.rb
@@ -58,8 +57,7 @@ files:
58
57
  - lib/resolvers/group.rb
59
58
  - lib/resolvers/percentage.rb
60
59
  - lib/tasks/canary_labs_tasks.rake
61
- - test/beta_test.rb
62
- - test/betas_test.rb
60
+ - test/canary_labs_test.rb
63
61
  - test/dummy/README.rdoc
64
62
  - test/dummy/Rakefile
65
63
  - test/dummy/app/assets/config/manifest.js
@@ -95,11 +93,12 @@ files:
95
93
  - test/dummy/db/development.sqlite3
96
94
  - test/dummy/db/schema.rb
97
95
  - test/dummy/db/test.sqlite3
96
+ - test/dummy/log/test.log
98
97
  - test/dummy/public/404.html
99
98
  - test/dummy/public/422.html
100
99
  - test/dummy/public/500.html
101
100
  - test/dummy/public/favicon.ico
102
- - test/experiment_repo_test.rb
101
+ - test/feature_test.rb
103
102
  - test/resolvers/group_test.rb
104
103
  - test/resolvers/percentage_test.rb
105
104
  - test/test_helper.rb
@@ -165,10 +164,10 @@ test_files:
165
164
  - test/dummy/db/schema.rb
166
165
  - test/dummy/db/test.sqlite3
167
166
  - test/dummy/db/development.sqlite3
167
+ - test/dummy/log/test.log
168
168
  - test/dummy/README.rdoc
169
169
  - test/resolvers/group_test.rb
170
170
  - test/resolvers/percentage_test.rb
171
- - test/betas_test.rb
172
- - test/experiment_repo_test.rb
171
+ - test/feature_test.rb
173
172
  - test/test_helper.rb
174
- - test/beta_test.rb
173
+ - test/canary_labs_test.rb
@@ -1,30 +0,0 @@
1
- module CanaryLabs
2
- class ExperimentRepo
3
- attr_reader :default_participation
4
-
5
- def initialize default_participation: true
6
- @betas = {}
7
- @default_participation = default_participation
8
- end
9
-
10
- def participating? beta_name, id
11
- b = @betas[beta_name]
12
-
13
- return @default_participation if b.nil?
14
-
15
- b.participating? id
16
- end
17
-
18
- def add name, desc, resolver
19
- @betas[name] = Feature.new name, desc, resolver
20
- end
21
-
22
- def find name
23
- @betas[name]
24
- end
25
-
26
- def all
27
- @betas.values
28
- end
29
- end
30
- end
data/test/betas_test.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class CanaryLabsTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, CanaryLabs
6
- end
7
- end
@@ -1,59 +0,0 @@
1
- require 'test_helper'
2
- require 'experiment_repo'
3
- require 'feature'
4
- require 'resolvers/group'
5
-
6
- module CanaryLabs
7
- class ExperimentRepoTest < ActiveSupport::TestCase
8
- def test_add_beta
9
- repo = new_repo
10
- repo.add :added_beta, '', CanaryLabs::Resolvers::Group.new([])
11
-
12
- assert_includes(
13
- repo.all,
14
- Feature.new(:added_beta, '', CanaryLabs::Resolvers::Group.new([])),
15
- )
16
- end
17
-
18
- def test_find_beta_by_name
19
- repo = new_repo
20
- repo.add :beta_to_find, '', CanaryLabs::Resolvers::Group.new([])
21
-
22
- assert_equal(
23
- Feature.new(:beta_to_find, '', CanaryLabs::Resolvers::Group.new([])),
24
- repo.find(:beta_to_find)
25
- )
26
- end
27
-
28
- def test_participating_by_name
29
- repo = new_repo
30
- repo.add :participatable_beta, '', CanaryLabs::Resolvers::Group.new(['my_id'])
31
-
32
- assert repo.participating? :participatable_beta, 'my_id'
33
- end
34
-
35
- def test_participating_with_bad_name
36
- repo = new_repo
37
-
38
- assert repo.participating? :bad_name, 'my_id'
39
- end
40
-
41
- def test_list_all_betas
42
- repo = new_repo
43
- repo.add :beta_a, '', CanaryLabs::Resolvers::Group.new([])
44
- repo.add :beta_b, '', CanaryLabs::Resolvers::Group.new([])
45
- repo.add :beta_c, '', CanaryLabs::Resolvers::Group.new([])
46
-
47
- all_betas = repo.all
48
-
49
- assert_equal 3, all_betas.length
50
- assert_includes all_betas, Feature.new(:beta_a, '', CanaryLabs::Resolvers::Group.new([]))
51
- end
52
-
53
- private
54
-
55
- def new_repo
56
- CanaryLabs::ExperimentRepo.new
57
- end
58
- end
59
- end