Class: CypressRails::StartsRailsServer

Inherits:
Object
  • Object
show all
Defined in:
lib/cypress-rails/starts_rails_server.rb

Instance Method Summary collapse

Instance Method Details

#call(host:, port:, transactional_server:) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/cypress-rails/starts_rails_server.rb', line 6

def call(host:, port:, transactional_server:)
  configure_rails_to_run_our_state_reset_on_every_request!(transactional_server)
  app = create_rack_app
  Server.new(app, host: host, port: port).tap do |server|
    server.boot
  end
end

#configure_rails_to_run_our_state_reset_on_every_request!(transactional_server) ⇒ Object



14
15
16
17
18
# File 'lib/cypress-rails/starts_rails_server.rb', line 14

def configure_rails_to_run_our_state_reset_on_every_request!(transactional_server)
  Rails.application.executor.to_run do
    TracksResets.instance.reset_state_if_needed(transactional_server)
  end
end

#create_rack_appObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cypress-rails/starts_rails_server.rb', line 20

def create_rack_app
  Rack::Builder.new do
    map "/cypress_rails_reset_state" do
      run lambda { |env|
        TracksResets.instance.reset_needed!
        [202, {"Content-Type" => "text/plain"}, ["Accepted"]]
      }
    end
    map "/" do
      run Rails.application
    end
  end
end