micro_sessions 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Appraisals ADDED
@@ -0,0 +1,9 @@
1
+ appraise "rails-3.0" do
2
+ gem "rails", "~> 3.0.12"
3
+ gem "micro_sessions", :path => "../"
4
+ end
5
+
6
+ appraise "rails-3.1" do
7
+ gem "rails", "~> 3.1.4"
8
+ gem "micro_sessions", :path => "../"
9
+ end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,135 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ micro_sessions (0.1.1)
5
+ rails (>= 3.0.0, < 3.2.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.12)
12
+ actionpack (= 3.0.12)
13
+ mail (~> 2.2.19)
14
+ actionpack (3.0.12)
15
+ activemodel (= 3.0.12)
16
+ activesupport (= 3.0.12)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.5.0)
20
+ rack (~> 1.2.5)
21
+ rack-mount (~> 0.6.14)
22
+ rack-test (~> 0.5.7)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.12)
25
+ activesupport (= 3.0.12)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.5.0)
28
+ activerecord (3.0.12)
29
+ activemodel (= 3.0.12)
30
+ activesupport (= 3.0.12)
31
+ arel (~> 2.0.10)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.12)
34
+ activemodel (= 3.0.12)
35
+ activesupport (= 3.0.12)
36
+ activesupport (3.0.12)
37
+ addressable (2.2.7)
38
+ appraisal (0.4.1)
39
+ bundler
40
+ rake
41
+ arel (2.0.10)
42
+ builder (2.1.2)
43
+ capybara (1.1.2)
44
+ mime-types (>= 1.16)
45
+ nokogiri (>= 1.3.3)
46
+ rack (>= 1.0.0)
47
+ rack-test (>= 0.5.4)
48
+ selenium-webdriver (~> 2.0)
49
+ xpath (~> 0.1.4)
50
+ childprocess (0.3.1)
51
+ ffi (~> 1.0.6)
52
+ cucumber (1.0.6)
53
+ builder (>= 2.1.2)
54
+ diff-lcs (>= 1.1.2)
55
+ gherkin (~> 2.4.18)
56
+ json (>= 1.4.6)
57
+ term-ansicolor (>= 1.0.6)
58
+ diff-lcs (1.1.3)
59
+ erubis (2.6.6)
60
+ abstract (>= 1.0.0)
61
+ ffi (1.0.11)
62
+ gherkin (2.4.21)
63
+ json (>= 1.4.6)
64
+ i18n (0.5.0)
65
+ json (1.6.6)
66
+ launchy (2.1.0)
67
+ addressable (~> 2.2.6)
68
+ mail (2.2.19)
69
+ activesupport (>= 2.3.6)
70
+ i18n (>= 0.4.0)
71
+ mime-types (~> 1.16)
72
+ treetop (~> 1.4.8)
73
+ mime-types (1.18)
74
+ multi_json (1.2.0)
75
+ nokogiri (1.5.2)
76
+ polyglot (0.3.3)
77
+ rack (1.2.5)
78
+ rack-mount (0.6.14)
79
+ rack (>= 1.0.0)
80
+ rack-test (0.5.7)
81
+ rack (>= 1.0)
82
+ rails (3.0.12)
83
+ actionmailer (= 3.0.12)
84
+ actionpack (= 3.0.12)
85
+ activerecord (= 3.0.12)
86
+ activeresource (= 3.0.12)
87
+ activesupport (= 3.0.12)
88
+ bundler (~> 1.0)
89
+ railties (= 3.0.12)
90
+ railties (3.0.12)
91
+ actionpack (= 3.0.12)
92
+ activesupport (= 3.0.12)
93
+ rake (>= 0.8.7)
94
+ rdoc (~> 3.4)
95
+ thor (~> 0.14.4)
96
+ rake (0.9.2.2)
97
+ rdoc (3.12)
98
+ json (~> 1.4)
99
+ rspec (2.9.0)
100
+ rspec-core (~> 2.9.0)
101
+ rspec-expectations (~> 2.9.0)
102
+ rspec-mocks (~> 2.9.0)
103
+ rspec-core (2.9.0)
104
+ rspec-expectations (2.9.0)
105
+ diff-lcs (~> 1.1.3)
106
+ rspec-mocks (2.9.0)
107
+ rubyzip (0.9.6.1)
108
+ selenium-webdriver (2.20.0)
109
+ childprocess (>= 0.2.5)
110
+ ffi (~> 1.0)
111
+ multi_json (~> 1.0)
112
+ rubyzip
113
+ sqlite3 (1.3.5)
114
+ term-ansicolor (1.0.7)
115
+ thor (0.14.6)
116
+ treetop (1.4.10)
117
+ polyglot
118
+ polyglot (>= 0.3.1)
119
+ tzinfo (0.3.32)
120
+ xpath (0.1.4)
121
+ nokogiri (~> 1.3)
122
+
123
+ PLATFORMS
124
+ ruby
125
+
126
+ DEPENDENCIES
127
+ appraisal (~> 0.4.0)
128
+ capybara (~> 1.1.0)
129
+ cucumber (~> 1.0.4)
130
+ launchy
131
+ micro_sessions!
132
+ rake
133
+ rdoc (~> 3.12)
134
+ rspec (~> 2.0)
135
+ sqlite3 (~> 1.3.4)
data/README.rdoc CHANGED
@@ -1,3 +1,5 @@
1
+ {<img src="https://secure.travis-ci.org/rubiety/micro_sessions.png?branch=master" alt="Build Status" />}[http://travis-ci.org/rubiety/micro_sessions]
2
+
1
3
  == Micro Sessions
2
4
 
3
5
  In terms of passing data amongst HTTP requests there are really two options:
@@ -5,7 +7,7 @@ In terms of passing data amongst HTTP requests there are really two options:
5
7
  * Storing in cookies
6
8
  * Storing in server-side session, keyed off an ID stored as a cookie.
7
9
 
8
- For a certain application where you're using number 3, this comes at a cost - the session is "global". In other words, in a single browser window with multiple tabs, the server side cannot distinguish between individual "sessions" *within* that browser session. This gem introduces a third, more granular method:
10
+ For a certain application where you're using number 3, this comes at a cost - the session is "global". In other words, in a single browser window with multiple tabs, the server side cannot distinguish between individual "sessions" *within* that browser session. This gem introduces a fourth, more granular method:
9
11
  * Storing in server-side session, keyed off an ID stored as a cookie *and* keyed off a request parameter.
10
12
 
11
13
  This could be useful in instances such as a very complex wizard where transmitting the entire history of data RESTfully via param passing may not be feasible, yet you'd still like to support multiple tabs within the same browser window separately.
@@ -18,6 +20,8 @@ Include the gem in your Gemfile:
18
20
 
19
21
  gem "micro_sessions"
20
22
 
23
+ NOTE: This gem currently only works with rails 3.0 and rails 3.1, but *not* rails 3.2, due to an issue with overriding url_for. If you want to help with this, see issue #1.
24
+
21
25
  == Usage
22
26
 
23
27
  Simply include the middleware in your controller:
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+ require 'cucumber/rake/task'
7
+ require 'appraisal'
8
+
9
+ Bundler::GemHelper.install_tasks
10
+
11
+ desc 'Default: run unit tests.'
12
+ task :default => [:clean, :all]
13
+
14
+ desc "Run Specs against all Appraisals"
15
+ task :all => :spec do
16
+ Rake::Task["appraisal:install"].execute
17
+ system("bundle exec rake -s appraisal test")
18
+ end
19
+
20
+ desc "Run Specs"
21
+ RSpec::Core::RakeTask.new(:spec) do |t|
22
+ end
23
+
24
+ task :test => [:spec, :cucumber]
25
+
26
+ Cucumber::Rake::Task.new(:cucumber) do |t|
27
+ t.fork = true
28
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
29
+ end
30
+
31
+ desc "Clean up files."
32
+ task :clean do |t|
33
+ FileUtils.rm_rf "tmp"
34
+ Dir.glob("spec/db/*.sqlite3").each {|f| FileUtils.rm f }
35
+ Dir.glob("micro_sessions-*.gem").each {|f| FileUtils.rm f }
36
+ end
37
+
@@ -1,13 +1,6 @@
1
- unless defined?(ActionController)
2
- begin
3
- require "action_pack"
4
- require "action_controller"
5
- require "action_view"
6
- rescue LoadError
7
- require "rubygems"
8
- require_gem "actionpack"
9
- end
10
- end
1
+ require "rails"
2
+ require "action_controller"
3
+ require "action_view"
11
4
 
12
5
  module MicroSessions
13
6
  extend ActiveSupport::Concern
@@ -13,7 +13,7 @@ module MicroSessions
13
13
  options[:length] ||= 10
14
14
  options[:counter] ||= 1
15
15
 
16
- class_inheritable_accessor :micro_session_options
16
+ class_attribute :micro_session_options
17
17
  self.micro_session_options = options
18
18
 
19
19
  class_eval do
@@ -27,4 +27,4 @@ module MicroSessions
27
27
  end
28
28
  end
29
29
  end
30
- end
30
+ end
@@ -2,25 +2,21 @@ module MicroSessions
2
2
  module Helpers
3
3
  module UrlHelper
4
4
  extend ActiveSupport::Concern
5
-
6
- module InstanceMethods
7
- def url_for(options = {})
8
- if options.is_a?(Hash) && ms_value = options.delete(:micro_sessions) && !micro_session.empty?
9
- options[micro_session.options[:param]] = (ms_value == true ? micro_session.id : ms_value)
10
- end
11
-
12
- super
5
+
6
+ def url_for(options = {})
7
+ if options.is_a?(Hash) && ms_value = options.delete(:micro_sessions) && !micro_session.empty?
8
+ options[micro_session.options[:param]] = (ms_value == true ? micro_session.id : ms_value)
13
9
  end
10
+
11
+ super
14
12
  end
15
13
  end
16
14
 
17
15
  module FormTagHelper
18
16
  extend ActiveSupport::Concern
19
17
 
20
- module InstanceMethods
21
- def micro_session_hidden_field
22
- hidden_field_tag controller.class.micro_session_options[:param], micro_session.id
23
- end
18
+ def micro_session_hidden_field
19
+ hidden_field_tag controller.class.micro_session_options[:param], micro_session.id
24
20
  end
25
21
  end
26
22
  end
@@ -37,11 +37,11 @@ module MicroSessions
37
37
  def generate_id
38
38
  case options[:param_type]
39
39
  when :hash
40
- ActiveSupport::SecureRandom.hex(options[:length] / 2)
40
+ (Object::const_defined?("SecureRandom") ? SecureRandom : ActiveSupport::SecureRandom).hex(options[:length] / 2)
41
41
  when :integer
42
42
  self.counter += 1
43
43
  when :random_integer
44
- ActiveSupport::SecureRandom.integer
44
+ (Object::const_defined?("SecureRandom") ? SecureRandom : ActiveSupport::SecureRandom).integer
45
45
  end
46
46
  end
47
47
  end
@@ -1,19 +1,32 @@
1
1
  module MicroSessions
2
- if defined?(Rails::Railtie)
3
- class Railtie < Rails::Railtie
4
- initializer "micro_sessions.insert" do
5
- ActiveSupport.on_load(:action_controller) do
6
- MicroSessions::Railtie.insert
7
- end
2
+ class Railtie < Rails::Railtie
3
+ initializer "micro_sessions.insert" do
4
+ ActiveSupport.on_load(:action_controller) do
5
+ MicroSessions::Railtie.insert_controller
6
+ end
7
+
8
+ ActiveSupport.on_load(:action_view) do
9
+ MicroSessions::Railtie.insert_view
8
10
  end
9
11
  end
10
- end
11
-
12
- class Railtie
13
- def self.insert
12
+
13
+ def self.insert_controller
14
14
  ActionController::Base.send(:include, MicroSessions::Controller)
15
- ActionView::Helpers::UrlHelper.send(:include, MicroSessions::Helpers::UrlHelper)
15
+ ActionController::Base.send(:include, MicroSessions::Helpers::UrlHelper)
16
+ end
17
+
18
+ def self.insert_view
16
19
  ActionView::Helpers::FormTagHelper.send(:include, MicroSessions::Helpers::FormTagHelper)
20
+ ActionView::Helpers::UrlHelper.send(:include, MicroSessions::Helpers::UrlHelper)
21
+ end
22
+
23
+ MicroSessions::Railtie.insert_controller
24
+ MicroSessions::Railtie.insert_view
25
+
26
+ config.after_initialize do
27
+ MicroSessions::Railtie.insert_controller
28
+ MicroSessions::Railtie.insert_view
17
29
  end
18
30
  end
19
31
  end
32
+
@@ -1,3 +1,3 @@
1
1
  module MicroSessions
2
- VERSION = "0.1.1"
3
- end
2
+ VERSION = "0.2.0"
3
+ end
data/spec/helpers_spec.rb CHANGED
@@ -1,24 +1,25 @@
1
1
  require "spec_helper"
2
2
 
3
+ # Complex Stubbing does not do us any good here... relying on integration tests...
3
4
  describe MicroSessions::Helpers do
4
- before do
5
- @controller_class = Class.new(ActionController::Base)
6
- @controller_class.stub(:micro_session_options).and_return(:param => "_msid")
7
- @helpers = ActionView::Base.new
8
- @helpers.stub(:controller).and_return(@controller_class.new)
9
- @helpers.stub(:micro_session).and_return(mock(:id => "abc123"))
10
- end
11
-
12
- it "should respond to #micro_session_hidden_field" do
13
- @helpers.should respond_to(:micro_session_hidden_field)
14
- end
15
-
16
- it "should render correct micro_session_hidden_field" do
17
- @helpers.micro_session_hidden_field.should == %{<input id="_msid" name="_msid" type="hidden" value="abc123" />}
18
- end
19
-
5
+ # before do
6
+ # @controller_class = Class.new(ActionController::Base)
7
+ # @controller_class.stub(:micro_session_options).and_return(:param => "_msid")
8
+ # @helpers = ActionView::Base.new
9
+ # @helpers.stub(:controller).and_return(@controller_class.new)
10
+ # @helpers.stub(:micro_session).and_return(mock(:id => "abc123"))
11
+ # end
12
+ #
13
+ # it "should respond to #micro_session_hidden_field" do
14
+ # @helpers.should respond_to(:micro_session_hidden_field)
15
+ # end
16
+ #
17
+ # it "should render correct micro_session_hidden_field" do
18
+ # @helpers.micro_session_hidden_field.should == %{<input id="_msid" name="_msid" type="hidden" value="abc123" />}
19
+ # end
20
+ #
20
21
  # TODO: This is way too complex to test, requires an enormous amount of stubbing... Need a real Rails app.
21
22
  # it "should render correct link_to with :micro_sessions => true" do
22
23
  # @helpers.url_for
23
24
  # end
24
- end
25
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,9 +2,8 @@ require "rubygems"
2
2
  require "rspec"
3
3
  require "active_support"
4
4
  require "action_pack"
5
-
6
- require File.dirname(__FILE__) + "/../init"
5
+ require "micro_sessions"
7
6
 
8
7
  RSpec.configure do |c|
9
8
 
10
- end
9
+ end
metadata CHANGED
@@ -1,64 +1,125 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: micro_sessions
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Ben Hughes
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-10-24 00:00:00 +03:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: actionpack
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-04-02 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70336143584920 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 3.0.0
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: 3.2.0
35
25
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: activesupport
39
26
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ version_requirements: *70336143584920
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: &70336143557720 !ruby/object:Gem::Requirement
41
31
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 7
46
- segments:
47
- - 3
48
- - 0
49
- - 0
50
- version: 3.0.0
51
- type: :runtime
52
- version_requirements: *id002
53
- description: Provides 'micro-sessions' within the global sessions object keyed off an identifier.
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '2.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: *70336143557720
39
+ - !ruby/object:Gem::Dependency
40
+ name: cucumber
41
+ requirement: &70336143555180 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.4
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: *70336143555180
50
+ - !ruby/object:Gem::Dependency
51
+ name: capybara
52
+ requirement: &70336143551280 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: 1.1.0
58
+ type: :development
59
+ prerelease: false
60
+ version_requirements: *70336143551280
61
+ - !ruby/object:Gem::Dependency
62
+ name: sqlite3
63
+ requirement: &70336143541440 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.4
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: *70336143541440
72
+ - !ruby/object:Gem::Dependency
73
+ name: appraisal
74
+ requirement: &70336143535060 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: 0.4.0
80
+ type: :development
81
+ prerelease: false
82
+ version_requirements: *70336143535060
83
+ - !ruby/object:Gem::Dependency
84
+ name: rdoc
85
+ requirement: &70336143527080 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '3.12'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: *70336143527080
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: &70336143474400 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: *70336143474400
105
+ - !ruby/object:Gem::Dependency
106
+ name: launchy
107
+ requirement: &70336143470060 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: *70336143470060
116
+ description: Provides 'micro-sessions' within the global sessions object keyed off
117
+ an identifier.
54
118
  email: ben@railsgarden.com
55
119
  executables: []
56
-
57
120
  extensions: []
58
-
59
121
  extra_rdoc_files: []
60
-
61
- files:
122
+ files:
62
123
  - lib/micro_sessions/controller.rb
63
124
  - lib/micro_sessions/helpers.rb
64
125
  - lib/micro_sessions/micro_session.rb
@@ -68,44 +129,34 @@ files:
68
129
  - spec/controller_spec.rb
69
130
  - spec/helpers_spec.rb
70
131
  - spec/spec_helper.rb
132
+ - Appraisals
133
+ - Gemfile
134
+ - Gemfile.lock
71
135
  - LICENSE
136
+ - Rakefile
72
137
  - README.rdoc
73
- - init.rb
74
- has_rdoc: true
75
138
  homepage: http://github.com/rubiety/micro_sessions
76
139
  licenses: []
77
-
78
140
  post_install_message:
79
141
  rdoc_options: []
80
-
81
- require_paths:
142
+ require_paths:
82
143
  - lib
83
- required_ruby_version: !ruby/object:Gem::Requirement
144
+ required_ruby_version: !ruby/object:Gem::Requirement
84
145
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
92
- required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
151
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- hash: 19
98
- segments:
99
- - 1
100
- - 3
101
- - 4
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
102
155
  version: 1.3.4
103
156
  requirements: []
104
-
105
157
  rubyforge_project: micro_sessions
106
- rubygems_version: 1.3.7
158
+ rubygems_version: 1.8.10
107
159
  signing_key:
108
160
  specification_version: 3
109
161
  summary: Keyed sessions within the global sessions object.
110
162
  test_files: []
111
-
data/init.rb DELETED
@@ -1,3 +0,0 @@
1
- require "micro_sessions"
2
-
3
- MicroSessions::Railtie.insert