citygate 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/README.rdoc +11 -0
  2. data/app/assets/javascripts/citygate/admin_users.coffee +1 -1
  3. data/app/assets/javascripts/citygate/jquery.pjax.js +4 -2
  4. data/app/assets/javascripts/citygate.js +16 -0
  5. data/app/assets/stylesheets/citygate/{application.css.scss → application.css} +0 -0
  6. data/app/assets/stylesheets/citygate/main.sass +0 -9
  7. data/app/controllers/citygate/admin/application_controller.rb +3 -1
  8. data/app/controllers/citygate/admin/users_controller.rb +4 -4
  9. data/app/controllers/citygate/application_controller.rb +4 -2
  10. data/app/controllers/citygate/users/omniauth_callbacks_controller.rb +13 -12
  11. data/app/models/citygate/permission.rb +7 -0
  12. data/app/models/citygate/role.rb +2 -1
  13. data/app/models/citygate/user.rb +24 -4
  14. data/app/views/citygate/admin/users/index.html.erb +3 -3
  15. data/app/views/citygate/admin/users/show.html.erb +12 -3
  16. data/app/views/citygate/home/index.html.erb +4 -5
  17. data/app/views/citygate/shared/_navigation.html.erb +18 -18
  18. data/app/views/citygate/users/show.html.erb +6 -4
  19. data/app/views/devise/confirmations/new.html.erb +12 -0
  20. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  21. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  22. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  23. data/app/views/devise/passwords/edit.html.erb +16 -0
  24. data/app/views/devise/passwords/new.html.erb +12 -0
  25. data/app/views/devise/registrations/edit.html.erb +33 -30
  26. data/app/views/devise/registrations/new.html.erb +10 -10
  27. data/app/views/devise/sessions/new.html.erb +18 -0
  28. data/app/views/devise/{_links.erb → shared/_links.erb} +7 -7
  29. data/app/views/devise/unlocks/new.html.erb +12 -0
  30. data/app/views/layouts/admin/application.html.erb +2 -2
  31. data/config/accounts.yml +1 -3
  32. data/config/initializers/devise.rb +1 -1
  33. data/config/locales/defaults/en.yml +2 -0
  34. data/config/locales/models/user/en.yml +4 -0
  35. data/config/locales/navigation/en.yml +12 -0
  36. data/config/locales/shared/cancan/en.yml +3 -0
  37. data/config/locales/{devise.en.yml → shared/devise/devise.en.yml} +0 -0
  38. data/config/locales/{devise_invitable.en.yml → shared/devise/devise_invitable.en.yml} +0 -0
  39. data/config/locales/views/admin/users/en.yml +32 -0
  40. data/db/migrate/20120303195103_add_name_to_users.rb +2 -1
  41. data/db/migrate/20120727143920_create_permissions_table.rb +12 -0
  42. data/db/seeds.rb +14 -0
  43. data/lib/ability.rb +53 -0
  44. data/lib/citygate/engine.rb +10 -0
  45. data/lib/citygate/version.rb +1 -1
  46. data/spec/dummy/README.rdoc +261 -0
  47. data/spec/dummy/Rakefile +30 -0
  48. data/{app/assets/javascripts/citygate → spec/dummy/app/assets/javascripts}/application.js +2 -3
  49. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  50. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  51. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  52. data/spec/dummy/app/views/layouts/application.html.erb +19 -0
  53. data/spec/dummy/config/application.rb +61 -0
  54. data/spec/dummy/config/boot.rb +10 -0
  55. data/spec/dummy/config/database.yml +25 -0
  56. data/spec/dummy/config/environment.rb +5 -0
  57. data/spec/dummy/config/environments/development.rb +39 -0
  58. data/spec/dummy/config/environments/production.rb +67 -0
  59. data/spec/dummy/config/environments/test.rb +39 -0
  60. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  61. data/spec/dummy/config/initializers/inflections.rb +15 -0
  62. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  63. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  64. data/spec/dummy/config/initializers/session_store.rb +8 -0
  65. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  66. data/{config → spec/dummy/config}/locales/en.yml +0 -0
  67. data/spec/dummy/config/routes.rb +3 -0
  68. data/spec/dummy/config.ru +4 -0
  69. data/spec/dummy/db/development.sqlite3 +0 -0
  70. data/spec/dummy/db/migrate/20120706095546_devise_create_users.citygate.rb +50 -0
  71. data/spec/dummy/db/migrate/20120706095547_add_name_to_users.citygate.rb +7 -0
  72. data/spec/dummy/db/migrate/20120706095548_add_confirmable_to_users.citygate.rb +12 -0
  73. data/spec/dummy/db/migrate/20120706095549_devise_invitable_add_to_users.citygate.rb +24 -0
  74. data/spec/dummy/db/migrate/20120706095550_add_omniauth_to_devise.citygate.rb +20 -0
  75. data/spec/dummy/db/migrate/20120706095551_create_roles.citygate.rb +11 -0
  76. data/spec/dummy/db/migrate/20120727145840_create_permissions_table.citygate.rb +13 -0
  77. data/spec/dummy/db/production.sqlite3 +0 -0
  78. data/spec/dummy/db/schema.rb +79 -0
  79. data/spec/dummy/db/seeds.rb +1 -0
  80. data/spec/dummy/db/test.sqlite3 +0 -0
  81. data/spec/dummy/features/step_definitions/email_steps.rb +206 -0
  82. data/spec/dummy/features/step_definitions/user_steps.rb +249 -0
  83. data/spec/dummy/features/support/email_spec.rb +1 -0
  84. data/spec/dummy/features/support/env.rb +107 -0
  85. data/spec/dummy/features/support/hooks.rb +0 -0
  86. data/spec/dummy/features/support/paths.rb +46 -0
  87. data/spec/dummy/features/users/login_omniauth.feature +19 -0
  88. data/spec/dummy/features/users/sign_in.feature +40 -0
  89. data/spec/dummy/features/users/sign_out.feature +11 -0
  90. data/spec/dummy/features/users/sign_up.feature +27 -0
  91. data/spec/dummy/features/users/user_edit.feature +9 -0
  92. data/spec/dummy/features/users/users_admin.feature +44 -0
  93. data/spec/dummy/log/development.log +18417 -0
  94. data/spec/dummy/log/test.log +59087 -0
  95. data/spec/dummy/public/404.html +26 -0
  96. data/spec/dummy/public/422.html +26 -0
  97. data/spec/dummy/public/500.html +25 -0
  98. data/spec/dummy/public/favicon.ico +0 -0
  99. data/spec/dummy/script/rails +6 -0
  100. data/spec/dummy/spec/controllers/admin/admin_controller_spec.rb +10 -0
  101. data/spec/dummy/spec/controllers/admin/users_spec.rb +15 -0
  102. data/spec/dummy/spec/controllers/home_controller_spec.rb +12 -0
  103. data/spec/dummy/spec/controllers/omniauth_spec.rb +73 -0
  104. data/spec/dummy/spec/factories.rb +33 -0
  105. data/spec/dummy/spec/javascripts/UserSpec.js +14 -0
  106. data/spec/dummy/spec/javascripts/fixtures/user_listing.html +20 -0
  107. data/spec/dummy/spec/javascripts/helpers/SpecHelper.js +9 -0
  108. data/spec/dummy/spec/javascripts/helpers/jasmine-jquery.js +306 -0
  109. data/spec/dummy/spec/javascripts/helpers/jquery.min.js +4 -0
  110. data/spec/dummy/spec/javascripts/support/jasmine.yml +19 -0
  111. data/spec/dummy/spec/models/user_spec.rb +100 -0
  112. data/spec/dummy/spec/routing/routing_spec.rb +22 -0
  113. data/spec/dummy/spec/spec_helper.rb +79 -0
  114. data/spec/dummy/spec/support/devise.rb +3 -0
  115. data/spec/dummy/tmp/cache/assets/C63/E40/sprockets%2F36a675f52eb281488964b58be8971051 +0 -0
  116. data/spec/dummy/tmp/cache/assets/C79/FC0/sprockets%2F76c2f8ffd1175afd6274640057134300 +0 -0
  117. data/spec/dummy/tmp/cache/assets/C7A/CE0/sprockets%2F9124c83a02e7332a90b2883b69f81d04 +0 -0
  118. data/spec/dummy/tmp/cache/assets/C89/540/sprockets%2F606a455261f8f047c994c4b9a582f126 +0 -0
  119. data/spec/dummy/tmp/cache/assets/CC5/020/sprockets%2Ffa39f3f719158fea829829617391b42c +0 -0
  120. data/spec/dummy/tmp/cache/assets/CD6/2B0/sprockets%2F08e01b4122e606428c6de7234d87bee1 +0 -0
  121. data/spec/dummy/tmp/cache/assets/CD8/070/sprockets%2F3afc9406d6d06c238a33603363af8a66 +0 -0
  122. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  123. data/spec/dummy/tmp/cache/assets/CE2/7D0/sprockets%2Fe69b8c4ca0800c940d1d9785f1a92327 +0 -0
  124. data/spec/dummy/tmp/cache/assets/CE8/510/sprockets%2F0d85ab6e3972f70636a990e91fec8301 +0 -0
  125. data/spec/dummy/tmp/cache/assets/CF6/500/sprockets%2Fe48376f3339fc2f84ac25d713936ea99 +0 -0
  126. data/spec/dummy/tmp/cache/assets/D0D/DE0/sprockets%2Fa35442f02b0b2479f22d83d639d8c4fd +0 -0
  127. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  128. data/spec/dummy/tmp/cache/assets/D3E/710/sprockets%2F93251497334cafddb54ecc36a332f5b9 +0 -0
  129. data/spec/dummy/tmp/cache/assets/D48/410/sprockets%2Fa18aa9c28f587c76e162489eb19f2a2a +0 -0
  130. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  131. data/spec/dummy/tmp/cache/assets/D53/840/sprockets%2Ff753499d8cefbb5a8450ca97540ff275 +0 -0
  132. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  133. data/spec/dummy/tmp/cache/assets/D72/580/sprockets%2F02aed4ae7c633d6d577280de93c4c7c6 +0 -0
  134. data/spec/dummy/tmp/cache/assets/D73/010/sprockets%2F834fa37dfa7f28148e125baf3f9d91b0 +0 -0
  135. data/spec/dummy/tmp/cache/assets/D75/530/sprockets%2F6a480d7952fbe8ce5c2eaad0369f7271 +0 -0
  136. data/spec/dummy/tmp/cache/assets/D78/BD0/sprockets%2Fd0c9ac69560ea197444b7f759ecd06da +0 -0
  137. data/spec/dummy/tmp/cache/assets/D9B/0B0/sprockets%2F609a6d0b06eb3752679f6e1f0adcb4fc +0 -0
  138. data/spec/dummy/tmp/cache/assets/D9E/F10/sprockets%2F9ab223df888d724dcad09eb1163cc5f4 +0 -0
  139. data/spec/dummy/tmp/cache/assets/D9E/F70/sprockets%2Fc5d4a6e7d907804c52cbf910339dafdb +0 -0
  140. data/spec/dummy/tmp/cache/assets/DB9/2A0/sprockets%2F0a7332e4e1420de7165bd13ecffca4cc +0 -0
  141. data/spec/dummy/tmp/cache/assets/DC2/210/sprockets%2Ff0049a44fff3a6ea3a55283aceb06fb4 +0 -0
  142. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  143. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  144. data/spec/dummy/tmp/cache/assets/E0B/AF0/sprockets%2Ff71f3afdedf8ab892f147a5facc07488 +0 -0
  145. data/spec/dummy/tmp/cache/assets/E2B/670/sprockets%2Feac21904ecb266ce92aecadb8681b7fe +0 -0
  146. data/spec/spec_helper.rb +33 -0
  147. metadata +267 -41
  148. data/app/models/citygate/ability.rb +0 -31
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</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; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</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; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
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; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -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,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citygate::Admin::ApplicationController do
4
+
5
+ it "should exist" do
6
+ Citygate.const_defined?('Admin').should be_true
7
+ Citygate::Admin.const_defined?('ApplicationController').should be_true
8
+ end
9
+
10
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citygate::Admin::UsersController do
4
+
5
+ before (:each) do
6
+ @user = Factory.create(:user)
7
+ sign_in @user
8
+ end
9
+
10
+ it "should get the defined number of users or less at a time" do
11
+ get :index
12
+ assigns(:users).size.should be <= Citygate::Engine.will_paginate_options[:per_page]
13
+ end
14
+
15
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citygate::HomeController do
4
+
5
+ describe "GET 'index'" do
6
+ it "should be successful" do
7
+ get :index
8
+ response.should be_success
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe Citygate::Users::OmniauthCallbacksController do
4
+
5
+ shared_examples "a provider for" do |provider|
6
+ describe "provider" do
7
+ before (:each) do
8
+ request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider]
9
+ request.env["devise.mapping"] = Devise.mappings[:user]
10
+ end
11
+
12
+ it "should create a new user" do
13
+ expect {
14
+ get provider
15
+ }.to change{Citygate::User.count}.by(1)
16
+ end
17
+
18
+ it "should create a new authorization" do
19
+ expect {
20
+ get provider
21
+ }.to change{Citygate::Authorization.count}.by(1)
22
+ end
23
+
24
+ context "limiting users" do
25
+ before (:each) do
26
+ Citygate::Engine.no_of_users = 1
27
+ Factory.create(:user)
28
+ request.env["omniauth.auth"] = OmniAuth.config.mock_auth[provider]
29
+ request.env["devise.mapping"] = Devise.mappings[:user]
30
+ end
31
+
32
+ it "should not create a new user" do
33
+ expect {
34
+ get provider
35
+ }.not_to change{Citygate::User.count}
36
+ end
37
+
38
+ it "should not create a new authorization" do
39
+ expect {
40
+ get provider
41
+ }.not_to change{Citygate::Authorization.count}
42
+ end
43
+ end
44
+
45
+ context "not changing the database" do
46
+ before (:each) do
47
+ get provider
48
+ end
49
+
50
+ it "should create a authorization for #{provider} provider" do
51
+ assigns(:user).authorizations.last.provider.should == provider.to_s.capitalize
52
+ end
53
+
54
+ it "should create a authorization for the right user" do
55
+ assigns(:user).id.should == Citygate::Authorization.last.user_id
56
+ end
57
+
58
+ it "should create a user with the correct email" do
59
+ assigns(:user).email.should == "zamith@groupbuddies.com"
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ context "facebook" do
66
+ it_behaves_like "a provider for", :facebook
67
+ end
68
+
69
+ context "google" do
70
+ it_behaves_like "a provider for", :google
71
+ end
72
+
73
+ end
@@ -0,0 +1,33 @@
1
+ Factory.define :user, :class => "Citygate::User" do |f|
2
+ f.first_name 'User'
3
+ f.email 'example@example.com'
4
+ f.password 'bigpasswordisbig'
5
+ f.password_confirmation 'bigpasswordisbig'
6
+
7
+ # required if the Devise Confirmable module is used
8
+ f.confirmed_at Time.now
9
+ end
10
+
11
+ Factory.define :facebook_auth, :class => "Citygate::Authorization" do |f|
12
+ f.provider 'Facebook'
13
+ f.uid '28'
14
+ f.name 'User'
15
+ f.link 'http://www.facebook.com/luis.zamith'
16
+ f.image_url 'http://graph.facebook.com/754864768/picture?type=square'
17
+ end
18
+
19
+ Factory.define :google_auth, :class => "Citygate::Authorization" do |f|
20
+ f.provider 'Google'
21
+ f.uid '28'
22
+ f.name 'User'
23
+ end
24
+
25
+ Factory.define :facebook_user, :parent => :user do |user|
26
+ user.first_name nil
27
+ user.after_create {|fb_user| Factory.create(:facebook_auth, :user => fb_user)}
28
+ end
29
+
30
+ Factory.define :google_user, :parent => :user do |user|
31
+ user.first_name nil
32
+ user.after_create {|g_user| Factory.create(:google_auth, :user => g_user)}
33
+ end
@@ -0,0 +1,14 @@
1
+ describe("User listing", function() {
2
+
3
+ beforeEach(function() {
4
+ loadFixtures("user_listing.html");
5
+ });
6
+
7
+ it("should add the previous page to the history", function() {
8
+ spyOnEvent($(".next_page"), 'click');
9
+ $(".next_page").click();
10
+ expect('click').toHaveBeenTriggeredOn($('.next_page'));
11
+ });
12
+
13
+
14
+ });
@@ -0,0 +1,20 @@
1
+ <div id="container" class="container">
2
+ <div id="users">
3
+ <div class="user">
4
+ <span class="email">user@example.com</span>
5
+ <span>First User</span>
6
+ <div class="user-links">
7
+ <a href="/admin/users/1" class="show-link">Show</a>
8
+ <a href="/admin/users/1/edit" class="edit-link">Edit</a>
9
+ </div>
10
+ </div>
11
+
12
+ <div class="pagination">
13
+ <span class="previous_page disabled">Previous</span>
14
+ <em class="current">1</em>
15
+ <a rel="next" href="/admin/users?page=2">2</a>
16
+ <a href="/admin/users?page=3">3</a>
17
+ <a class="next_page" rel="next" href="/admin/users?page=2">Next</a></div>
18
+ </div>
19
+ </div>
20
+ </div>
@@ -0,0 +1,9 @@
1
+ beforeEach(function() {
2
+ this.addMatchers({
3
+ toBePlaying: function(expectedSong) {
4
+ var player = this.actual;
5
+ return player.currentlyPlayingSong === expectedSong &&
6
+ player.isPlaying;
7
+ }
8
+ });
9
+ });
@@ -0,0 +1,306 @@
1
+ var readFixtures = function() {
2
+ return jasmine.getFixtures().proxyCallTo_('read', arguments);
3
+ };
4
+
5
+ var preloadFixtures = function() {
6
+ jasmine.getFixtures().proxyCallTo_('preload', arguments);
7
+ };
8
+
9
+ var loadFixtures = function() {
10
+ jasmine.getFixtures().proxyCallTo_('load', arguments);
11
+ };
12
+
13
+ var setFixtures = function(html) {
14
+ jasmine.getFixtures().set(html);
15
+ };
16
+
17
+ var sandbox = function(attributes) {
18
+ return jasmine.getFixtures().sandbox(attributes);
19
+ };
20
+
21
+ var spyOnEvent = function(selector, eventName) {
22
+ jasmine.JQuery.events.spyOn(selector, eventName);
23
+ };
24
+
25
+ jasmine.getFixtures = function() {
26
+ return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures();
27
+ };
28
+
29
+ jasmine.Fixtures = function() {
30
+ this.containerId = 'jasmine-fixtures';
31
+ this.fixturesCache_ = {};
32
+ this.fixturesPath = 'spec/javascripts/fixtures';
33
+ };
34
+
35
+ jasmine.Fixtures.prototype.set = function(html) {
36
+ this.cleanUp();
37
+ this.createContainer_(html);
38
+ };
39
+
40
+ jasmine.Fixtures.prototype.preload = function() {
41
+ this.read.apply(this, arguments);
42
+ };
43
+
44
+ jasmine.Fixtures.prototype.load = function() {
45
+ this.cleanUp();
46
+ this.createContainer_(this.read.apply(this, arguments));
47
+ };
48
+
49
+ jasmine.Fixtures.prototype.read = function() {
50
+ var htmlChunks = [];
51
+
52
+ var fixtureUrls = arguments;
53
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
54
+ htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]));
55
+ }
56
+
57
+ return htmlChunks.join('');
58
+ };
59
+
60
+ jasmine.Fixtures.prototype.clearCache = function() {
61
+ this.fixturesCache_ = {};
62
+ };
63
+
64
+ jasmine.Fixtures.prototype.cleanUp = function() {
65
+ jQuery('#' + this.containerId).remove();
66
+ };
67
+
68
+ jasmine.Fixtures.prototype.sandbox = function(attributes) {
69
+ var attributesToSet = attributes || {};
70
+ return jQuery('<div id="sandbox" />').attr(attributesToSet);
71
+ };
72
+
73
+ jasmine.Fixtures.prototype.createContainer_ = function(html) {
74
+ var container;
75
+ if(html instanceof jQuery) {
76
+ container = jQuery('<div id="' + this.containerId + '" />');
77
+ container.html(html);
78
+ } else {
79
+ container = '<div id="' + this.containerId + '">' + html + '</div>'
80
+ }
81
+ jQuery('body').append(container);
82
+ };
83
+
84
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
85
+ if (typeof this.fixturesCache_[url] == 'undefined') {
86
+ this.loadFixtureIntoCache_(url);
87
+ }
88
+ return this.fixturesCache_[url];
89
+ };
90
+
91
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
92
+ var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
93
+ var request = new XMLHttpRequest();
94
+ request.open("GET", url + "?" + new Date().getTime(), false);
95
+ request.send(null);
96
+ this.fixturesCache_[relativeUrl] = request.responseText;
97
+ };
98
+
99
+ jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
100
+ return this[methodName].apply(this, passedArguments);
101
+ };
102
+
103
+
104
+ jasmine.JQuery = function() {};
105
+
106
+ jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
107
+ return jQuery('<div/>').append(html).html();
108
+ };
109
+
110
+ jasmine.JQuery.elementToString = function(element) {
111
+ return jQuery('<div />').append($(element).clone()).html();
112
+ };
113
+
114
+ jasmine.JQuery.matchersClass = {};
115
+
116
+ (function(namespace) {
117
+ var data = {
118
+ spiedEvents: {},
119
+ handlers: []
120
+ };
121
+
122
+ namespace.events = {
123
+ spyOn: function(selector, eventName) {
124
+ var handler = function(e) {
125
+ data.spiedEvents[[selector, eventName]] = e;
126
+ };
127
+ jQuery(selector).bind(eventName, handler);
128
+ data.handlers.push(handler);
129
+ },
130
+
131
+ wasTriggered: function(selector, eventName) {
132
+ return !!(data.spiedEvents[[selector, eventName]]);
133
+ },
134
+
135
+ wasPrevented: function(selector, eventName) {
136
+ return data.spiedEvents[[selector, eventName]].isDefaultPrevented();
137
+ },
138
+
139
+ cleanUp: function() {
140
+ data.spiedEvents = {};
141
+ data.handlers = [];
142
+ }
143
+ }
144
+ })(jasmine.JQuery);
145
+
146
+ (function(){
147
+ var jQueryMatchers = {
148
+ toHaveClass: function(className) {
149
+ return this.actual.hasClass(className);
150
+ },
151
+
152
+ toBeVisible: function() {
153
+ return this.actual.is(':visible');
154
+ },
155
+
156
+ toBeHidden: function() {
157
+ return this.actual.is(':hidden');
158
+ },
159
+
160
+ toBeSelected: function() {
161
+ return this.actual.is(':selected');
162
+ },
163
+
164
+ toBeChecked: function() {
165
+ return this.actual.is(':checked');
166
+ },
167
+
168
+ toBeEmpty: function() {
169
+ return this.actual.is(':empty');
170
+ },
171
+
172
+ toExist: function() {
173
+ return this.actual.size() > 0;
174
+ },
175
+
176
+ toHaveAttr: function(attributeName, expectedAttributeValue) {
177
+ return hasProperty(this.actual.attr(attributeName), expectedAttributeValue);
178
+ },
179
+
180
+ toHaveProp: function(propertyName, expectedPropertyValue) {
181
+ return hasProperty(this.actual.prop(propertyName), expectedPropertyValue);
182
+ },
183
+
184
+ toHaveId: function(id) {
185
+ return this.actual.attr('id') == id;
186
+ },
187
+
188
+ toHaveHtml: function(html) {
189
+ return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
190
+ },
191
+
192
+ toHaveText: function(text) {
193
+ var trimmedText = $.trim(this.actual.text());
194
+ if (text && jQuery.isFunction(text.test)) {
195
+ return text.test(trimmedText);
196
+ } else {
197
+ return trimmedText == text;
198
+ }
199
+ },
200
+
201
+ toHaveValue: function(value) {
202
+ return this.actual.val() == value;
203
+ },
204
+
205
+ toHaveData: function(key, expectedValue) {
206
+ return hasProperty(this.actual.data(key), expectedValue);
207
+ },
208
+
209
+ toBe: function(selector) {
210
+ return this.actual.is(selector);
211
+ },
212
+
213
+ toContain: function(selector) {
214
+ return this.actual.find(selector).size() > 0;
215
+ },
216
+
217
+ toBeDisabled: function(selector){
218
+ return this.actual.is(':disabled');
219
+ },
220
+
221
+ toBeFocused: function(selector) {
222
+ return this.actual.is(':focus');
223
+ },
224
+
225
+ // tests the existence of a specific event binding
226
+ toHandle: function(eventName) {
227
+ var events = this.actual.data("events");
228
+ return events && events[eventName].length > 0;
229
+ },
230
+
231
+ // tests the existence of a specific event binding + handler
232
+ toHandleWith: function(eventName, eventHandler) {
233
+ var stack = this.actual.data("events")[eventName];
234
+ var i;
235
+ for (i = 0; i < stack.length; i++) {
236
+ if (stack[i].handler == eventHandler) {
237
+ return true;
238
+ }
239
+ }
240
+ return false;
241
+ }
242
+ };
243
+
244
+ var hasProperty = function(actualValue, expectedValue) {
245
+ if (expectedValue === undefined) {
246
+ return actualValue !== undefined;
247
+ }
248
+ return actualValue == expectedValue;
249
+ };
250
+
251
+ var bindMatcher = function(methodName) {
252
+ var builtInMatcher = jasmine.Matchers.prototype[methodName];
253
+
254
+ jasmine.JQuery.matchersClass[methodName] = function() {
255
+ if (this.actual
256
+ && (this.actual instanceof jQuery
257
+ || jasmine.isDomNode(this.actual))) {
258
+ this.actual = $(this.actual);
259
+ var result = jQueryMatchers[methodName].apply(this, arguments);
260
+ this.actual = jasmine.JQuery.elementToString(this.actual);
261
+ return result;
262
+ }
263
+
264
+ if (builtInMatcher) {
265
+ return builtInMatcher.apply(this, arguments);
266
+ }
267
+
268
+ return false;
269
+ };
270
+ };
271
+
272
+ for(var methodName in jQueryMatchers) {
273
+ bindMatcher(methodName);
274
+ }
275
+ })();
276
+
277
+ beforeEach(function() {
278
+ this.addMatchers(jasmine.JQuery.matchersClass);
279
+ this.addMatchers({
280
+ toHaveBeenTriggeredOn: function(selector) {
281
+ this.message = function() {
282
+ return [
283
+ "Expected event " + this.actual + " to have been triggered on " + selector,
284
+ "Expected event " + this.actual + " not to have been triggered on " + selector
285
+ ];
286
+ };
287
+ return jasmine.JQuery.events.wasTriggered($(selector), this.actual);
288
+ }
289
+ });
290
+ this.addMatchers({
291
+ toHaveBeenPreventedOn: function(selector) {
292
+ this.message = function() {
293
+ return [
294
+ "Expected event " + this.actual + " to have been prevented on " + selector,
295
+ "Expected event " + this.actual + " not to have been prevented on " + selector
296
+ ];
297
+ };
298
+ return jasmine.JQuery.events.wasPrevented(selector, this.actual);
299
+ }
300
+ });
301
+ });
302
+
303
+ afterEach(function() {
304
+ jasmine.getFixtures().cleanUp();
305
+ jasmine.JQuery.events.cleanUp();
306
+ });