kojac 0.9.1 → 0.11.0

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.
Files changed (95) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +4 -0
  3. data/Gemfile +1 -1
  4. data/app/assets/javascripts/kojac.js +393 -125
  5. data/app/assets/javascripts/kojac_canjs.js +34 -34
  6. data/app/assets/javascripts/kojac_ember.js +110 -152
  7. data/app/controllers/{kojac_controller.rb → kojac_base_controller.rb} +18 -11
  8. data/app/policies/kojac_base_policy.rb +114 -0
  9. data/app/serializers/kojac_base_serializer.rb +35 -0
  10. data/kojac.gemspec +12 -10
  11. data/lib/kojac/app_serialize.rb +31 -29
  12. data/lib/kojac/concentric.rb +152 -0
  13. data/lib/kojac/kojac_policy.rb +70 -0
  14. data/lib/kojac/kojac_rails.rb +200 -49
  15. data/lib/kojac/version.rb +1 -1
  16. data/spec/can_cache_spec.js +19 -19
  17. data/spec/demo/.gitignore +16 -0
  18. data/spec/demo/.ruby-gemset +1 -0
  19. data/spec/demo/.ruby-version +1 -0
  20. data/spec/demo/Gemfile +59 -0
  21. data/spec/demo/Gemfile.lock +153 -0
  22. data/spec/demo/README.rdoc +15 -248
  23. data/spec/demo/Rakefile +25 -1
  24. data/spec/demo/app/{mailers/.gitkeep → assets/images/.keep} +0 -0
  25. data/spec/demo/app/assets/javascripts/application.js +3 -3
  26. data/spec/demo/app/controllers/application_controller.rb +6 -1
  27. data/spec/demo/app/{models/.gitkeep → controllers/concerns/.keep} +0 -0
  28. data/spec/demo/app/controllers/users_controller.rb +5 -0
  29. data/spec/demo/{lib/assets/.gitkeep → app/mailers/.keep} +0 -0
  30. data/spec/demo/{log/.gitkeep → app/models/.keep} +0 -0
  31. data/spec/demo/app/models/concerns/.keep +0 -0
  32. data/spec/demo/app/models/user.rb +36 -0
  33. data/spec/demo/app/policies/user_policy.rb +42 -0
  34. data/spec/demo/bin/bundle +3 -0
  35. data/spec/demo/bin/rails +4 -0
  36. data/spec/demo/bin/rake +4 -0
  37. data/spec/demo/config.ru +1 -1
  38. data/spec/demo/config/application.rb +14 -46
  39. data/spec/demo/config/application.yml +4 -0
  40. data/spec/demo/config/boot.rb +3 -9
  41. data/spec/demo/config/database.yml +6 -6
  42. data/spec/demo/config/environment.rb +4 -2
  43. data/spec/demo/config/environments/development.rb +11 -19
  44. data/spec/demo/config/environments/production.rb +40 -27
  45. data/spec/demo/config/environments/test.rb +13 -14
  46. data/spec/demo/config/initializers/concentric_config.rb +9 -0
  47. data/spec/demo/config/initializers/filter_parameter_logging.rb +4 -0
  48. data/spec/demo/config/initializers/inflections.rb +6 -5
  49. data/spec/demo/config/initializers/initialize_kojac.rb +16 -0
  50. data/spec/demo/config/initializers/secret_token.rb +7 -2
  51. data/spec/demo/config/initializers/session_store.rb +0 -5
  52. data/spec/demo/config/initializers/wrap_parameters.rb +6 -6
  53. data/spec/demo/config/locales/en.yml +20 -2
  54. data/spec/demo/config/routes.rb +24 -24
  55. data/spec/demo/db/migrate/20131212034312_add_user.rb +14 -0
  56. data/spec/demo/db/migrate/20140107085351_add_owner_id.rb +5 -0
  57. data/spec/demo/db/schema.rb +28 -0
  58. data/spec/demo/db/seeds.rb +7 -0
  59. data/spec/demo/lib/assets/.keep +0 -0
  60. data/spec/demo/lib/tasks/.keep +0 -0
  61. data/spec/demo/log/.keep +0 -0
  62. data/spec/demo/public/404.html +43 -11
  63. data/spec/demo/public/422.html +43 -11
  64. data/spec/demo/public/500.html +43 -11
  65. data/spec/demo/public/robots.txt +5 -0
  66. data/spec/demo/spec/controllers/allowed_fields_spec.rb +171 -0
  67. data/spec/demo/spec/factories/users.rb +9 -0
  68. data/spec/demo/spec/features/concentric_spec.rb +63 -0
  69. data/spec/demo/spec/features/serialization_spec.rb +86 -0
  70. data/spec/demo/spec/spec_helper.rb +133 -0
  71. data/spec/demo/spec/spec_utils.rb +42 -0
  72. data/spec/demo/vendor/assets/javascripts/.keep +0 -0
  73. data/spec/demo/vendor/assets/stylesheets/.keep +0 -0
  74. data/spec/ember_factory_spec.js +1 -1
  75. data/spec/ember_model_spec.js +13 -3
  76. data/spec/ember_tojsono_spec.js +105 -0
  77. data/spec/error_handling_spec.js +90 -0
  78. data/spec/external/underscore_plus.js +318 -9
  79. data/spec/kojac_caching_spec.js +3 -1
  80. data/spec/kojac_ember_cache_spec.js +9 -0
  81. data/spec/kojac_mock_spec.js +4 -4
  82. data/spec/kojac_operations_spec.js +4 -4
  83. data/spec/local_provider_spec.js +184 -0
  84. data/spec/model_ring_spec.rb +2 -2
  85. data/spec/operation_include_spec.js +2 -2
  86. data/spec/run.html +34 -24
  87. data/spec/type_conversion_spec.js +38 -0
  88. data/vendor/assets/javascripts/jstorage.js +950 -0
  89. metadata +115 -129
  90. data/Gemfile.lock +0 -157
  91. data/app/serializers/default_kojac_serializer.rb +0 -10
  92. data/lib/kojac/ring_strong_parameters.rb +0 -195
  93. data/spec/.DS_Store +0 -0
  94. data/spec/demo/script/rails +0 -6
  95. data/spec/external/.DS_Store +0 -0
@@ -2,17 +2,48 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>We're sorry, but something went wrong (500)</title>
5
- <style type="text/css">
6
- body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
- div.dialog {
8
- width: 25em;
9
- padding: 0 4em;
10
- margin: 4em auto 0 auto;
11
- border: 1px solid #ccc;
12
- border-right-color: #999;
13
- border-bottom-color: #999;
14
- }
15
- h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
16
47
  </style>
17
48
  </head>
18
49
 
@@ -21,5 +52,6 @@
21
52
  <div class="dialog">
22
53
  <h1>We're sorry, but something went wrong.</h1>
23
54
  </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
24
56
  </body>
25
57
  </html>
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
@@ -0,0 +1,171 @@
1
+ require 'spec_helper'
2
+
3
+ describe KojacBaseController do
4
+
5
+ #before(:each) do
6
+ # #@user = FactoryGirl.create(:user, ring: 3)
7
+ # #ApplicationController.any_instance.stub(:current_user).and_return(@user)
8
+ #end
9
+
10
+ it 'user read should return allowed fields' do
11
+ stub_login_user(ring: USER_RING)
12
+ @user2 = FactoryGirl.create(:user)
13
+ read_op = {
14
+ verb: 'READ',
15
+ key: @user2.kojac_key
16
+ }
17
+ draw_routes do
18
+ get ":controller/:action"
19
+ end
20
+ result = do_op(read_op)
21
+ result.keys.sort.should == (User::PUBLIC_FIELDS).map(&:to_s).sort
22
+ end
23
+
24
+ it 'admin read should return more allowed fields' do
25
+ stub_login_user(ring: ADMIN_RING)
26
+ @user2 = FactoryGirl.create(:user)
27
+ read_op = {
28
+ verb: 'READ',
29
+ key: @user2.kojac_key
30
+ }
31
+ draw_routes do
32
+ get ":controller/:action"
33
+ end
34
+ result = do_op(read_op)
35
+ result.keys.sort.should == (User::PUBLIC_FIELDS + User::PRIVATE_FIELDS + User::ADMIN_FIELDS + User::READ_ONLY_FIELDS).map(&:to_s).sort
36
+ end
37
+
38
+ it "user should not be able to update other's name" do
39
+ user = stub_login_user(ring: USER_RING)
40
+ user2 = FactoryGirl.create(:user)
41
+ original_name = user2.last_name
42
+ send_op = {
43
+ verb: 'UPDATE',
44
+ key: user2.kojac_key,
45
+ value: {
46
+ last_name: 'Smithy-Jones'
47
+ }
48
+ }
49
+ draw_routes do
50
+ get ":controller/:action"
51
+ end
52
+ expect { do_op(send_op) }.to raise_exception(Pundit::NotAuthorizedError)
53
+ user2.reload
54
+ user2.last_name.should == original_name
55
+ end
56
+
57
+ it 'user should be able to read own PRIVATE_FIELDS' do
58
+ user = stub_login_user(ring: USER_RING)
59
+ send_op = {
60
+ verb: 'READ',
61
+ key: user.kojac_key
62
+ }
63
+ draw_routes do
64
+ get ":controller/:action"
65
+ end
66
+ result = do_op(send_op)
67
+ result.keys.sort.should == (User::PUBLIC_FIELDS + User::PRIVATE_FIELDS).map(&:to_s).sort
68
+ end
69
+
70
+
71
+ it 'user should be able to update own name' do
72
+ user = stub_login_user(ring: USER_RING)
73
+ send_op = {
74
+ verb: 'UPDATE',
75
+ key: user.kojac_key,
76
+ value: {
77
+ last_name: 'Smithy-Jones'
78
+ }
79
+ }
80
+ draw_routes do
81
+ get ":controller/:action"
82
+ end
83
+ result = do_op(send_op)
84
+ result['last_name'].should == send_op.g?('value.last_name')
85
+ result.keys.sort.should == (User::PUBLIC_FIELDS + User::PRIVATE_FIELDS).map(&:to_s).sort
86
+ end
87
+
88
+ it 'admin user should be able to update user of same owner' do
89
+ user = stub_login_user(ring: ADMIN_RING, owner_id: 1)
90
+ user2 = FactoryGirl.create(:user, owner_id: 1)
91
+ original_name = user2.last_name
92
+ send_op = {
93
+ verb: 'UPDATE',
94
+ key: user2.kojac_key,
95
+ value: {
96
+ last_name: 'Smithy-Jones'
97
+ }
98
+ }
99
+ draw_routes do
100
+ get ":controller/:action"
101
+ end
102
+ result = do_op(send_op)
103
+ result['last_name'].should == send_op.g?('value.last_name')
104
+ user2.reload
105
+ user2.last_name.should == send_op.g?('value.last_name')
106
+ result.keys.sort.should == (User::PUBLIC_FIELDS + User::PRIVATE_FIELDS + User::ADMIN_FIELDS + User::READ_ONLY_FIELDS).map(&:to_s).sort
107
+ end
108
+
109
+ it 'admin user should not be able to update user of different owner' do
110
+ user = stub_login_user(ring: ADMIN_RING, owner_id: 1)
111
+ user2 = FactoryGirl.create(:user, owner_id: 2)
112
+ original_name = user2.last_name
113
+ send_op = {
114
+ verb: 'UPDATE',
115
+ key: user2.kojac_key,
116
+ value: {
117
+ last_name: 'Smithy-Jones'
118
+ }
119
+ }
120
+ draw_routes do
121
+ get ":controller/:action"
122
+ end
123
+ expect { do_op(send_op) }.to raise_exception(Pundit::NotAuthorizedError)
124
+ user2.reload
125
+ user2.last_name.should == original_name
126
+ end
127
+
128
+ it 'should read users' do
129
+ @user = stub_login_user(ring: ADMIN_RING)
130
+ @user2 = FactoryGirl.create(:user)
131
+ read_op = {
132
+ verb: 'READ',
133
+ key: 'users'
134
+ }
135
+ content = {
136
+ options: {},
137
+ ops: [
138
+ read_op
139
+ ]
140
+ }
141
+ draw_routes do
142
+ get ":controller/:action"
143
+ end
144
+ request.accept = "application/json"
145
+ post :receive, format: :json, kojac: content
146
+
147
+ output = JSON.parse response.body
148
+ output['ops'].should be_is_a Array
149
+ output['ops'].length.should == 1
150
+ op = output['ops'].first
151
+ op['verb'].should == read_op[:verb]
152
+ op['key'].should == read_op[:key]
153
+ op['results'].class.should == Hash
154
+ user_key = "users__#{@user.id}"
155
+ user2_key = "users__#{@user2.id}"
156
+
157
+ op['results'].keys.sort.should == ["users",user_key,user2_key].sort
158
+ op['results']['users'].should == [@user.id,@user2.id]
159
+ op['results'][user_key].filter_include(%w(id first_name last_name)).should == {
160
+ 'id' => @user.id,
161
+ 'first_name' => @user.first_name,
162
+ 'last_name' => @user.last_name
163
+ }
164
+ op['results'][user2_key].filter_include(%w(id first_name last_name)).should == {
165
+ 'id' => @user2.id,
166
+ 'first_name' => @user2.first_name,
167
+ 'last_name' => @user2.last_name
168
+ }
169
+ op['result'].should_not be
170
+ end
171
+ end
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ ring { USER_RING }
4
+
5
+ first_name { Faker::Name.first_name }
6
+ last_name { Faker::Name.last_name }
7
+ email { Faker::Internet.email }
8
+ end
9
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ConcentricTestModel" do
4
+
5
+ before(:all) do
6
+ @original_config = Concentric.config
7
+ Concentric.config = {
8
+ ring_names: {
9
+ master: 0,
10
+ boss: 10,
11
+ pleb: 30,
12
+ anyone: 100
13
+ }
14
+ }
15
+ end
16
+
17
+ after(:all) do
18
+ Concentric.config = @original_config
19
+ end
20
+
21
+ it "attributes described should be available in outer rings" do
22
+ class ConcentricTestModel < ActiveRecord::Base
23
+ include Concentric::Model
24
+
25
+ ring :pleb, read: [:name,:address]
26
+ ring :pleb, read: [:dob]
27
+ ring :boss, read: [:next_of_kin]
28
+
29
+ ring :boss, transmogrify: []
30
+ ring :boss, eliminate: :this
31
+
32
+ ring :pleb, [:cough,:sneeze] => [:desk,:outside]
33
+ end
34
+
35
+ ConcentricTestModel.permitted(:pleb,:read).should == [:address,:dob,:name]
36
+ ConcentricTestModel.permitted(:master,:read).should == [:address,:dob,:name,:next_of_kin]
37
+ ConcentricTestModel.permitted(:anyone,:read).should == []
38
+ ConcentricTestModel.ring_can?(:pleb,:read).should == true
39
+ ConcentricTestModel.ring_can?(:master,:read).should == true
40
+ ConcentricTestModel.ring_can?(:anyone,:read).should == false
41
+
42
+ ConcentricTestModel.ring_can?(:pleb,:transmogrify).should == false
43
+ ConcentricTestModel.ring_can?(:boss,:transmogrify).should == false
44
+ ConcentricTestModel.ring_can?(:master,:transmogrify).should == false
45
+
46
+ ConcentricTestModel.ring_can?(:pleb,:eliminate).should == false
47
+ ConcentricTestModel.ring_can?(:boss,:eliminate).should == true
48
+ ConcentricTestModel.ring_can?(:master,:eliminate).should == true
49
+
50
+ ConcentricTestModel.ring_can?(:pleb,:cough).should == true
51
+ ConcentricTestModel.ring_can?(:pleb,:sneeze).should == true
52
+ ConcentricTestModel.ring_can?(:boss,:cough).should == true
53
+ ConcentricTestModel.ring_can?(:boss,:sneeze).should == true
54
+ ConcentricTestModel.ring_can?(:pleb,:cough,:outside).should == true
55
+ ConcentricTestModel.ring_can?(:pleb,:cough,:desk).should == true
56
+ ConcentricTestModel.ring_can?(:pleb,:cough,[:desk,:outside]).should == true
57
+ ConcentricTestModel.ring_can?(:pleb,:cough,:lunch_room).should == false
58
+
59
+ ConcentricTestModel.permitted(:pleb,:cough).should == [:desk,:outside]
60
+ ConcentricTestModel.permitted(:pleb,:sneeze).should == [:desk,:outside]
61
+ end
62
+
63
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe "serialization" do
4
+
5
+ it "should serialize array" do
6
+ user = FactoryGirl.create(:user)
7
+ jsons = KojacUtils.to_json([1,2,3],scope: user)
8
+ jsons.should == '[1,2,3]'
9
+ end
10
+
11
+ it "should serialize number" do
12
+ user = FactoryGirl.create(:user)
13
+ jsons = KojacUtils.to_json(5,scope: user)
14
+ jsons.should == '5'
15
+ end
16
+
17
+ it "should serialize object" do
18
+ user = FactoryGirl.create(:user)
19
+ jsons = KojacUtils.to_json({a: 1, b: 2},scope: user)
20
+ jsons.should == '{"a":1,"b":2}'
21
+ end
22
+
23
+ #it "should serialize Deal" do
24
+ # user = FactoryGirl.create(:user)
25
+ # deal = FactoryGirl.create(:deal, user: user)
26
+ # jsons = KojacUtils.to_json(deal,scope: user)
27
+ # jsono = JSON.parse jsons
28
+ # jsono['trade_in_price'].should be > 0
29
+ # jsono['cash_deposit'].should be > 0
30
+ # jsono['other_cost'].should be > 0
31
+ #end
32
+
33
+ it "to_jsono should convert embedded model to a hash" do
34
+ user = FactoryGirl.create(:user)
35
+ user2 = FactoryGirl.create(:user)
36
+
37
+ embed = {user: user2}
38
+ jsono = KojacUtils.to_jsono(embed,scope: user)
39
+ jsono['user'].class.should == Hash
40
+ end
41
+
42
+ it "model serialized inside a hash should give the same fields as when serialized directly" do
43
+ user = FactoryGirl.create(:user)
44
+ user2 = FactoryGirl.create(:user)
45
+
46
+ embed = {user: user2}
47
+ embed_jsons = KojacUtils.to_json(embed,scope: user)
48
+ embed_jsono = JSON.parse embed_jsons
49
+
50
+ direct_jsons = KojacUtils.to_json(user2,scope: user)
51
+ direct_jsono = JSON.parse direct_jsons
52
+
53
+ embed_jsono['user'].should == direct_jsono
54
+ end
55
+
56
+ #it "model serialized deeply inside a structure should give the same fields as when serialized directly" do
57
+ # user = FactoryGirl.create(:user)
58
+ # user2 = FactoryGirl.create(:user)
59
+ #
60
+ # embed = {user: user2}
61
+ # embed_jsons = KojacUtils.to_json(embed,scope: user)
62
+ # embed_jsono = JSON.parse embed_jsons
63
+ #
64
+ # direct_jsons = KojacUtils.to_json(user2,scope: user)
65
+ # direct_jsono = JSON.parse direct_jsons
66
+ #
67
+ # embed_jsono['user'].should == direct_jsono
68
+ #end
69
+
70
+ it "should test models embedded in an Array" do
71
+ user = FactoryGirl.create(:user)
72
+ user2 = FactoryGirl.create(:user)
73
+
74
+ embed = [user2]
75
+ embed_jsons = KojacUtils.to_json(embed,scope: user)
76
+ embed_jsono = JSON.parse embed_jsons
77
+
78
+ direct_jsons = KojacUtils.to_json(user2,scope: user)
79
+ direct_jsono = JSON.parse direct_jsons
80
+
81
+ embed_jsono[0].should == direct_jsono
82
+ end
83
+
84
+ it "should test models embedded in an HashWithIndifferentAccess"
85
+
86
+ end
@@ -0,0 +1,133 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ #require 'capybara/rspec'
6
+ require 'rspec/autorun'
7
+
8
+ # Requires supporting ruby files with custom matchers and macros, etc,
9
+ # in spec/support/ and its subdirectories.
10
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
11
+
12
+ #Capybara.run_server = true #Whether start server when testing
13
+ #Capybara.server_port = 8200
14
+ #Capybara.default_selector = :css #:xpath #default selector , you can change to :css
15
+ #Capybara.default_wait_time = 5 #When we testing AJAX, we can set a default wait time
16
+ #Capybara.ignore_hidden_elements = false #Ignore hidden elements when testing, make helpful when you hide or show elements using javascript
17
+ #Capybara.javascript_driver = :selenium #default driver when you using @javascript tag
18
+
19
+ #require 'capybara/poltergeist'
20
+ #Capybara.javascript_driver = :poltergeist
21
+ #Capybara.register_driver :poltergeist do |app|
22
+ # options = {
23
+ # :js_errors => true,
24
+ # :timeout => 120,
25
+ # :debug => true,
26
+ # :phantomjs_options => ['--load-images=no', '--disk-cache=false'],
27
+ # :inspector => true,
28
+ # }
29
+ # Capybara::Poltergeist::Driver.new(app, options)
30
+ #end
31
+
32
+ #Post-install message from capybara:
33
+ #IMPORTANT! Some of the defaults have changed in Capybara 2.1. If you're experiencing failures,
34
+ #please revert to the old behaviour by setting:
35
+ #
36
+ # Capybara.configure do |config|
37
+ # config.match = :one
38
+ # config.exact_options = true
39
+ # config.ignore_hidden_elements = true
40
+ # config.visible_text_only = true
41
+ # end
42
+ #
43
+ #If you're migrating from Capybara 1.x, try:
44
+ #
45
+ # Capybara.configure do |config|
46
+ # config.match = :prefer_exact
47
+ # config.ignore_hidden_elements = false
48
+ # end
49
+ #
50
+ #Details here: http://www.elabs.se/blog/60-introducing-capybara-2-1
51
+ #
52
+
53
+
54
+
55
+ RSpec.configure do |config|
56
+ config.color_enabled = true
57
+ config.tty = true
58
+
59
+ # ## Mock Framework
60
+ #
61
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
62
+ #
63
+ # config.mock_with :mocha
64
+ # config.mock_with :flexmock
65
+ # config.mock_with :rr
66
+
67
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
68
+ #config.fixture_path = "#{::Rails.root}/spec/fixtures"
69
+
70
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
71
+ # examples within a transaction, remove the following line or assign false
72
+ # instead of true.
73
+ config.use_transactional_fixtures = true # false # should be false when using Database Cleaner https://www.relishapp.com/rspec/rspec-rails/docs/transactions
74
+
75
+ # Run specs in random order to surface order dependencies. If you find an
76
+ # order dependency and want to debug it, you can fix the order by providing
77
+ # the seed, which is printed after each run.
78
+ # --seed 1234
79
+ #config.order = "random"
80
+
81
+ # see http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/
82
+ #config.before(:suite) do # once only, before set of specs run
83
+ # DatabaseCleaner.clean_with(:truncation)
84
+ #end
85
+ #
86
+ #config.before :each do
87
+ # #if Capybara.current_driver == :rack_test
88
+ # DatabaseCleaner.strategy = :transaction
89
+ # #else
90
+ # # DatabaseCleaner.strategy = :truncation
91
+ # #end
92
+ # DatabaseCleaner.start
93
+ # ActionMailer::Base.deliveries.clear
94
+ #end
95
+ #
96
+ #config.after(:each) do
97
+ # DatabaseCleaner.clean
98
+ #end
99
+
100
+ #config.before(:all) do
101
+ # DeferredGarbageCollection.start
102
+ #end
103
+ #
104
+ #config.after(:all) do
105
+ # DeferredGarbageCollection.reconsider
106
+ #end
107
+
108
+ #config.include ShowMeTheCookies#, :type => :feature
109
+ #
110
+ ##config.include ProductsHelper
111
+ #config.include ActionView::Helpers::TextHelper
112
+ #
113
+ #config.include(EmailSpec::Helpers)
114
+ #config.include(EmailSpec::Matchers)
115
+
116
+ #config.treat_symbols_as_metadata_keys_with_true_values = true
117
+ #config.filter_run_excluding :requires_elasticsearch unless CONFIG[:elasticsearch_available]
118
+ end
119
+
120
+ # Capybara operations normally happen on another thread and connection, and so transactional database cleaning won't work.
121
+ # This hack makes all operations share a common connection, and so transactional database cleaning works even for capybara tests
122
+ # Also see https://gist.github.com/josevalim/470808 and http://stackoverflow.com/questions/8774227/why-not-use-shared-activerecord-connections-for-rspec-selenium
123
+ #class ActiveRecord::Base
124
+ # mattr_accessor :shared_connection
125
+ # @@shared_connection = nil
126
+ #
127
+ # def self.connection
128
+ # @@shared_connection || retrieve_connection
129
+ # end
130
+ #end
131
+ #ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
132
+ #
133
+ require 'spec_utils'