netzke-testing 0.9.1 → 0.10.0.rc1
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/Gemfile +2 -2
- data/README.md +13 -12
- data/Rakefile +7 -0
- data/app/assets/{vendor/javascripts → javascripts/netzke/testing}/expect/expect.js +0 -0
- data/app/assets/javascripts/netzke/testing/helpers/expectations.js.coffee +3 -2
- data/app/assets/javascripts/netzke/testing/helpers/queries.js.coffee +15 -1
- data/app/assets/{vendor/javascripts → javascripts/netzke/testing}/mocha/mocha.js +0 -0
- data/app/assets/{vendor/stylesheets → stylesheets/netzke/testing}/mocha/mocha.css +0 -0
- data/app/controllers/netzke/testing_controller.rb +9 -2
- data/app/views/layouts/netzke/testing.html.erb +10 -5
- data/lib/netzke/testing/helpers.rb +13 -9
- data/lib/netzke/testing/version.rb +1 -1
- data/lib/netzke/testing.rb +5 -0
- data/netzke-testing.gemspec +3 -1
- data/spec/features/foo_spec.rb +7 -0
- data/spec/features/javascripts/foo.js.coffee +6 -0
- data/spec/rails_app/.gitignore +15 -0
- data/spec/rails_app/README.rdoc +248 -15
- data/spec/rails_app/Rakefile +1 -0
- data/spec/rails_app/app/assets/images/rails.png +0 -0
- data/spec/rails_app/app/assets/javascripts/application.js +3 -4
- data/spec/rails_app/app/assets/{images/.keep → javascripts/custom.js} +0 -0
- data/spec/rails_app/app/controllers/application_controller.rb +1 -3
- data/spec/rails_app/app/{controllers/concerns/.keep → mailers/.gitkeep} +0 -0
- data/spec/rails_app/app/{mailers/.keep → models/.gitkeep} +0 -0
- data/spec/rails_app/app/views/layouts/application.html.erb +2 -2
- data/spec/rails_app/config/application.rb +44 -5
- data/spec/rails_app/config/boot.rb +2 -0
- data/spec/rails_app/config/environment.rb +2 -2
- data/spec/rails_app/config/environments/development.rb +20 -12
- data/spec/rails_app/config/environments/production.rb +27 -40
- data/spec/rails_app/config/environments/test.rb +15 -14
- data/spec/rails_app/config/initializers/inflections.rb +5 -6
- data/spec/rails_app/config/initializers/netzke_testing.rb +4 -0
- data/spec/rails_app/config/initializers/secret_token.rb +2 -7
- data/spec/rails_app/config/initializers/session_store.rb +5 -0
- data/spec/rails_app/config/initializers/wrap_parameters.rb +6 -6
- data/spec/rails_app/config/locales/en.yml +2 -20
- data/spec/rails_app/config.ru +1 -1
- data/spec/rails_app/{app/models/.keep → lib/assets/.gitkeep} +0 -0
- data/spec/rails_app/{app/models/concerns/.keep → lib/tasks/.gitkeep} +0 -0
- data/spec/rails_app/{lib/assets/.keep → log/.gitkeep} +0 -0
- data/spec/rails_app/public/404.html +11 -43
- data/spec/rails_app/public/422.html +11 -43
- data/spec/rails_app/public/500.html +11 -43
- data/spec/rails_app/public/index.html +241 -0
- data/spec/rails_app/public/robots.txt +1 -1
- data/spec/rails_app/script/rails +6 -0
- data/spec/spec_helper.rb +4 -4
- data/spec/testing_controller_spec.rb +20 -0
- metadata +61 -31
- data/spec/rails_app/bin/bundle +0 -3
- data/spec/rails_app/bin/rails +0 -4
- data/spec/rails_app/bin/rake +0 -4
- data/spec/rails_app/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/rails_app/lib/tasks/.keep +0 -0
- data/spec/rails_app/log/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a398a89114051cb8e7bdde6ee2745c8579504010
|
4
|
+
data.tar.gz: 16e5861d805b4857cfa3bba04a0812816cefb830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df63c42359d22684ed007539a5c24faa0e4722dc4f7494199c760bc0ffb748e4e2dc1fe4d75cbe7f8c406648218ef1cfe9583e744241055db4af76264dfba081
|
7
|
+
data.tar.gz: 909c16f872eb7862b59ded9bb166487136b77d92a1858df38a47a9289a6834e628b77febf4884f0c661a709173644f7c318ee84e187846968f8b41b0d0590c6c
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -24,8 +24,8 @@ the height by providing the `height` parameter in the URL:
|
|
24
24
|
|
25
25
|
## Testing components with Mocha and Expect.js
|
26
26
|
|
27
|
-
Place the Mocha specs (written in Coffeescript) for your components inside `spec/javascripts` folder. An
|
28
|
-
may look like this (in `spec/javascripts/user_grid.js.coffee`):
|
27
|
+
Place the Mocha specs (written in Coffeescript) for your components inside `spec/features/javascripts` folder. An
|
28
|
+
example spec may look like this (in `spec/features/javascripts/user_grid.js.coffee`):
|
29
29
|
|
30
30
|
describe 'UserGrid', ->
|
31
31
|
it 'shows proper title', ->
|
@@ -41,8 +41,8 @@ Specs can be structured into directories. For example, let's say we have a names
|
|
41
41
|
class Admin::UserGrid < Netzke::Basepack::Grid
|
42
42
|
end
|
43
43
|
|
44
|
-
It makes sense to put the corresponding specs in `spec/javascripts/admin/user_grid.js.coffee`. In this case,
|
45
|
-
to run the Mocha specs will be:
|
44
|
+
It makes sense to put the corresponding specs in `spec/features/javascripts/admin/user_grid.js.coffee`. In this case,
|
45
|
+
the URL to run the Mocha specs will be:
|
46
46
|
|
47
47
|
http://localhost:3000/netzke/components/UserGrid?spec=admin/user_grid
|
48
48
|
|
@@ -67,13 +67,13 @@ In order to enable these helpers, add the following line somewhere in your `RSpe
|
|
67
67
|
Keep in mind the following:
|
68
68
|
|
69
69
|
* the current set of helpers is in flux, and may be drastically changed sooner than you may expect
|
70
|
-
* the helpers directly pollute the `window` namespace; if you decide you're better off without provided
|
71
|
-
specify 'no-helpers=true' as an extra URL parameter
|
70
|
+
* the helpers directly pollute the global (`window`) namespace; if you decide you're better off without provided
|
71
|
+
helpers, specify 'no-helpers=true' as an extra URL parameter
|
72
72
|
|
73
73
|
See the [source
|
74
74
|
code](https://github.com/netzke/netzke-testing/tree/master/app/assets/javascripts/netzke/testing/helpers) for currently
|
75
75
|
implemented helpers (TODO: document them). Also, refer to other Netzke gems source code (like netzke-core and
|
76
|
-
|
76
|
+
netzke-basepack) to see examples using the helpers.
|
77
77
|
|
78
78
|
## Testing with selenium webdriver
|
79
79
|
|
@@ -81,10 +81,11 @@ Generate the `netzke_mocha_spec.rb` file that will automatically run the specs t
|
|
81
81
|
|
82
82
|
rails g netzke_testing
|
83
83
|
|
84
|
-
This spec will pick up all the `*_spec.js.coffee` files from `spec/javascripts` folder and generate an `it`
|
85
|
-
each of them. Let's say we want to create the spec for UserGrid. For this we name the spec file
|
86
|
-
`spec/javascripts/user_grid_spec.js.coffee`. And the other way around: when `netzke_mocha_spec.rb` finds a file
|
87
|
-
`spec/javascripts/order_grid_spec.js.coffee`, it'll assume existance of `OrderGrid` component that
|
84
|
+
This spec will pick up all the `*_spec.js.coffee` files from `spec/features/javascripts` folder and generate an `it`
|
85
|
+
clause for each of them. Let's say we want to create the spec for UserGrid. For this we name the spec file
|
86
|
+
`spec/features/javascripts/user_grid_spec.js.coffee`. And the other way around: when `netzke_mocha_spec.rb` finds a file
|
87
|
+
called `spec/features/javascripts/order_grid_spec.js.coffee`, it'll assume existance of `OrderGrid` component that
|
88
|
+
should be tested.
|
88
89
|
|
89
90
|
## Mixing client- and server-side testing code
|
90
91
|
|
@@ -109,7 +110,7 @@ You can explicitely specify a component to run the spec on (in order to override
|
|
109
110
|
run_mocha_spec 'grid_with_destructive_button', component: 'UserGrid'
|
110
111
|
|
111
112
|
---
|
112
|
-
Copyright (c) 2008-
|
113
|
+
Copyright (c) 2008-2014 [Max Gorin](https://twitter.com/uptomax), released under the MIT license (see LICENSE).
|
113
114
|
|
114
115
|
**Note** that Ext JS is licensed [differently](http://www.sencha.com/products/extjs/license/), and you may need to
|
115
116
|
purchase a commercial license in order to use it in your projects!
|
data/Rakefile
CHANGED
File without changes
|
@@ -1,6 +1,7 @@
|
|
1
1
|
Ext.apply window,
|
2
|
-
expectToSee: (
|
3
|
-
|
2
|
+
expectToSee: (cmp) ->
|
3
|
+
throw cmp + " not found" if Ext.isString(cmp)
|
4
|
+
expect(Ext.isObject(cmp) || Ext.isElement(cmp)).to.be.ok()
|
4
5
|
|
5
6
|
expectToNotSee: (el) ->
|
6
7
|
expect(Ext.isString(el)).to.be.ok()
|
@@ -11,7 +11,9 @@ Ext.apply window,
|
|
11
11
|
Ext.DomQuery.select("div.x-panel-body:contains(" + text + ")")[0] || 'panel with content ' + text
|
12
12
|
|
13
13
|
button: (text) ->
|
14
|
-
Ext.ComponentQuery.query("button{isVisible(true)}[text='"+text+"']")[0]
|
14
|
+
button = Ext.ComponentQuery.query("button{isVisible(true)}[text='"+text+"']")[0]
|
15
|
+
button ||= Ext.ComponentQuery.query("button{isVisible(true)}[tooltip='"+text+"']")[0]
|
16
|
+
button || "button " + text
|
15
17
|
|
16
18
|
tool: (type) ->
|
17
19
|
Ext.ComponentQuery.query("tool{isVisible(true)}[type='"+type+"']")[0] || 'tool ' + type
|
@@ -82,6 +84,18 @@ Ext.apply window,
|
|
82
84
|
return
|
83
85
|
res
|
84
86
|
|
87
|
+
eastRegion: ->
|
88
|
+
Ext.ComponentQuery.query("[region=east]")[0]
|
89
|
+
|
90
|
+
westRegion: ->
|
91
|
+
Ext.ComponentQuery.query("[region=west]")[0]
|
92
|
+
|
93
|
+
southRegion: ->
|
94
|
+
Ext.ComponentQuery.query("[region=south]")[0]
|
95
|
+
|
96
|
+
northRegion: ->
|
97
|
+
Ext.ComponentQuery.query("[region=north]")[0]
|
98
|
+
|
85
99
|
_componentLike:(type,attr,value)->
|
86
100
|
Ext.ComponentQuery.query(type+'['+attr+'='+value+']')[0] || type + " with " + attr + " '" + value + "'"
|
87
101
|
# alias
|
File without changes
|
File without changes
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'coffee-script'
|
2
2
|
|
3
3
|
class Netzke::TestingController < ApplicationController
|
4
|
+
before_filter :set_locale
|
5
|
+
|
4
6
|
def components
|
5
7
|
component_name = params[:class].gsub("::", "_").underscore
|
6
8
|
render :inline => "<%= netzke :#{component_name}, :class_name => '#{params[:class]}', :height => #{params[:height] || 400} %>",
|
@@ -14,13 +16,18 @@ class Netzke::TestingController < ApplicationController
|
|
14
16
|
|
15
17
|
private
|
16
18
|
|
19
|
+
def set_locale
|
20
|
+
# if params[:locale] is nil then I18n.default_locale will be used
|
21
|
+
I18n.locale = params[:locale]
|
22
|
+
end
|
23
|
+
|
17
24
|
def spec_file(name)
|
18
25
|
spec_root = Pathname.new(Netzke::Testing.spec_root || Rails.root)
|
19
26
|
|
20
|
-
path = spec_root.join "spec/javascripts/#{name}_spec.js.coffee"
|
27
|
+
path = spec_root.join "spec/features/javascripts/#{name}_spec.js.coffee"
|
21
28
|
|
22
29
|
if !File.exists?(File.expand_path(path, __FILE__))
|
23
|
-
path = spec_root.join "spec/javascripts/#{name}.js.coffee"
|
30
|
+
path = spec_root.join "spec/features/javascripts/#{name}.js.coffee"
|
24
31
|
end
|
25
32
|
|
26
33
|
File.read(File.expand_path(path, __FILE__))
|
@@ -6,23 +6,28 @@
|
|
6
6
|
<%= load_netzke %>
|
7
7
|
|
8
8
|
<% if params[:spec] %>
|
9
|
-
<%= javascript_include_tag "/assets/
|
10
|
-
<%= javascript_include_tag "/assets/
|
11
|
-
<%= stylesheet_link_tag "/assets/
|
9
|
+
<%= javascript_include_tag "/assets/netzke/testing/expect/expect.js" %>
|
10
|
+
<%= javascript_include_tag "/assets/netzke/testing/mocha/mocha.js" %>
|
11
|
+
<%= stylesheet_link_tag "/assets/netzke/testing/mocha/mocha.css" %>
|
12
12
|
<script>
|
13
13
|
mocha.setup('bdd');
|
14
|
-
mocha.setup({ignoreLeaks: true, slow: 500});
|
14
|
+
mocha.setup({ignoreLeaks: true, slow: 500, timeout: 5000});
|
15
15
|
Ext.onReady(function(){
|
16
16
|
Netzke.mochaRunner = mocha.run(function(){Netzke.mochaDone = true;});
|
17
17
|
});
|
18
18
|
</script>
|
19
|
-
<% if params["no-helpers"]
|
19
|
+
<% if !params["no-helpers"] %>
|
20
20
|
<%= javascript_include_tag "/assets/netzke/testing/helpers/actions" %>
|
21
21
|
<%= javascript_include_tag "/assets/netzke/testing/helpers/queries" %>
|
22
22
|
<%= javascript_include_tag "/assets/netzke/testing/helpers/expectations" %>
|
23
23
|
<%= javascript_include_tag "/assets/netzke/testing/helpers/grid" %>
|
24
24
|
<%= javascript_include_tag "/assets/netzke/testing/helpers/form" %>
|
25
25
|
<% end %>
|
26
|
+
|
27
|
+
<% for path in Netzke::Testing.custom_js %>
|
28
|
+
<%= javascript_include_tag path %>
|
29
|
+
<% end %>
|
30
|
+
|
26
31
|
<%= javascript_include_tag "/netzke/specs/#{params[:spec]}" %>
|
27
32
|
<% end %>
|
28
33
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Netzke::Testing::Helpers
|
2
2
|
def run_mocha_spec(path, options = {})
|
3
|
-
component = options[:component] || path.camelcase
|
3
|
+
@component = options[:component] || path.camelcase
|
4
4
|
locale = options[:locale]
|
5
|
-
url = netzke_components_path(class: component, spec: path)
|
5
|
+
url = netzke_components_path(class: @component, spec: path)
|
6
6
|
url << "&locale=#{locale}" if locale
|
7
7
|
|
8
8
|
visit url
|
@@ -18,8 +18,8 @@ module Netzke::Testing::Helpers
|
|
18
18
|
loop do
|
19
19
|
page.execute_script("return Netzke.mochaDone;") ? break : sleep(0.1)
|
20
20
|
|
21
|
-
# no specs are supposed to run longer than
|
22
|
-
raise "Timeout running JavaScript specs for #{component}" if Time.now > start +
|
21
|
+
# no specs are supposed to run longer than 100 seconds
|
22
|
+
raise "Timeout running JavaScript specs for #{@component}" if Time.now > start + 100.seconds
|
23
23
|
end
|
24
24
|
|
25
25
|
rescue Selenium::WebDriver::Error::JavascriptError => e
|
@@ -31,17 +31,21 @@ module Netzke::Testing::Helpers
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def assert_mocha_results
|
34
|
-
|
35
|
-
var
|
36
|
-
return
|
34
|
+
result = page.execute_script(<<-JS)
|
35
|
+
var runner = Netzke.mochaRunner;
|
36
|
+
return {
|
37
|
+
test: runner.test.title,
|
38
|
+
success: runner.stats.failures == 0 && runner.stats.tests !=0,
|
39
|
+
error: runner.test.err && runner.test.err.toString()
|
40
|
+
}
|
37
41
|
JS
|
38
42
|
|
39
|
-
if !success
|
43
|
+
if !result["success"]
|
40
44
|
# give some time for visual examination of the problem
|
41
45
|
# (TODO: make configurable)
|
42
46
|
sleep 5
|
43
47
|
|
44
|
-
raise "
|
48
|
+
raise "Test failed: #{result["test"]}\n#{result["error"]}"
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
data/lib/netzke/testing.rb
CHANGED
@@ -8,8 +8,13 @@ end
|
|
8
8
|
|
9
9
|
module Netzke
|
10
10
|
module Testing
|
11
|
+
# Path to the root of your JS specs (which are part of integration tests)
|
11
12
|
mattr_accessor :spec_root
|
12
13
|
|
14
|
+
# JS paths that should be included in the testing template
|
15
|
+
mattr_accessor :custom_js
|
16
|
+
@@custom_js = []
|
17
|
+
|
13
18
|
def self.rspec_init(rspec_config)
|
14
19
|
@@spec_root = Pathname.new(caller.first).join("../..")
|
15
20
|
rspec_config.include(Netzke::Testing::Helpers)
|
data/netzke-testing.gemspec
CHANGED
@@ -20,7 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rails"
|
23
|
+
spec.add_development_dependency "rails", "~> 3.2.0"
|
24
|
+
spec.add_development_dependency "sqlite3"
|
24
25
|
spec.add_development_dependency "rspec-rails"
|
25
26
|
spec.add_development_dependency "coffee-script"
|
27
|
+
spec.add_development_dependency 'netzke-core', '0.10.0.rc1'
|
26
28
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile ~/.gitignore_global
|
6
|
+
|
7
|
+
# Ignore bundler config
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
|
13
|
+
# Ignore all logfiles and tempfiles.
|
14
|
+
/log/*.log
|
15
|
+
/tmp
|
data/spec/rails_app/README.rdoc
CHANGED
@@ -1,28 +1,261 @@
|
|
1
|
-
==
|
1
|
+
== Welcome to Rails
|
2
2
|
|
3
|
-
|
4
|
-
|
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
5
|
|
6
|
-
|
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.
|
7
13
|
|
8
|
-
|
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.
|
9
19
|
|
10
|
-
|
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.
|
11
27
|
|
12
|
-
* Configuration
|
13
28
|
|
14
|
-
|
29
|
+
== Getting Started
|
15
30
|
|
16
|
-
|
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)
|
17
33
|
|
18
|
-
|
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)
|
19
36
|
|
20
|
-
|
37
|
+
3. Go to http://localhost:3000/ and you'll see:
|
38
|
+
"Welcome aboard: You're riding Ruby on Rails!"
|
21
39
|
|
22
|
-
|
40
|
+
4. Follow the guidelines to start developing your application. You can find
|
41
|
+
the following resources handy:
|
23
42
|
|
24
|
-
*
|
43
|
+
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
44
|
+
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
25
45
|
|
26
46
|
|
27
|
-
|
28
|
-
|
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.
|
data/spec/rails_app/Rakefile
CHANGED
Binary file
|
@@ -5,12 +5,11 @@
|
|
5
5
|
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
6
|
//
|
7
7
|
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
8
|
+
// the compiled file.
|
9
9
|
//
|
10
|
-
//
|
11
|
-
//
|
10
|
+
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
11
|
+
// GO AFTER THE REQUIRES BELOW.
|
12
12
|
//
|
13
13
|
//= require jquery
|
14
14
|
//= require jquery_ujs
|
15
|
-
//= require turbolinks
|
16
15
|
//= require_tree .
|
File without changes
|
File without changes
|
File without changes
|