fluidfeatures-rails 0.1.0 → 0.1.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.
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-18mode
9
+ - rbx-19mode
10
+ - ruby-head
11
+ #- jruby-head
12
+ - ree
13
+ gemfile:
14
+ - test/testapp/Gemfile
15
+ before_install: cd test/testapp
16
+ # uncomment this line if your project needs to run something other than `rake`:
17
+ script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
+ [![Build Status](https://secure.travis-ci.org/BigFastSite/fluidfeatures-rails.png)](http://travis-ci.org/BigFastSite/fluidfeatures-rails)
2
+
1
3
  fluidfeatures-rails
2
4
  ===================
3
5
 
4
- Rails client for API of FluidFeatures.com
6
+ Rails client for API of FluidFeatures.com
7
+
data/Rakefile CHANGED
@@ -3,10 +3,10 @@ Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rake/testtask'
5
5
 
6
- namespace :test do
7
- Rake::TestTask.new(:all) do |t|
8
- t.libs << "test"
9
- t.pattern = 'test/**/*_test.rb'
10
- t.verbose = true
6
+ task :default => :test
7
+
8
+ task :test do
9
+ Dir.chdir("test/testapp") do
10
+ exec("bundle exec rspec spec")
11
11
  end
12
12
  end
@@ -14,6 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.files = `git ls-files`.split("\n")
15
15
  #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.require_paths = ["lib"]
17
- s.add_dependency "rails", "~>3.0"
17
+ #s.add_dependency "rails", "~>3.0"
18
18
  s.add_dependency "persistent_http", "~>1.0.3"
19
19
  end
@@ -1,5 +1,5 @@
1
1
  module FluidFeatures
2
2
  module Rails
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
@@ -214,13 +214,11 @@ module ActionController
214
214
  # We call user_id to get the current user's unique id.
215
215
  #
216
216
  def fluidfeature(feature_name, defaults={})
217
- @features_hit ||= []
218
- @features_hit << feature_name
219
217
  if defaults === true or defaults === false
220
218
  defaults = { :enabled => defaults }
221
219
  end
222
220
  global_defaults = fluidfeatures_defaults || {}
223
- version = (defaults[:version] || global_defaults[:version]).to_s
221
+ version_name = (defaults[:version] || global_defaults[:version]).to_s
224
222
  if not @features
225
223
  fluidfeatures_retrieve_user_features
226
224
  end
@@ -228,8 +226,8 @@ module ActionController
228
226
  if @features[feature_name].is_a? FalseClass or @features[feature_name].is_a? TrueClass
229
227
  enabled = @features[feature_name]
230
228
  elsif @features[feature_name].is_a? Hash
231
- if @features[feature_name].has_key? version
232
- enabled = @features[feature_name][version]
229
+ if @features[feature_name].has_key? version_name
230
+ enabled = @features[feature_name][version_name]
233
231
  end
234
232
  end
235
233
  end
@@ -239,9 +237,16 @@ module ActionController
239
237
  # Tell FluidFeatures about this amazing new feature...
240
238
  options = Hash.new(defaults)
241
239
  options[:enabled] = enabled
242
- options[:version] = version
243
- ::Rails.logger.error "fluidfeature: #{feature_name.to_s} #{version}"
244
- FluidFeatures::Rails.unknown_feature_hit(feature_name, version, options)
240
+ if options.has_key? :version
241
+ options.remove(:version)
242
+ end
243
+ ::Rails.logger.debug "fluidfeature: seeing feature '#{feature_name.to_s}' (version '#{version_name.to_s}') for the first time."
244
+ FluidFeatures::Rails.unknown_feature_hit(feature_name, version_name, options)
245
+ end
246
+ if enabled
247
+ @features_hit ||= {}
248
+ @features_hit[feature_name] ||= {}
249
+ @features_hit[feature_name][version_name] = {}
245
250
  end
246
251
  enabled
247
252
  end
@@ -0,0 +1,15 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'railties'
5
+ gem 'tzinfo'
6
+ gem 'fluidfeatures-rails', :path => '../..'
7
+ gem "rspec-rails", "~> 2.0"
8
+ gem "fakeweb"
9
+ gem "json_pure"
10
+ gem "json_spec"
@@ -0,0 +1,8 @@
1
+ require "rspec/core/rake_task"
2
+
3
+ task :default => :core
4
+
5
+ RSpec::Core::RakeTask.new(:core) do |spec|
6
+ spec.pattern = 'spec/*/*_spec.rb'
7
+ spec.rspec_opts = ['--backtrace']
8
+ end
@@ -0,0 +1,17 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+ before_filter :authenticate_user
5
+
6
+ # simple authentication. user passes their id
7
+ def authenticate_user
8
+ user_id = params[:user_id]
9
+ unless user_id
10
+ raise "user_id not given"
11
+ end
12
+
13
+ # inform fluidfeatures gem of the user id
14
+ fluidfeatures_set_user_id(user_id)
15
+ end
16
+
17
+ end
@@ -0,0 +1,17 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ enabled_features = []
4
+ # apples is enabled by default
5
+ if fluidfeature("apples", { :enabled => true })
6
+ enabled_features << "apples"
7
+ end
8
+ %w{oranges lemons}.each do |feature_name|
9
+ if fluidfeature(feature_name)
10
+ enabled_features << feature_name
11
+ end
12
+ end
13
+ # render a simple page that is a list of features enabled
14
+ # separated by one space character
15
+ render :inline => enabled_features.join(" ")
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require 'fluidfeatures/rails'
5
+
6
+ module Testapp
7
+ class Application < Rails::Application
8
+ FluidFeatures::Rails.initializer
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Testapp::Application.instance.initialize!
@@ -0,0 +1,9 @@
1
+ Testapp::Application.configure do
2
+ config.cache_classes = true
3
+ config.whiny_nils = true
4
+ config.consider_all_requests_local = true
5
+ config.action_controller.perform_caching = false
6
+ config.action_dispatch.show_exceptions = false
7
+ # Print deprecation notices to the stderr
8
+ config.active_support.deprecation = :stderr
9
+ end
@@ -0,0 +1 @@
1
+ Testapp::Application.config.secret_token = "some secret phrase of at least 30 characters"
@@ -0,0 +1,3 @@
1
+ Testapp::Application.routes.draw do
2
+ root :to => "home#index"
3
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Testapp::Application
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+ require 'fakeweb'
3
+ require 'json'
4
+ require 'json_spec'
5
+
6
+ describe HomeController do
7
+
8
+ describe '#index' do
9
+
10
+ before do
11
+ FakeWeb.register_uri(
12
+ :get,
13
+ File.join(ENV["FLUIDFEATURES_BASEURI"], "/app/123/user/1/features"),
14
+ :body => JSON.generate({}) # no features registered yet
15
+ )
16
+ FakeWeb.register_uri(
17
+ :get,
18
+ File.join(ENV["FLUIDFEATURES_BASEURI"], "/app/123/user/2/features"),
19
+ :body => JSON.generate({
20
+ :apples => false,
21
+ :oranges => true,
22
+ :lemons => true
23
+ })
24
+ )
25
+ [1,2].each do |user_id|
26
+ FakeWeb.register_uri(
27
+ :post,
28
+ File.join(ENV["FLUIDFEATURES_BASEURI"], "/app/123/user/#{user_id.to_s}/features/hit"),
29
+ :body => ""
30
+ )
31
+ end
32
+ end
33
+
34
+ it 'should return only the default enabled features for user 1' do
35
+ get :index, { :user_id => 1 }
36
+ response.response_code.should == 200
37
+ response.body.should == "apples"
38
+
39
+ # Check the call to features hit
40
+ features_hit_request = FakeWeb.last_request
41
+ JsonSpec.exclude_keys("duration")
42
+ features_hit_request.body.should be_json_eql(%({
43
+ "features": {
44
+ "hit": [
45
+ "apples",
46
+ "oranges",
47
+ "lemons"
48
+ ],
49
+ "unknown": {
50
+ // features that we have not seen before
51
+ "apples": {
52
+ "versions": {
53
+ "1": {
54
+ "enabled": true
55
+ }
56
+ }
57
+ },
58
+ "lemons": {
59
+ "versions": {
60
+ "1": {
61
+ "enabled": false
62
+ }
63
+ }
64
+ },
65
+ "oranges": {
66
+ "versions": {
67
+ "1": {
68
+ "enabled": false
69
+ }
70
+ }
71
+ }
72
+ }
73
+ },
74
+ "stats": {
75
+ "fetch": {
76
+ // duration ignored
77
+ },
78
+ "request": {
79
+ // duration ignored
80
+ }
81
+ }
82
+ }))
83
+ end
84
+
85
+ it 'should not return the feature for user 2' do
86
+ get :index, { :user_id => 2 }
87
+ response.response_code.should == 200
88
+ response.body.should == "oranges lemons"
89
+
90
+ # Check the call to features hit
91
+ features_hit_request = FakeWeb.last_request
92
+ JsonSpec.exclude_keys("duration")
93
+ features_hit_request.body.should be_json_eql(%({
94
+ "features": {
95
+ "hit": [
96
+ "apples",
97
+ "oranges",
98
+ "lemons"
99
+ ],
100
+ "unknown": {
101
+ // no unknown features
102
+ }
103
+ },
104
+ "stats": {
105
+ "fetch": {
106
+ // duration ignored
107
+ },
108
+ "request": {
109
+ // duration ignored
110
+ }
111
+ }
112
+ }))
113
+ end
114
+
115
+ end
116
+
117
+ end
118
+
@@ -0,0 +1,8 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ ENV["FLUIDFEATURES_BASEURI"] ||= "http://www.fluidfeatures.com/service"
4
+ ENV["FLUIDFEATURES_APPID"] ||= "123"
5
+ ENV["FLUIDFEATURES_SECRET"] ||= "ssssshhhhhh"
6
+
7
+ require File.expand_path("../../config/environment", __FILE__)
8
+ require 'rspec/rails'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluidfeatures-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-23 00:00:00.000000000 Z
12
+ date: 2012-08-10 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rails
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '3.0'
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: persistent_http
32
16
  requirement: !ruby/object:Gem::Requirement
@@ -51,12 +35,28 @@ extensions: []
51
35
  extra_rdoc_files: []
52
36
  files:
53
37
  - .gitignore
38
+ - .travis.yml
54
39
  - Gemfile
55
40
  - README.md
56
41
  - Rakefile
57
42
  - fluidfeatures-rails.gemspec
58
43
  - lib/fluidfeatures/rails.rb
59
44
  - lib/fluidfeatures/rails/version.rb
45
+ - test/testapp/.gitignore
46
+ - test/testapp/Gemfile
47
+ - test/testapp/Rakefile
48
+ - test/testapp/app/controllers/application_controller.rb
49
+ - test/testapp/app/controllers/home_controller.rb
50
+ - test/testapp/config.ru
51
+ - test/testapp/config/application.rb
52
+ - test/testapp/config/boot.rb
53
+ - test/testapp/config/environment.rb
54
+ - test/testapp/config/environments/test.rb
55
+ - test/testapp/config/initializers/secret_token.rb
56
+ - test/testapp/config/routes.rb
57
+ - test/testapp/script/rails
58
+ - test/testapp/spec/controllers/home_controller_spec.rb
59
+ - test/testapp/spec/spec_helper.rb
60
60
  homepage: https://github.com/BigFastSite/fluidfeatures-rails
61
61
  licenses: []
62
62
  post_install_message: