bucket_maker 0.0.1
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.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/.travis.yml +8 -0
- data/Appraisals +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +115 -0
- data/Rakefile +17 -0
- data/app/controllers/bucket_maker_controller.rb +32 -0
- data/app/controllers/concerns/bucket_maker_concern.rb +23 -0
- data/bucket_maker.gemspec +37 -0
- data/config/routes.rb +14 -0
- data/lib/bucket_maker.rb +8 -0
- data/lib/bucket_maker/bucket.rb +65 -0
- data/lib/bucket_maker/configuration.rb +66 -0
- data/lib/bucket_maker/engine.rb +13 -0
- data/lib/bucket_maker/models/active_recordable.rb +35 -0
- data/lib/bucket_maker/models/bucketable.rb +92 -0
- data/lib/bucket_maker/models/redisable.rb +59 -0
- data/lib/bucket_maker/series.rb +48 -0
- data/lib/bucket_maker/series_maker.rb +80 -0
- data/lib/bucket_maker/version.rb +3 -0
- data/lib/generators/active_record/bucket_maker_generator.rb +90 -0
- data/lib/generators/bucket_maker/bucket_maker_generator.rb +15 -0
- data/lib/generators/bucket_maker/install_generator.rb +16 -0
- data/lib/generators/templates/active_recordable_migration.rb +12 -0
- data/lib/generators/templates/bucket_maker.rb +41 -0
- data/spec/controllers/bucket_maker_controller_spec.rb +112 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +16 -0
- data/spec/dummy/app/assets/javascripts/welcome.js.coffee +3 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/welcome.css.scss +3 -0
- data/spec/dummy/app/controllers/application_controller.rb +12 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/welcome_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/welcome_helper.rb +2 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/user.rb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +16 -0
- data/spec/dummy/app/views/welcome/index.html.erb +2 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +16 -0
- data/spec/dummy/config/boot.rb +9 -0
- data/spec/dummy/config/buckets.yml +35 -0
- data/spec/dummy/config/database.yml +6 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/test.rb +31 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/bucket_maker.rb +41 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/db/migrate/20131223144333_create_users.rb +9 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/factories/factories.rb +8 -0
- data/spec/routing/routes_spec.rb +81 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/unit/bucket_spec.rb +57 -0
- data/spec/unit/bucketable_spec.rb +100 -0
- data/spec/unit/series_maker_spec.rb +91 -0
- data/spec/unit/series_spec.rb +64 -0
- metadata +339 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module BucketMaker
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Creates a BucketMaker initializer"
|
9
|
+
|
10
|
+
def copy_initializer
|
11
|
+
template "bucket_maker.rb", "config/initializers/bucket_maker.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Configure the BucketMaker
|
2
|
+
BucketMaker.configure do |config|
|
3
|
+
# Path Prefix
|
4
|
+
# All the Series, Buckets and Groups can be viewed/edited via a special URI
|
5
|
+
# The path prefix is used to prefix these routes
|
6
|
+
# When set to nil, the routes are not loaded
|
7
|
+
#
|
8
|
+
# Default value - '2bOrNot2B/'
|
9
|
+
# config.path_prefix = '2bOrNot2B/'
|
10
|
+
#
|
11
|
+
# Redis Options
|
12
|
+
# Set the Redis options which can be host, port and db
|
13
|
+
# This takes effect when in module included
|
14
|
+
# in the ActiveModel is BucketMaker::Models::Redisable
|
15
|
+
#
|
16
|
+
# Default value - { host: 'localhost', port: 6379, db: 1 }
|
17
|
+
# config.redis_options = {
|
18
|
+
# host: 'localhost',
|
19
|
+
# port: 6379,
|
20
|
+
# db: 1
|
21
|
+
# }
|
22
|
+
#
|
23
|
+
# Buckets Config File
|
24
|
+
# The configuration file for adding/removing Series, Buckets and Groups
|
25
|
+
#
|
26
|
+
# config.buckets_config_file = 'config/buckets.yml'
|
27
|
+
#
|
28
|
+
# Lazy Load
|
29
|
+
# If false then Bucketize the object on creation
|
30
|
+
# If true then the Bucketization happens on the first call of in_bucket?
|
31
|
+
#
|
32
|
+
# Default value - true
|
33
|
+
# config.lazy_load = true
|
34
|
+
#
|
35
|
+
# Redis Expiration Time
|
36
|
+
# The redis expiration time if the configuration is for Redis
|
37
|
+
#
|
38
|
+
# Default value - 12.months
|
39
|
+
# config.redis_expiration_time = 12.months
|
40
|
+
#
|
41
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
describe BucketMakerController do
|
5
|
+
|
6
|
+
let(:user) { build(:user) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
ApplicationController.any_instance.stub(:set_current_user) { true }
|
10
|
+
controller.instance_variable_set(:@current_user, user)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'with no current user' do
|
14
|
+
before do
|
15
|
+
controller.instance_variable_set(:@current_user, nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'for get group' do
|
19
|
+
before { get :show, series_name: 'test_series_one', bucket_name: 'actual_test_one', group_name: 'group_one'}
|
20
|
+
|
21
|
+
it 'returns failure' do
|
22
|
+
response.should_not be_success
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'for forced set group' do
|
27
|
+
before { post :switch, series_name: 'test_series_one', bucket_name: 'actual_test_one', group_name: 'group_one'}
|
28
|
+
|
29
|
+
it 'returns failure' do
|
30
|
+
response.should_not be_success
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'for randomized set group' do
|
35
|
+
before { post :randomize, series_name: 'test_series_one', bucket_name: 'actual_test_one'}
|
36
|
+
|
37
|
+
it 'returns failure' do
|
38
|
+
response.should_not be_success
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with current user' do
|
44
|
+
context 'with out the correct params' do
|
45
|
+
context 'for get group' do
|
46
|
+
before { get :show, series_name: 'non_existant_series', bucket_name: 'actual_test_one', group_name: 'group_one'}
|
47
|
+
|
48
|
+
it 'returns failure' do
|
49
|
+
response.should_not be_success
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'for forced set group' do
|
54
|
+
before { post :switch, series_name: 'non_existant_series', bucket_name: 'actual_test_one', group_name: 'group_one'}
|
55
|
+
|
56
|
+
it 'returns failure' do
|
57
|
+
response.should_not be_success
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'for randomized set group' do
|
62
|
+
before { post :randomize, series_name: 'non_existant_series', bucket_name: 'actual_test_one'}
|
63
|
+
|
64
|
+
it 'returns failure' do
|
65
|
+
response.should_not be_success
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'for get group' do
|
71
|
+
it 'returns success' do
|
72
|
+
get :show, series_name: 'test_series_one', bucket_name: 'actual_test_one', group_name: 'group_one'
|
73
|
+
response.should be_success
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'for the correct bucket' do
|
77
|
+
before do
|
78
|
+
user.stub(:in_bucket?).with('test_series_one', 'actual_test_one', 'group_one') { true }
|
79
|
+
get :show, series_name: 'test_series_one', bucket_name: 'actual_test_one', group_name: 'group_one'
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'has a true response' do
|
83
|
+
response.body.should include('true')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'for forced set group' do
|
89
|
+
before { post :switch, series_name: 'test_series_one', bucket_name: 'actual_test_one', group_name: 'group_one'}
|
90
|
+
|
91
|
+
it 'returns success' do
|
92
|
+
response.should be_success
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'has a true response' do
|
96
|
+
response.body.should include('true')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'for randomized set group' do
|
101
|
+
before { post :randomize, series_name: 'test_series_one', bucket_name: 'actual_test_one'}
|
102
|
+
|
103
|
+
it 'returns success' do
|
104
|
+
response.should be_success
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'has a true response' do
|
108
|
+
response.body.should include('true')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require jquery
|
14
|
+
//= require jquery_ujs
|
15
|
+
//= require turbolinks
|
16
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
# Prevent CSRF attacks by raising an exception.
|
3
|
+
# For APIs, you may want to use :null_session instead.
|
4
|
+
protect_from_forgery with: :exception
|
5
|
+
|
6
|
+
before_filter :set_current_user
|
7
|
+
|
8
|
+
private
|
9
|
+
def set_current_user
|
10
|
+
@current_user = User.new(id: '123456')
|
11
|
+
end
|
12
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>UsettingsTest</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= javascript_include_tag_for_user_settings %>
|
8
|
+
<%= csrf_meta_tags %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
|
12
|
+
<%= yield %>
|
13
|
+
|
14
|
+
<%= init_user_settings %>
|
15
|
+
</body>
|
16
|
+
</html>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "active_record/railtie"
|
4
|
+
require "action_controller/railtie"
|
5
|
+
require "action_view/railtie"
|
6
|
+
|
7
|
+
Bundler.require(:default, Rails.env)
|
8
|
+
require "bucket_maker"
|
9
|
+
|
10
|
+
module Dummy
|
11
|
+
class Application < Rails::Application
|
12
|
+
# For Ruby 1.9
|
13
|
+
config.encoding = "utf-8"
|
14
|
+
config.secret_key_base = 'Testme'
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
series:
|
2
|
+
test_series_one:
|
3
|
+
description: Some lame description for the Series
|
4
|
+
# created_after: "3rd Jan 2014"
|
5
|
+
buckets:
|
6
|
+
actual_test_one:
|
7
|
+
description: Test One
|
8
|
+
created_after: "1st Jan 2000"
|
9
|
+
distributions:
|
10
|
+
group_one: 0.3
|
11
|
+
group_two: 0.5
|
12
|
+
group_three: 0.2
|
13
|
+
actual_test_two:
|
14
|
+
description: Test Two
|
15
|
+
created_after: "1st Jan 2000"
|
16
|
+
distributions:
|
17
|
+
group_one: 0.7
|
18
|
+
group_two: 0.3
|
19
|
+
test_series_two:
|
20
|
+
description: Some lame description for the Series
|
21
|
+
created_after: "1st Jan 2000"
|
22
|
+
buckets:
|
23
|
+
actual_1test_one:
|
24
|
+
description: Test One
|
25
|
+
created_after: "1st Jan 2000"
|
26
|
+
distributions:
|
27
|
+
group_one: 0.3
|
28
|
+
group_two: 0.5
|
29
|
+
group_three: 0.2
|
30
|
+
actual_1test_two:
|
31
|
+
description: Test Two
|
32
|
+
created_after: "1st Jan 2000"
|
33
|
+
distributions:
|
34
|
+
group_one: 0.7
|
35
|
+
group_two: 0.3
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Dummy::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Do not eager load code on boot. This avoids loading your whole application
|
11
|
+
# just for the purpose of running a single test. If you are using a tool that
|
12
|
+
# preloads Rails for running tests, you may have to set it to true.
|
13
|
+
config.eager_load = false
|
14
|
+
|
15
|
+
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
+
config.serve_static_assets = true
|
17
|
+
config.static_cache_control = "public, max-age=3600"
|
18
|
+
|
19
|
+
# Show full error reports and disable caching.
|
20
|
+
config.consider_all_requests_local = true
|
21
|
+
config.action_controller.perform_caching = false
|
22
|
+
|
23
|
+
# Raise exceptions instead of rendering exception templates.
|
24
|
+
config.action_dispatch.show_exceptions = false
|
25
|
+
|
26
|
+
# Disable request forgery protection in test environment.
|
27
|
+
config.action_controller.allow_forgery_protection = false
|
28
|
+
|
29
|
+
# Print deprecation notices to the stderr.
|
30
|
+
config.active_support.deprecation = :stderr
|
31
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
# Rails.backtrace_cleaner.remove_silencers!
|