fluidfeatures-rails 0.4.0 → 0.4.4

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/.gitignore CHANGED
@@ -1,6 +1,8 @@
1
1
  *.gem
2
2
  *.swp
3
3
  .bundle
4
+ .idea
5
+ /.rvmrc
4
6
  Gemfile.lock
5
7
  pkg/*
6
8
  *.rbc
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@fluidfeature-rails --create
data/.travis.yml CHANGED
@@ -1,17 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
3
  - 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
4
  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
5
+ - Gemfile
6
+ script: bundle exec rake spec
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/README.md CHANGED
@@ -1,4 +1,3 @@
1
- [![Build Status](https://secure.travis-ci.org/FluidFeatures/fluidfeatures-rails.png)](http://travis-ci.org/FluidFeatures/fluidfeatures-rails)
2
1
 
3
2
  fluidfeatures-rails
4
3
  ===================
data/Rakefile CHANGED
@@ -1,13 +1,3 @@
1
- require 'bundler'
2
- Bundler::GemHelper.install_tasks
1
+ require 'rspec/core/rake_task'
3
2
 
4
- require 'rake/testtask'
5
-
6
- task :default => :test
7
-
8
- task :test do
9
- Dir.chdir("test/testapp") do
10
- system("bundle update")
11
- exec("bundle exec rspec spec")
12
- end
13
- end
3
+ RSpec::Core::RakeTask.new('spec')
@@ -12,8 +12,13 @@ Gem::Specification.new do |s|
12
12
  s.description = %q{Ruby on Rails client for the FluidFeatures service.}
13
13
  s.rubyforge_project = s.name
14
14
  s.files = `git ls-files`.split("\n")
15
- #s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
16
16
  s.require_paths = ["lib"]
17
- #s.add_dependency "rails", "~>3.0"
18
- s.add_dependency "fluidfeatures", "~>0.4.0" unless ENV["FF_DEV"]
17
+
18
+ s.add_dependency "fluidfeatures", "~>0.4.4" unless ENV["FF_DEV"]
19
+
20
+ s.add_development_dependency('rake', '~> 10.0.2')
21
+ s.add_development_dependency('rspec', '~> 2.12.0')
22
+ s.add_development_dependency('guard-rspec', '~> 2.2.1')
23
+ s.add_development_dependency('rb-inotify', '~> 0.8.8')
19
24
  end
@@ -1,5 +1,5 @@
1
1
  module FluidFeatures
2
2
  module Rails
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.4'
4
4
  end
5
5
  end
@@ -14,7 +14,8 @@ module FluidFeatures
14
14
  # It sets up the before and after request hooks
15
15
  #
16
16
  def self.initializer
17
-
17
+ #fixes class variable state persisted between calls
18
+ @enabled = false
18
19
  #
19
20
  # Without these FluidFeatures credentials we cannot talk to
20
21
  # the FluidFeatures service.
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+ require "fluidfeatures/rails"
3
+
4
+ describe "FluidFeatures controller extensions" do
5
+
6
+ let(:controller) { class DummyController < ActionController::Base; end; DummyController.new }
7
+
8
+ let(:transaction) { mock('transaction', user: mock('user')) }
9
+
10
+ context "API calls" do
11
+
12
+ before(:each) do
13
+ FluidFeatures::Rails.stub!(:enabled).and_return(true)
14
+ controller.ff_transaction = transaction
15
+ end
16
+
17
+ it "#fluidfeature should call #feature_enabled? on transaction" do
18
+ params = ["Feature", "a", true]
19
+ controller.ff_transaction.should_receive(:feature_enabled?).with(*params)
20
+ controller.fluidfeature(*params)
21
+ end
22
+
23
+ it "#fluidfeature should call #feature_enabled? on transaction without version" do
24
+ controller.ff_transaction.should_receive(:feature_enabled?).with("Feature", nil, true)
25
+ controller.fluidfeature("Feature", true)
26
+ end
27
+
28
+ it "#fluidgoal should call #goal_hit on transaction" do
29
+ controller.ff_transaction.should_receive(:goal_hit).with("Goal", nil)
30
+ controller.fluidgoal("Goal")
31
+ end
32
+
33
+ end
34
+
35
+ context "#fluidfeatures_initialize_user" do
36
+
37
+ before(:each) do
38
+ transaction.user.stub!(:anonymous).and_return(true)
39
+ transaction.user.stub!(:unique_id).and_return("unique id")
40
+ controller.stub!(:fluidfeatures_current_user).and_return({})
41
+ controller.cookies.stub!(:[]).with(:fluidfeatures_anonymous).and_return("anonymous id")
42
+ controller.stub!(:request).and_return(mock("request", protocol: 'http://', host_with_port: 'example.com', fullpath: '/'))
43
+ FluidFeatures::Rails.ff_app = mock('app')
44
+ FluidFeatures::Rails.ff_app.stub!(:user_transaction).and_return(transaction)
45
+ end
46
+
47
+ it "should log error if not #fluidfeature_current_user defined" do
48
+ controller.unstub!(:fluidfeatures_current_user)
49
+ Rails.logger.should_receive(:error).with("[FF] Method fluidfeatures_current_user is not defined in your ApplicationController")
50
+ controller.fluidfeatures_initialize_user.should == nil
51
+ end
52
+
53
+ it "should get user id from cookies if not set" do
54
+ controller.cookies.should_receive(:[]).with(:fluidfeatures_anonymous).and_return("anonymous id")
55
+ controller.fluidfeatures_initialize_user
56
+ end
57
+
58
+ it "should update cookie for anonymous user" do
59
+ controller.cookies.should_receive(:[]=).with(:fluidfeatures_anonymous, "unique id")
60
+ controller.fluidfeatures_initialize_user
61
+ end
62
+
63
+ it "should delete cookie for existing user" do
64
+ transaction.user.stub!(:anonymous).and_return(false)
65
+ controller.cookies.stub!(:has_key?).with(:fluidfeatures_anonymous).and_return(true)
66
+ controller.cookies.should_receive(:delete).with(:fluidfeatures_anonymous)
67
+ controller.fluidfeatures_initialize_user
68
+ end
69
+
70
+ it "should call #user_transaction on app with valid params" do
71
+ FluidFeatures::Rails.ff_app.should_receive(:user_transaction).with("anonymous id", "http://example.com/", nil, false, nil, nil)
72
+ controller.fluidfeatures_initialize_user
73
+ end
74
+
75
+ end
76
+
77
+ it "#fluidfeatures_request_before should initialize user transaction" do
78
+ transaction = mock("transaction")
79
+ controller.should_receive(:fluidfeatures_initialize_user).and_return(transaction)
80
+ controller.fluidfeatures_request_before
81
+ controller.ff_transaction.should == transaction
82
+ end
83
+
84
+ it "#fluidfeatures_request_after should end transaction" do
85
+ controller.ff_transaction = mock("transaction")
86
+ controller.ff_transaction.should_receive(:end_transaction)
87
+ controller.fluidfeatures_request_after
88
+ end
89
+
90
+ it "#fluidfeatures_retrieve_user_features should return user transaction features" do
91
+ features = []
92
+ controller.ff_transaction = mock("transaction")
93
+ controller.ff_transaction.should_receive(:features).and_return(features)
94
+ controller.fluidfeatures_retrieve_user_features.should eq(features)
95
+ end
96
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+ require "fluidfeatures/rails/app/controllers/fluidfeatures_controller"
3
+
4
+ describe "FluidFeatures Features controller" do
5
+ let(:controller) { FluidFeatureAjaxController.new }
6
+
7
+ it "should call #fluidfeature and render on index" do
8
+ controller.update_params(feature_name: "Feature", version_name: "a")
9
+ controller.should_receive(:fluidfeature).with("Feature", "a")
10
+ controller.should_receive(:render)
11
+ controller.index
12
+ end
13
+ end
14
+
15
+ describe "FluidFeatures Goals controller" do
16
+ let(:controller) { FluidGoalAjaxController.new }
17
+
18
+ it "should call #fluidgoal and render on index" do
19
+ controller.update_params(goal_name: "Goal", goal_version: "default")
20
+ controller.should_receive(:fluidgoal).with("Goal", "default")
21
+ controller.should_receive(:render)
22
+ controller.index
23
+ end
24
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+ require "fluidfeatures/rails"
3
+
4
+ describe "FluidFeatures Rails initialization" do
5
+ CONFIG_KEYS = %w[FLUIDFEATURES_BASEURI FLUIDFEATURES_SECRET FLUIDFEATURES_APPID]
6
+
7
+ before(:each) do
8
+ CONFIG_KEYS.each {|k| ENV[k] = k}
9
+ end
10
+
11
+ CONFIG_KEYS.each do |key|
12
+ it "should require #{key} environment variable" do
13
+ ENV[key] = nil
14
+ $stderr.should_receive(:puts).with("!! fluidfeatures-rails requires ENV[\"#{key}\"] (fluidfeatures is disabled)")
15
+ FluidFeatures::Rails.initializer
16
+ FluidFeatures::Rails.enabled.should be_false
17
+ end
18
+ end
19
+
20
+ it "should start application if Rails defined" do
21
+ defined?(Rails).should be_true
22
+ $stderr.should_receive(:puts).with("=> fluidfeatures-rails initializing as app #{ENV["FLUIDFEATURES_APPID"]} with #{ENV["FLUIDFEATURES_BASEURI"]}")
23
+ FluidFeatures::Rails.initializer
24
+ FluidFeatures::Rails.enabled.should be_true
25
+ end
26
+
27
+ describe "on :action_controller load" do
28
+ let(:on_load) { ActiveSupport.on_load_block }
29
+
30
+ before(:each) do
31
+ $stderr.stub!(:puts)
32
+ FluidFeatures.stub!(:app)
33
+ ActionController::Base.stub!(:append_before_filter)
34
+ ActionController::Base.stub!(:append_after_filter)
35
+ FluidFeatures::Rails.initializer
36
+ end
37
+
38
+ it "should create app with passed credentials" do
39
+ @app = mock("app")
40
+ FluidFeatures.should_receive(:app).with(ENV["FLUIDFEATURES_BASEURI"], ENV["FLUIDFEATURES_APPID"], ENV["FLUIDFEATURES_SECRET"]).and_return(@app)
41
+ instance_eval &on_load
42
+ FluidFeatures::Rails.ff_app.should == @app
43
+ end
44
+
45
+ it "should add :fluidfeatures_request_before to before filter chain" do
46
+ ActionController::Base.should_receive(:append_before_filter).with(:fluidfeatures_request_before)
47
+ instance_eval &on_load
48
+ end
49
+
50
+ it "should add :fluidfeatures_request_after to after filter chain" do
51
+ ActionController::Base.should_receive(:append_after_filter).with(:fluidfeatures_request_after)
52
+ instance_eval &on_load
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+ require "fluidfeatures/rails/config/routes"
3
+
4
+ describe "FluidFeatures routes" do
5
+ let(:routes) { Rails::Routes.routes_block }
6
+
7
+ it "should be added for feature by name" do
8
+ stub!(:match)
9
+ should_receive(:match).with("/fluidfeature/:feature_name"=> "fluid_feature_ajax#index")
10
+ instance_eval &routes
11
+ end
12
+
13
+ it "should be added for goal by name" do
14
+ stub!(:match)
15
+ should_receive(:match).with("/fluidgoal/:goal_name" => "fluid_goal_ajax#index")
16
+ instance_eval &routes
17
+ end
18
+
19
+ it "should be added for goal by name and version" do
20
+ stub!(:match)
21
+ should_receive(:match).with("/fluidgoal/:goal_name/:goal_version" => "fluid_goal_ajax#index")
22
+ instance_eval &routes
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+
8
+ # Run specs in random order to surface order dependencies. If you find an
9
+ # order dependency and want to debug it, you can fix the order by providing
10
+ # the seed, which is printed after each run.
11
+ # --seed 1234
12
+ config.order = 'random'
13
+ end
@@ -0,0 +1,10 @@
1
+ module ActionController
2
+ class Base
3
+ def self.helper_method(*attrs)
4
+ end
5
+
6
+ def cookies
7
+ @cookies ||= {}
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class ActiveSupport
2
+ def self.on_load(name, &block)
3
+ @@on_load_block = block
4
+ end
5
+
6
+ def self.on_load_block
7
+ @@on_load_block
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class ApplicationController
2
+ def params
3
+ @params ||={}
4
+ end
5
+
6
+ def update_params(p)
7
+ @params = p
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module Rails
2
+ class Routes
3
+ def draw(&block)
4
+ @@routes_block = block
5
+ end
6
+
7
+ def self.routes_block
8
+ @@routes_block
9
+ end
10
+ end
11
+
12
+ class Application
13
+ def routes
14
+ Routes.new
15
+ end
16
+
17
+ def self.initializer(initializer_name, &block)
18
+ block.call
19
+ end
20
+ end
21
+
22
+ def self.application
23
+ Application.new
24
+ end
25
+
26
+ def self.logger
27
+ @@logger ||= Object.new
28
+ end
29
+ end
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.4.0
4
+ version: 0.4.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-04 00:00:00.000000000 Z
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fluidfeatures
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.4.0
21
+ version: 0.4.4
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,71 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.4.0
29
+ version: 0.4.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 10.0.2
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.0.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.12.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.2.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.2.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: rb-inotify
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.8.8
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.8.8
30
94
  description: Ruby on Rails client for the FluidFeatures service.
31
95
  email:
32
96
  - phil@fluidfeatures.com
@@ -35,8 +99,10 @@ extensions: []
35
99
  extra_rdoc_files: []
36
100
  files:
37
101
  - .gitignore
102
+ - .rvmrc
38
103
  - .travis.yml
39
104
  - Gemfile
105
+ - Guardfile
40
106
  - LICENSE
41
107
  - README.md
42
108
  - Rakefile
@@ -46,21 +112,15 @@ files:
46
112
  - lib/fluidfeatures/rails/config/routes.rb
47
113
  - lib/fluidfeatures/rails/version.rb
48
114
  - lib/pre_ruby192/uri.rb
49
- - test/testapp/.gitignore
50
- - test/testapp/Gemfile
51
- - test/testapp/Rakefile
52
- - test/testapp/app/controllers/application_controller.rb
53
- - test/testapp/app/controllers/home_controller.rb
54
- - test/testapp/config.ru
55
- - test/testapp/config/application.rb
56
- - test/testapp/config/boot.rb
57
- - test/testapp/config/environment.rb
58
- - test/testapp/config/environments/test.rb
59
- - test/testapp/config/initializers/secret_token.rb
60
- - test/testapp/config/routes.rb
61
- - test/testapp/script/rails
62
- - test/testapp/spec/controllers/home_controller_spec.rb
63
- - test/testapp/spec/spec_helper.rb
115
+ - spec/controller_extentions_spec.rb
116
+ - spec/controller_spec.rb
117
+ - spec/initializer_spec.rb
118
+ - spec/routes_spec.rb
119
+ - spec/spec_helper.rb
120
+ - spec/support/action_controller/base.rb
121
+ - spec/support/active_support.rb
122
+ - spec/support/application_controller.rb
123
+ - spec/support/rails.rb
64
124
  homepage: https://github.com/FluidFeatures/fluidfeatures-rails
65
125
  licenses: []
66
126
  post_install_message:
@@ -1,15 +0,0 @@
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
data/test/testapp/Gemfile DELETED
@@ -1,18 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rake'
4
- gem 'railties'
5
- gem 'tzinfo'
6
- if ENV["FF_DEV"] and File.directory? '../../../fluidfeatures-ruby'
7
- # (used this for development of the fluidfeature gems)
8
- gem 'fluidfeatures', :path => '../../../fluidfeatures-ruby'
9
- end
10
- gem 'fluidfeatures-rails', :path => '../..'
11
- gem "rspec-rails", "~> 2.0"
12
- gem "fakeweb"
13
- gem "json_pure"
14
- gem "json_spec"
15
-
16
- # JRuby Rails requires this for active_support/message_encryptor.rb
17
- gem 'jruby-openssl', :platforms => :jruby
18
-
@@ -1,8 +0,0 @@
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
@@ -1,16 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
-
3
- # simple authentication. user passes their id
4
- def authenticate_user
5
- params[:user_id]
6
- end
7
-
8
- def current_user_id
9
- @current_user_id ||= authenticate_user
10
- end
11
-
12
- def fluidfeature_current_user(verbose=false)
13
- { :id => current_user_id }
14
- end
15
-
16
- end
@@ -1,17 +0,0 @@
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
@@ -1,10 +0,0 @@
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
@@ -1,6 +0,0 @@
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'])
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- Testapp::Application.instance.initialize!
@@ -1,9 +0,0 @@
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
@@ -1 +0,0 @@
1
- Testapp::Application.config.secret_token = "some secret phrase of at least 30 characters"
@@ -1,3 +0,0 @@
1
- Testapp::Application.routes.draw do
2
- root :to => "home#index"
3
- end
@@ -1,4 +0,0 @@
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
@@ -1,6 +0,0 @@
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'
@@ -1,133 +0,0 @@
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?anonymous=?false"),
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?anonymous=false"),
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", "ff_latency")
42
- features_hit_request.body.should be_json_eql(%({
43
- "user": {
44
- "id": "1"
45
- },
46
- "hits": {
47
- "feature": {
48
- "apples": {
49
- "default": {}
50
- }
51
- },
52
- "goal": {
53
- }
54
- },
55
- "features": {
56
- "unknown": {
57
- // features that we have not seen before
58
- "apples": {
59
- "versions": {
60
- "default": {
61
- "enabled": true
62
- }
63
- }
64
- },
65
- "lemons": {
66
- "versions": {
67
- "default": {
68
- "enabled": false
69
- }
70
- }
71
- },
72
- "oranges": {
73
- "versions": {
74
- "default": {
75
- "enabled": false
76
- }
77
- }
78
- }
79
- }
80
- },
81
- "stats": {
82
- "ff_latency": 1,
83
- "request": {
84
- // duration ignored
85
- }
86
- },
87
- "url": "http://test.host/?user_id=1"
88
- }))
89
- end
90
-
91
- it 'should not return the feature for user 2' do
92
- get :index, { :user_id => 2 }
93
- response.response_code.should == 200
94
- response.body.should == "oranges lemons"
95
-
96
- # Check the call to features hit
97
- features_hit_request = FakeWeb.last_request
98
- JsonSpec.exclude_keys("duration", "ff_latency")
99
- features_hit_request.body.should be_json_eql(%({
100
- "user": {
101
- "id": "2"
102
- },
103
- "hits": {
104
- "feature": {
105
- "oranges": {
106
- "default": {}
107
- },
108
- "lemons": {
109
- "default": {}
110
- }
111
- },
112
- "goal": {
113
- }
114
- },
115
- "features": {
116
- "unknown": {
117
- // no unknown features
118
- }
119
- },
120
- "stats": {
121
- "ff_latency": 1,
122
- "request": {
123
- // duration ignored
124
- }
125
- },
126
- "url": "http://test.host/?user_id=2"
127
- }))
128
- end
129
-
130
- end
131
-
132
- end
133
-
@@ -1,8 +0,0 @@
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'