Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. ng-show="argumentation.user_id == userid"
  2.  
  3. def create
  4. @argumentation = Argumentation.create!(
  5. title: "Labore et Dolore",
  6. content: "Errare humanum est",
  7. user_id: current_user.id #<-- Not working during the test.
  8. )
  9. end
  10.  
  11. visit "/argumentation#!/overview"
  12. click_button "Argumentation erstellen"
  13.  
  14. fill_in "argumentation_title", with: "A Defence of Moral Realism"
  15. fill_in "argumentation_content", with: "Russ Shafer-Landau"
  16.  
  17. click_button "Speichern"
  18. save_screenshot('screen.png', full: true)
  19. click_button "Übersicht" #<-- In test, this button is not there, but should be
  20.  
  21. $http.get("/getcurrentuser.json").then(function(data,status,headers,config) {
  22. $scope.userid = data.data;
  23. });
  24.  
  25. def get_current_user
  26. @id = 0
  27. if current_user
  28. @id = current_user.id
  29. end
  30. respond_to do |format|
  31. format.json { render json: @id}
  32. end
  33. end
  34.  
  35. class ActiveRecord::Base
  36. mattr_accessor :shared_connection
  37. @@shared_connection = nil
  38.  
  39. def self.connection
  40. @@shared_connection || retrieve_connection
  41. end
  42. end
  43.  
  44. # Forces all threads to share the same connection. This works on
  45. # Capybara because it starts the web server in a thread.
  46. ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
  47.  
  48. # This file is copied to spec/ when you run 'rails generate rspec:install'
  49. ENV['RAILS_ENV'] ||= 'test'
  50. require File.expand_path('../../config/environment', __FILE__)
  51. # Prevent database truncation if the environment is production
  52. abort("The Rails environment is running in production mode!") if Rails.env.production?
  53. require 'spec_helper'
  54. require 'rspec/rails'
  55. require 'devise'
  56. require 'capybara/poltergeist'
  57. Capybara.javascript_driver = :poltergeist
  58. Capybara.default_driver = :poltergeist
  59. # Add additional requires below this line. Rails is not loaded until this point!
  60.  
  61. # Requires supporting ruby files with custom matchers and macros, etc, in
  62. # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
  63. # run as spec files by default. This means that files in spec/support that end
  64. # in _spec.rb will both be required and run as specs, causing the specs to be
  65. # run twice. It is recommended that you do not name files matching this glob to
  66. # end with _spec.rb. You can configure this pattern with the --pattern
  67. # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
  68. #
  69. # The following line is provided for convenience purposes. It has the downside
  70. # of increasing the boot-up time by auto-requiring all files in the support
  71. # directory. Alternatively, in the individual `*_spec.rb` files, manually
  72. # require only the support files necessary.
  73. #
  74. # Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
  75.  
  76. # Checks for pending migration and applies them before tests are run.
  77. # If you are not using ActiveRecord, you can remove this line.
  78. ActiveRecord::Migration.maintain_test_schema!
  79.  
  80. RSpec.configure do |config|
  81. # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  82. config.fixture_path = "#{::Rails.root}/spec/fixtures"
  83. config.include Devise::Test::ControllerHelpers, type: :controller
  84. config.include Warden::Test::Helpers
  85. # If you're not using ActiveRecord, or you'd prefer not to run each of your
  86. # examples within a transaction, remove the following line or assign false
  87. # instead of true.
  88. config.use_transactional_fixtures = false
  89.  
  90. # RSpec Rails can automatically mix in different behaviours to your tests
  91. # based on their file location, for example enabling you to call `get` and
  92. # `post` in specs under `spec/controllers`.
  93. #
  94. # You can disable this behaviour by removing the line below, and instead
  95. # explicitly tag your specs with their type, e.g.:
  96. #
  97. # RSpec.describe UsersController, :type => :controller do
  98. # # ...
  99. # end
  100. #
  101. # The different available types are documented in the features, such as in
  102. # https://relishapp.com/rspec/rspec-rails/docs
  103. config.infer_spec_type_from_file_location!
  104.  
  105. # Filter lines from Rails gems in backtraces.
  106. config.filter_rails_from_backtrace!
  107. # arbitrary gems may also be filtered via:
  108. # config.filter_gems_from_backtrace("gem name")
  109. config.before(:suite) do
  110. DatabaseCleaner.clean_with(:truncation)
  111. end
  112.  
  113. config.before(:each) do
  114. DatabaseCleaner.strategy = :transaction
  115. end
  116.  
  117. config.before(:each, :type => :feature) do
  118. DatabaseCleaner.strategy = :truncation
  119. end
  120. config.before(:each) do
  121. DatabaseCleaner.start
  122. end
  123. config.after(:each) do
  124. DatabaseCleaner.clean
  125. end
  126. end
  127.  
  128. class ActiveRecord::Base
  129. mattr_accessor :shared_connection
  130. @@shared_connection = nil
  131.  
  132. def self.connection
  133. @@shared_connection || retrieve_connection
  134. end
  135. end
  136.  
  137. # Forces all threads to share the same connection. This works on
  138. # Capybara because it starts the web server in a thread.
  139. ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
  140.  
  141. let(:email) { "bob@example.com" }
  142. let(:password) { "password123" }
  143.  
  144. before do
  145. @user = User.create!(email: email,
  146. password: password,
  147. password_confirmation: password)
  148. end
  149.  
  150. login_as(@user, :scope => :user)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement