cypress-on-rails 0.2.2 → 1.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.rspec +1 -0
  4. data/.travis.yml +29 -0
  5. data/CHANGELOG.md +6 -0
  6. data/README.md +155 -54
  7. data/Rakefile +8 -0
  8. data/cypress-on-rails.gemspec +10 -9
  9. data/lib/cypress-on-rails.rb +3 -1
  10. data/lib/cypress/smart_factory_wrapper.rb +3 -0
  11. data/lib/cypress_dev.rb +4 -0
  12. data/lib/cypress_dev/command_executor.rb +33 -0
  13. data/lib/cypress_dev/configuration.rb +37 -0
  14. data/lib/cypress_dev/middleware.rb +65 -0
  15. data/lib/{cypress → cypress_dev}/railtie.rb +5 -7
  16. data/lib/cypress_dev/simple_rails_factory.rb +17 -0
  17. data/lib/cypress_dev/smart_factory_wrapper.rb +79 -0
  18. data/lib/cypress_dev/version.rb +3 -0
  19. data/lib/generators/cypress_dev/install_generator.rb +59 -0
  20. data/lib/generators/cypress_dev/templates/config/initializers/cypress_dev.rb.erb +9 -0
  21. data/lib/generators/cypress_dev/templates/spec/cypress.json +4 -0
  22. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/clean.rb +7 -0
  23. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/eval.rb +1 -0
  24. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/factory_bot.rb +12 -0
  25. data/lib/generators/cypress_dev/templates/spec/cypress/app_commands/scenarios/basic.rb +2 -0
  26. data/lib/generators/cypress_dev/templates/spec/cypress/cypress_helper.rb +30 -0
  27. data/lib/generators/cypress_dev/templates/spec/cypress/integration/on_rails_spec.js +33 -0
  28. data/lib/generators/cypress_dev/templates/spec/cypress/support/commands.js +25 -0
  29. data/lib/generators/cypress_dev/templates/spec/cypress/support/index.js +21 -0
  30. data/lib/generators/cypress_dev/templates/spec/cypress/support/on-rails.js +33 -0
  31. data/spec/cypress_dev/command_executor/cypress_helper.rb +6 -0
  32. data/spec/cypress_dev/command_executor/test_command.rb +1 -0
  33. data/spec/cypress_dev/command_executor/test_command_with_options.rb +1 -0
  34. data/spec/cypress_dev/command_executor_spec.rb +33 -0
  35. data/spec/cypress_dev/configuration_spec.rb +23 -0
  36. data/spec/cypress_dev/middleware_spec.rb +104 -0
  37. data/spec/cypress_dev/railtie_spec.rb +22 -0
  38. data/spec/cypress_dev/smart_factory_wrapper_spec.rb +83 -0
  39. data/spec/integrations/rails_3_2/.gitignore +9 -0
  40. data/spec/integrations/rails_3_2/Gemfile +7 -0
  41. data/spec/integrations/rails_3_2/README.rdoc +261 -0
  42. data/spec/integrations/rails_3_2/Rakefile +7 -0
  43. data/spec/integrations/rails_3_2/app/assets/stylesheets/application.css +13 -0
  44. data/spec/integrations/rails_3_2/app/controllers/application_controller.rb +3 -0
  45. data/spec/integrations/rails_3_2/app/controllers/welcome_controller.rb +4 -0
  46. data/spec/integrations/rails_3_2/app/helpers/application_helper.rb +2 -0
  47. data/spec/integrations/rails_3_2/app/models/post.rb +13 -0
  48. data/spec/integrations/rails_3_2/app/views/layouts/application.html.erb +13 -0
  49. data/spec/integrations/rails_3_2/app/views/welcome/index.html.erb +5 -0
  50. data/spec/integrations/rails_3_2/bin/rails +6 -0
  51. data/spec/integrations/rails_3_2/config.ru +4 -0
  52. data/spec/integrations/rails_3_2/config/application.rb +69 -0
  53. data/spec/integrations/rails_3_2/config/boot.rb +6 -0
  54. data/spec/integrations/rails_3_2/config/environment.rb +5 -0
  55. data/spec/integrations/rails_3_2/config/environments/development.rb +31 -0
  56. data/spec/integrations/rails_3_2/config/environments/production.rb +64 -0
  57. data/spec/integrations/rails_3_2/config/environments/test.rb +35 -0
  58. data/spec/integrations/rails_3_2/config/initializers/backtrace_silencers.rb +7 -0
  59. data/spec/integrations/rails_3_2/config/initializers/inflections.rb +15 -0
  60. data/spec/integrations/rails_3_2/config/initializers/mime_types.rb +5 -0
  61. data/spec/integrations/rails_3_2/config/initializers/secret_token.rb +7 -0
  62. data/spec/integrations/rails_3_2/config/initializers/session_store.rb +8 -0
  63. data/spec/integrations/rails_3_2/config/initializers/wrap_parameters.rb +10 -0
  64. data/spec/integrations/rails_3_2/config/locales/en.yml +5 -0
  65. data/spec/integrations/rails_3_2/config/routes.rb +60 -0
  66. data/spec/integrations/rails_3_2/public/404.html +26 -0
  67. data/spec/integrations/rails_3_2/public/422.html +26 -0
  68. data/spec/integrations/rails_3_2/public/500.html +25 -0
  69. data/spec/integrations/rails_3_2/public/favicon.ico +0 -0
  70. data/spec/integrations/rails_3_2/public/robots.txt +5 -0
  71. data/spec/integrations/rails_3_2/test.sh +30 -0
  72. data/spec/integrations/rails_3_2/tmp/.keep +0 -0
  73. data/spec/integrations/rails_3_2/vendor/.gitkeep +0 -0
  74. data/spec/integrations/rails_4_2/.gitignore +10 -0
  75. data/spec/integrations/rails_4_2/Gemfile +8 -0
  76. data/spec/integrations/rails_4_2/README.rdoc +28 -0
  77. data/spec/integrations/rails_4_2/Rakefile +6 -0
  78. data/spec/integrations/rails_4_2/app/controllers/application_controller.rb +5 -0
  79. data/spec/integrations/rails_4_2/app/controllers/welcome_controller.rb +4 -0
  80. data/spec/integrations/rails_4_2/app/models/post.rb +13 -0
  81. data/spec/integrations/rails_4_2/app/views/layouts/application.html.erb +12 -0
  82. data/spec/integrations/rails_4_2/app/views/welcome/index.html.erb +5 -0
  83. data/spec/integrations/rails_4_2/bin/bundle +3 -0
  84. data/spec/integrations/rails_4_2/bin/rails +4 -0
  85. data/spec/integrations/rails_4_2/bin/rake +4 -0
  86. data/spec/integrations/rails_4_2/bin/setup +29 -0
  87. data/spec/integrations/rails_4_2/config.ru +4 -0
  88. data/spec/integrations/rails_4_2/config/application.rb +33 -0
  89. data/spec/integrations/rails_4_2/config/boot.rb +3 -0
  90. data/spec/integrations/rails_4_2/config/environment.rb +5 -0
  91. data/spec/integrations/rails_4_2/config/environments/development.rb +25 -0
  92. data/spec/integrations/rails_4_2/config/environments/production.rb +64 -0
  93. data/spec/integrations/rails_4_2/config/environments/test.rb +42 -0
  94. data/spec/integrations/rails_4_2/config/initializers/backtrace_silencers.rb +7 -0
  95. data/spec/integrations/rails_4_2/config/initializers/cookies_serializer.rb +3 -0
  96. data/spec/integrations/rails_4_2/config/initializers/filter_parameter_logging.rb +4 -0
  97. data/spec/integrations/rails_4_2/config/initializers/inflections.rb +16 -0
  98. data/spec/integrations/rails_4_2/config/initializers/mime_types.rb +4 -0
  99. data/spec/integrations/rails_4_2/config/initializers/session_store.rb +3 -0
  100. data/spec/integrations/rails_4_2/config/initializers/to_time_preserves_timezone.rb +10 -0
  101. data/spec/integrations/rails_4_2/config/initializers/wrap_parameters.rb +9 -0
  102. data/spec/integrations/rails_4_2/config/locales/en.yml +23 -0
  103. data/spec/integrations/rails_4_2/config/routes.rb +56 -0
  104. data/spec/integrations/rails_4_2/config/secrets.yml +22 -0
  105. data/spec/integrations/rails_4_2/public/404.html +67 -0
  106. data/spec/integrations/rails_4_2/public/422.html +67 -0
  107. data/spec/integrations/rails_4_2/public/500.html +66 -0
  108. data/spec/integrations/rails_4_2/public/favicon.ico +0 -0
  109. data/spec/integrations/rails_4_2/public/robots.txt +5 -0
  110. data/spec/integrations/rails_4_2/test.sh +31 -0
  111. data/spec/integrations/rails_4_2/vendor/.keep +0 -0
  112. data/spec/integrations/rails_5_2/.gitignore +10 -0
  113. data/spec/integrations/rails_5_2/Gemfile +12 -0
  114. data/spec/integrations/rails_5_2/README.md +24 -0
  115. data/spec/integrations/rails_5_2/Rakefile +6 -0
  116. data/spec/integrations/rails_5_2/app/controllers/application_controller.rb +2 -0
  117. data/spec/integrations/rails_5_2/app/controllers/welcome_controller.rb +4 -0
  118. data/spec/integrations/rails_5_2/app/jobs/application_job.rb +2 -0
  119. data/spec/integrations/rails_5_2/app/models/post.rb +13 -0
  120. data/spec/integrations/rails_5_2/app/views/layouts/application.html.erb +12 -0
  121. data/spec/integrations/rails_5_2/app/views/welcome/index.html.erb +5 -0
  122. data/spec/integrations/rails_5_2/bin/bundle +3 -0
  123. data/spec/integrations/rails_5_2/bin/rails +4 -0
  124. data/spec/integrations/rails_5_2/bin/rake +4 -0
  125. data/spec/integrations/rails_5_2/bin/setup +25 -0
  126. data/spec/integrations/rails_5_2/bin/update +25 -0
  127. data/spec/integrations/rails_5_2/config.ru +5 -0
  128. data/spec/integrations/rails_5_2/config/application.rb +37 -0
  129. data/spec/integrations/rails_5_2/config/boot.rb +4 -0
  130. data/spec/integrations/rails_5_2/config/credentials.yml.enc +1 -0
  131. data/spec/integrations/rails_5_2/config/environment.rb +5 -0
  132. data/spec/integrations/rails_5_2/config/environments/development.rb +40 -0
  133. data/spec/integrations/rails_5_2/config/environments/production.rb +68 -0
  134. data/spec/integrations/rails_5_2/config/environments/test.rb +36 -0
  135. data/spec/integrations/rails_5_2/config/initializers/application_controller_renderer.rb +8 -0
  136. data/spec/integrations/rails_5_2/config/initializers/backtrace_silencers.rb +7 -0
  137. data/spec/integrations/rails_5_2/config/initializers/content_security_policy.rb +25 -0
  138. data/spec/integrations/rails_5_2/config/initializers/cookies_serializer.rb +5 -0
  139. data/spec/integrations/rails_5_2/config/initializers/filter_parameter_logging.rb +4 -0
  140. data/spec/integrations/rails_5_2/config/initializers/inflections.rb +16 -0
  141. data/spec/integrations/rails_5_2/config/initializers/mime_types.rb +4 -0
  142. data/spec/integrations/rails_5_2/config/initializers/wrap_parameters.rb +9 -0
  143. data/spec/integrations/rails_5_2/config/locales/en.yml +33 -0
  144. data/spec/integrations/rails_5_2/config/master.key +1 -0
  145. data/spec/integrations/rails_5_2/config/routes.rb +4 -0
  146. data/spec/integrations/rails_5_2/public/404.html +67 -0
  147. data/spec/integrations/rails_5_2/public/422.html +67 -0
  148. data/spec/integrations/rails_5_2/public/500.html +66 -0
  149. data/spec/integrations/rails_5_2/public/apple-touch-icon-precomposed.png +0 -0
  150. data/spec/integrations/rails_5_2/public/apple-touch-icon.png +0 -0
  151. data/spec/integrations/rails_5_2/public/favicon.ico +0 -0
  152. data/spec/integrations/rails_5_2/public/robots.txt +1 -0
  153. data/spec/integrations/rails_5_2/test.sh +31 -0
  154. data/spec/integrations/rails_5_2/tmp/.keep +0 -0
  155. data/spec/integrations/rails_5_2/vendor/.keep +0 -0
  156. data/spec/spec_helper.rb +104 -0
  157. metadata +177 -25
  158. data/Gemfile.lock +0 -32
  159. data/bin/cypress +0 -3
  160. data/lib/cypress.rb +0 -27
  161. data/lib/cypress/configuration.rb +0 -41
  162. data/lib/cypress/middleware.rb +0 -69
  163. data/lib/cypress/runner.rb +0 -42
  164. data/lib/cypress/scenario_bank.rb +0 -21
  165. data/lib/cypress/scenario_context.rb +0 -23
  166. data/lib/cypress/version.rb +0 -3
  167. data/lib/generators/install_generator.rb +0 -77
@@ -0,0 +1,6 @@
1
+ class DummyTest
2
+ # @return [Array]
3
+ def self.values
4
+ @values ||= []
5
+ end
6
+ end
@@ -0,0 +1 @@
1
+ DummyTest.values << 'hello'
@@ -0,0 +1 @@
1
+ DummyTest.values << command_options
@@ -0,0 +1,33 @@
1
+ require 'cypress_dev/command_executor'
2
+
3
+ RSpec.describe CypressDev::CommandExecutor do
4
+ describe '.load' do
5
+ let(:folder) { "#{__dir__}/command_executor" }
6
+ subject { described_class }
7
+
8
+ def executor_load(*values)
9
+ subject.load(*values)
10
+ end
11
+
12
+ before do
13
+ CypressDev.configuration.cypress_folder = folder
14
+ DummyTest.values.clear if defined?(DummyTest)
15
+ end
16
+
17
+ it 'runs test command' do
18
+ executor_load("#{folder}/test_command.rb")
19
+ expect(DummyTest.values).to eq(%w(hello))
20
+ end
21
+
22
+ it 'runs test command twice' do
23
+ executor_load("#{folder}/test_command.rb")
24
+ executor_load("#{folder}/test_command.rb")
25
+ expect(DummyTest.values).to eq(%w(hello hello))
26
+ end
27
+
28
+ it 'runs command with options' do
29
+ executor_load("#{folder}/test_command_with_options.rb", 'my_string')
30
+ expect(DummyTest.values).to eq(%w(my_string))
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ require 'cypress_dev/configuration'
2
+
3
+ RSpec.describe CypressDev::Configuration do
4
+ it 'has defaults' do
5
+ CypressDev.configure { |config| config.reset }
6
+
7
+ expect(CypressDev.configuration.cypress_folder).to eq('spec/cypress')
8
+ expect(CypressDev.configuration.use_middleware?).to eq(true)
9
+ expect(CypressDev.configuration.logger).to_not be_nil
10
+ end
11
+
12
+ it 'can be configured' do
13
+ my_logger = Logger.new(STDOUT)
14
+ CypressDev.configure do |config|
15
+ config.cypress_folder = 'my/path'
16
+ config.use_middleware = false
17
+ config.logger = my_logger
18
+ end
19
+ expect(CypressDev.configuration.cypress_folder).to eq('my/path')
20
+ expect(CypressDev.configuration.use_middleware?).to eq(false)
21
+ expect(CypressDev.configuration.logger).to eq(my_logger)
22
+ end
23
+ end
@@ -0,0 +1,104 @@
1
+ require 'cypress_dev/middleware'
2
+
3
+ RSpec.describe CypressDev::Middleware do
4
+ let(:app) { ->(env) { [200, {}, ["app did #{env['PATH_INFO']}"]] } }
5
+ let(:command_executor) { class_double(CypressDev::CommandExecutor) }
6
+ let(:file) { class_double(File) }
7
+ subject { described_class.new(app, command_executor, file) }
8
+
9
+ let(:env) { {} }
10
+
11
+ let(:response) { subject.call(env) }
12
+
13
+ def rack_input(json_value)
14
+ StringIO.new(JSON.generate(json_value))
15
+ end
16
+
17
+ context '/__cypress__/command' do
18
+ before do
19
+ allow(command_executor).to receive(:load)
20
+ allow(file).to receive(:exists?)
21
+ env['PATH_INFO'] = '/__cypress__/command'
22
+ end
23
+
24
+ it 'command file exists' do
25
+ env['rack.input'] = rack_input(name: 'seed')
26
+ allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
27
+
28
+ aggregate_failures do
29
+ expect(response).to eq([201, {}, ['success']])
30
+ expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
31
+ end
32
+ end
33
+
34
+ it 'command file exists with options' do
35
+ env['rack.input'] = rack_input(name: 'seed', options: ['my_options'])
36
+ allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
37
+
38
+ aggregate_failures do
39
+ expect(response).to eq([201, {}, ['success']])
40
+ expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', ['my_options'])
41
+ end
42
+ end
43
+
44
+ it 'command file does not exists' do
45
+ env['rack.input'] = rack_input(name: 'seed')
46
+ allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(false)
47
+
48
+ aggregate_failures do
49
+ expect(response).to eq([404, {}, ['could not find command file: spec/cypress/app_commands/seed.rb']])
50
+ expect(command_executor).to_not have_received(:load)
51
+ end
52
+ end
53
+
54
+ it 'running multiple commands' do
55
+ env['rack.input'] = rack_input([{name: 'load_user'},
56
+ {name: 'load_sample', options: {'all' => 'true'}}])
57
+ allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
58
+ allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_sample.rb').and_return(true)
59
+
60
+ aggregate_failures do
61
+ expect(response).to eq([201, {}, ['success']])
62
+ expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/load_user.rb', nil)
63
+ expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/load_sample.rb', {'all' => 'true'})
64
+ end
65
+ end
66
+
67
+ it 'running multiple commands but one missing' do
68
+ env['rack.input'] = rack_input([{name: 'load_user'}, {name: 'load_sample'}])
69
+ allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
70
+ allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_sample.rb').and_return(false)
71
+
72
+ aggregate_failures do
73
+ expect(response).to eq([404, {}, ['could not find command file: spec/cypress/app_commands/load_sample.rb']])
74
+ expect(command_executor).to_not have_received(:load)
75
+ end
76
+ end
77
+ end
78
+
79
+ context '"Other paths"' do
80
+ it 'runs app' do
81
+ aggregate_failures do
82
+ %w(/ /__cypress__/login command /cypress_command /).each do |path|
83
+ env['PATH_INFO'] = path
84
+
85
+ response = subject.call(env)
86
+
87
+ expect(response).to eq([200, {}, ["app did #{path}"]])
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ context 'without stubs' do
94
+ subject { described_class.new(app) }
95
+
96
+ it 'runs' do
97
+ env['PATH_INFO'] = '/test'
98
+
99
+ response = subject.call(env)
100
+
101
+ expect(response).to eq([200, {}, ["app did /test"]])
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,22 @@
1
+ require 'cypress_dev/railtie'
2
+
3
+ module Rails
4
+ def self.env
5
+ end
6
+ end
7
+
8
+ RSpec.describe CypressDev::Railtie do
9
+ let(:rails_env) { double }
10
+ let(:middleware) { double('Middleware', use: true) }
11
+ let(:rails_app) { double('RailsApp', middleware: middleware) }
12
+
13
+ before do
14
+ allow(Rails).to receive(:env).and_return(rails_env)
15
+ end
16
+
17
+ it 'runs the middleware in test mode' do
18
+ CypressDev::Railtie.initializers.each do |initializer|
19
+ initializer.run(rails_app)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,83 @@
1
+ require 'cypress_dev/smart_factory_wrapper'
2
+
3
+ RSpec.describe CypressDev::SmartFactoryWrapper do
4
+ FileSystemDummy = Struct.new(:file_hash) do
5
+ def mtime(filename)
6
+ file_hash.fetch(filename)
7
+ end
8
+ end
9
+
10
+ let(:time_now) { Time.now }
11
+ let(:mtime_hash) { {'file1.rb' => time_now, 'file2.rb' => time_now } }
12
+ let(:files) { %w(file1.rb file2.rb) }
13
+ let(:factory_double) { double('FactoryBot', create: true, create_list: true) }
14
+ let(:factory_cleaner) { class_double(CypressDev::SmartFactoryWrapper::FactoryCleaner, clean: true) }
15
+ let(:kernel_double) { class_double(Kernel, load: true) }
16
+ let(:file_double) { FileSystemDummy.new(mtime_hash) }
17
+
18
+ subject do
19
+ described_class.new(files: files,
20
+ factory: factory_double,
21
+ kernel: kernel_double,
22
+ file_system: file_double,
23
+ factory_cleaner: factory_cleaner)
24
+ end
25
+
26
+ it 'loads all the files on first create it' do
27
+ subject.create(:user)
28
+ expect(kernel_double).to have_received(:load).with('file1.rb')
29
+ expect(kernel_double).to have_received(:load).with('file2.rb')
30
+ end
31
+
32
+ it 'loads all the files on first create_list ' do
33
+ subject.create_list(:user, 10)
34
+ expect(kernel_double).to have_received(:load).with('file1.rb')
35
+ expect(kernel_double).to have_received(:load).with('file2.rb')
36
+ end
37
+
38
+ it 'it sends delegates create to the factory' do
39
+ subject.create(:user)
40
+ expect(factory_double).to have_received(:create).with(:user)
41
+ end
42
+
43
+ it 'it sends delegates create_list to the factory' do
44
+ subject.create_list(:note, 10)
45
+ expect(factory_double).to have_received(:create_list).with(:note, 10)
46
+ end
47
+
48
+ it 'wont load the files if they have not changed' do
49
+ subject.create(:user)
50
+ subject.create_list(:user)
51
+ expect(kernel_double).to have_received(:load).with('file1.rb').once
52
+ expect(kernel_double).to have_received(:load).with('file2.rb').once
53
+ end
54
+
55
+ it 'will reload the files if a has changed' do
56
+ subject.create(:user)
57
+ expect(kernel_double).to have_received(:load).with('file1.rb').once
58
+ expect(kernel_double).to have_received(:load).with('file2.rb').once
59
+
60
+ mtime_hash['file1.rb'] = Time.now
61
+ subject.create_list(:user)
62
+ expect(kernel_double).to have_received(:load).with('file1.rb').twice
63
+ expect(kernel_double).to have_received(:load).with('file2.rb').twice
64
+ end
65
+
66
+ it 'will reset factory if a has changed' do
67
+ subject.create(:user)
68
+ expect(factory_cleaner).to have_received(:clean).with(factory_double)
69
+
70
+ mtime_hash['file1.rb'] = Time.now
71
+ subject.create_list(:user)
72
+
73
+ expect(factory_cleaner).to have_received(:clean).with(factory_double).twice
74
+ end
75
+
76
+ it 'will always reload the files enabled' do
77
+ subject.always_reload = true
78
+ subject.create_list(:user)
79
+ subject.create(:user)
80
+ expect(kernel_double).to have_received(:load).with('file1.rb').twice
81
+ expect(kernel_double).to have_received(:load).with('file2.rb').twice
82
+ end
83
+ end
@@ -0,0 +1,9 @@
1
+ .bundle
2
+ node_modules
3
+ cypress.json
4
+ package-lock.json
5
+ cypress/
6
+ config/initializers/cypress_dev.rb
7
+ vendor/bundle
8
+ tmp/pids
9
+ tmp/cache
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 3.2.22'
4
+
5
+ group :development, :test do
6
+ gem 'cypress-on-rails', path: '../../../'
7
+ end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | | |-- images
161
+ | | |-- javascripts
162
+ | | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | |-- assets
177
+ | `-- tasks
178
+ |-- log
179
+ |-- public
180
+ |-- script
181
+ |-- test
182
+ | |-- fixtures
183
+ | |-- functional
184
+ | |-- integration
185
+ | |-- performance
186
+ | `-- unit
187
+ |-- tmp
188
+ | `-- cache
189
+ | `-- assets
190
+ `-- vendor
191
+ |-- assets
192
+ | |-- javascripts
193
+ | `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.