* removed all microposts/follower stuff; just user sign up and login
This commit is contained in:
parent
035ebb098e
commit
15042a9c9b
|
|
@ -13,3 +13,10 @@
|
|||
# Ignore all logfiles and tempfiles.
|
||||
/log/*.log
|
||||
/tmp
|
||||
# Ignore other unneeded files.
|
||||
doc/
|
||||
*.swp
|
||||
*~
|
||||
.project
|
||||
.DS_Store
|
||||
.idea
|
||||
|
|
|
|||
51
Gemfile
51
Gemfile
|
|
@ -1,40 +1,39 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem 'rails', '3.2.8'
|
||||
gem 'jquery-rails', '2.0.2'
|
||||
gem 'bootstrap-sass', '2.0.4'
|
||||
gem 'bcrypt-ruby', '3.0.1'
|
||||
gem 'faker', '1.0.1'
|
||||
gem 'will_paginate', '3.0.3'
|
||||
gem 'bootstrap-will_paginate', '0.0.6'
|
||||
|
||||
# Bundle edge Rails instead:
|
||||
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
||||
|
||||
group :development do
|
||||
gem 'pg', '0.14.0'
|
||||
group :development, :test do
|
||||
gem 'sqlite3', '1.3.5'
|
||||
gem 'rspec-rails', '2.11.0'
|
||||
gem 'guard-rspec', '0.5.5'
|
||||
end
|
||||
|
||||
|
||||
# Gems used only for assets and not required
|
||||
# in production environments by default.
|
||||
group :assets do
|
||||
gem 'sass-rails', '3.2.5'
|
||||
gem 'sass-rails', '3.2.5'
|
||||
gem 'coffee-rails', '3.2.2'
|
||||
|
||||
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
|
||||
# gem 'therubyracer', :platforms => :ruby
|
||||
|
||||
gem 'uglifier', '1.2.3'
|
||||
end
|
||||
|
||||
gem 'jquery-rails', '2.0.2'
|
||||
group :test do
|
||||
gem 'capybara', '1.1.2'
|
||||
gem 'factory_girl_rails', '1.4.0'
|
||||
gem 'cucumber-rails', '1.2.1', :require => false
|
||||
gem 'database_cleaner', '0.7.0'
|
||||
gem 'guard-spork', '0.3.2'
|
||||
gem 'spork', '0.9.0'
|
||||
gem 'launchy', '2.1.0'
|
||||
# gem 'rb-fsevent', '0.9.1', :require => false
|
||||
# gem 'growl', '1.0.3'
|
||||
end
|
||||
|
||||
# To use ActiveModel has_secure_password
|
||||
# gem 'bcrypt-ruby', '~> 3.0.0'
|
||||
|
||||
# To use Jbuilder templates for JSON
|
||||
# gem 'jbuilder'
|
||||
|
||||
# Use unicorn as the app server
|
||||
# gem 'unicorn'
|
||||
|
||||
# Deploy with Capistrano
|
||||
# gem 'capistrano'
|
||||
|
||||
# To use debugger
|
||||
# gem 'debugger'
|
||||
group :production do
|
||||
gem 'pg', '0.12.2'
|
||||
end
|
||||
105
Gemfile.lock
105
Gemfile.lock
|
|
@ -28,8 +28,22 @@ GEM
|
|||
activesupport (3.2.8)
|
||||
i18n (~> 0.6)
|
||||
multi_json (~> 1.0)
|
||||
addressable (2.2.8)
|
||||
arel (3.0.2)
|
||||
bcrypt-ruby (3.0.1)
|
||||
bootstrap-sass (2.0.4.0)
|
||||
bootstrap-will_paginate (0.0.6)
|
||||
will_paginate
|
||||
builder (3.0.0)
|
||||
capybara (1.1.2)
|
||||
mime-types (>= 1.16)
|
||||
nokogiri (>= 1.3.3)
|
||||
rack (>= 1.0.0)
|
||||
rack-test (>= 0.5.4)
|
||||
selenium-webdriver (~> 2.0)
|
||||
xpath (~> 0.1.4)
|
||||
childprocess (0.3.2)
|
||||
ffi (~> 1.0.6)
|
||||
coffee-rails (3.2.2)
|
||||
coffee-script (>= 2.2.0)
|
||||
railties (~> 3.2.0)
|
||||
|
|
@ -37,23 +51,61 @@ GEM
|
|||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.3.3)
|
||||
cucumber (1.2.0)
|
||||
builder (>= 2.1.2)
|
||||
diff-lcs (>= 1.1.3)
|
||||
gherkin (~> 2.10.0)
|
||||
json (>= 1.4.6)
|
||||
cucumber-rails (1.2.1)
|
||||
capybara (>= 1.1.2)
|
||||
cucumber (>= 1.1.3)
|
||||
nokogiri (>= 1.5.0)
|
||||
database_cleaner (0.7.0)
|
||||
diff-lcs (1.1.3)
|
||||
erubis (2.7.0)
|
||||
execjs (1.4.0)
|
||||
multi_json (~> 1.0)
|
||||
factory_girl (2.3.2)
|
||||
activesupport
|
||||
factory_girl_rails (1.4.0)
|
||||
factory_girl (~> 2.3.0)
|
||||
railties (>= 3.0.0)
|
||||
faker (1.0.1)
|
||||
i18n (~> 0.4)
|
||||
ffi (1.0.11)
|
||||
gherkin (2.10.0)
|
||||
json (>= 1.4.6)
|
||||
guard (1.1.1)
|
||||
listen (>= 0.4.2)
|
||||
thor (>= 0.14.6)
|
||||
guard-rspec (0.5.5)
|
||||
guard (>= 0.8.4)
|
||||
guard-spork (0.3.2)
|
||||
guard (>= 0.8.4)
|
||||
spork (>= 0.8.4)
|
||||
hike (1.2.1)
|
||||
i18n (0.6.0)
|
||||
journey (1.0.4)
|
||||
jquery-rails (2.0.2)
|
||||
railties (>= 3.2.0, < 5.0)
|
||||
thor (~> 0.14)
|
||||
json (1.7.5)
|
||||
json (1.7.4)
|
||||
launchy (2.1.0)
|
||||
addressable (~> 2.2.6)
|
||||
libwebsocket (0.1.3)
|
||||
addressable
|
||||
listen (0.4.2)
|
||||
rb-fchange (~> 0.0.5)
|
||||
rb-fsevent (~> 0.9.1)
|
||||
rb-inotify (~> 0.8.8)
|
||||
mail (2.4.4)
|
||||
i18n (>= 0.4.0)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
mime-types (1.19)
|
||||
multi_json (1.3.6)
|
||||
pg (0.14.0)
|
||||
nokogiri (1.5.5)
|
||||
pg (0.12.2)
|
||||
polyglot (0.3.3)
|
||||
rack (1.4.1)
|
||||
rack-cache (1.2)
|
||||
|
|
@ -78,18 +130,45 @@ GEM
|
|||
rdoc (~> 3.4)
|
||||
thor (>= 0.14.6, < 2.0)
|
||||
rake (0.9.2.2)
|
||||
rb-fchange (0.0.5)
|
||||
ffi
|
||||
rb-fsevent (0.9.1)
|
||||
rb-inotify (0.8.8)
|
||||
ffi (>= 0.5.0)
|
||||
rdoc (3.12)
|
||||
json (~> 1.4)
|
||||
rspec (2.11.0)
|
||||
rspec-core (~> 2.11.0)
|
||||
rspec-expectations (~> 2.11.0)
|
||||
rspec-mocks (~> 2.11.0)
|
||||
rspec-core (2.11.1)
|
||||
rspec-expectations (2.11.2)
|
||||
diff-lcs (~> 1.1.3)
|
||||
rspec-mocks (2.11.2)
|
||||
rspec-rails (2.11.0)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
rspec (~> 2.11.0)
|
||||
rubyzip (0.9.8)
|
||||
sass (3.2.1)
|
||||
sass-rails (3.2.5)
|
||||
railties (~> 3.2.0)
|
||||
sass (>= 3.1.10)
|
||||
tilt (~> 1.3)
|
||||
selenium-webdriver (2.22.2)
|
||||
childprocess (>= 0.2.5)
|
||||
ffi (~> 1.0)
|
||||
libwebsocket (~> 0.1.3)
|
||||
multi_json (~> 1.0)
|
||||
rubyzip
|
||||
spork (0.9.0)
|
||||
sprockets (2.1.3)
|
||||
hike (~> 1.2)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
thor (0.16.0)
|
||||
sqlite3 (1.3.5)
|
||||
thor (0.15.4)
|
||||
tilt (1.3.3)
|
||||
treetop (1.4.10)
|
||||
polyglot
|
||||
|
|
@ -98,14 +177,32 @@ GEM
|
|||
uglifier (1.2.3)
|
||||
execjs (>= 0.3.0)
|
||||
multi_json (>= 1.0.2)
|
||||
will_paginate (3.0.3)
|
||||
xpath (0.1.4)
|
||||
nokogiri (~> 1.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
bcrypt-ruby (= 3.0.1)
|
||||
bootstrap-sass (= 2.0.4)
|
||||
bootstrap-will_paginate (= 0.0.6)
|
||||
capybara (= 1.1.2)
|
||||
coffee-rails (= 3.2.2)
|
||||
cucumber-rails (= 1.2.1)
|
||||
database_cleaner (= 0.7.0)
|
||||
factory_girl_rails (= 1.4.0)
|
||||
faker (= 1.0.1)
|
||||
guard-rspec (= 0.5.5)
|
||||
guard-spork (= 0.3.2)
|
||||
jquery-rails (= 2.0.2)
|
||||
pg (= 0.14.0)
|
||||
launchy (= 2.1.0)
|
||||
pg (= 0.12.2)
|
||||
rails (= 3.2.8)
|
||||
rspec-rails (= 2.11.0)
|
||||
sass-rails (= 3.2.5)
|
||||
spork (= 0.9.0)
|
||||
sqlite3 (= 1.3.5)
|
||||
uglifier (= 1.2.3)
|
||||
will_paginate (= 3.0.3)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
# A sample Guardfile
|
||||
# More info at https://github.com/guard/guard#readme
|
||||
|
||||
require 'active_support/core_ext'
|
||||
|
||||
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
|
||||
watch('config/application.rb')
|
||||
watch('config/environment.rb')
|
||||
watch(%r{^config/environments/.+\.rb$})
|
||||
watch(%r{^config/initializers/.+\.rb$})
|
||||
watch('Gemfile')
|
||||
watch('Gemfile.lock')
|
||||
watch('spec/spec_helper.rb')
|
||||
watch('test/test_helper.rb')
|
||||
watch('spec/support/')
|
||||
end
|
||||
|
||||
guard 'rspec', :version => 2, :all_after_pass => false, :cli => '--drb' do
|
||||
watch(%r{^spec/.+_spec\.rb$})
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
|
||||
# Rails example
|
||||
watch(%r{^spec/.+_spec\.rb$})
|
||||
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
||||
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
||||
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
||||
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
watch('config/routes.rb') { "spec/routing" }
|
||||
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
||||
# Capybara request specs
|
||||
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
||||
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
|
||||
["spec/routing/#{m[1]}_routing_spec.rb",
|
||||
"spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
|
||||
"spec/acceptance/#{m[1]}_spec.rb",
|
||||
"spec/requests/#{m[1].singularize}_pages_spec.rb",
|
||||
(m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
|
||||
"spec/requests/#{m[1].singularize}_pages_spec.rb")]
|
||||
end
|
||||
watch(%r{^app/views/(.+)/}) do |m|
|
||||
"spec/requests/#{m[1].singularize}_pages_spec.rb"
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
The Ruby on Rails Tutorial source code is licensed jointly
|
||||
under the MIT License and the Beerware License.
|
||||
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2012 Michael Hartl
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:</p>
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.</p>
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* "THE BEER-WARE LICENSE" (Revision 42):
|
||||
* Michael Hartl wrote this code. As long as you retain this notice you
|
||||
* can do whatever you want with this stuff. If we meet some day, and you think
|
||||
* this stuff is worth it, you can buy me a beer in return.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
# Ruby on Rails Tutorial: sample application
|
||||
|
||||
This is the sample application for
|
||||
[*Ruby on Rails Tutorial: Learn Web Development with Rails*](http://railstutorial.org/)
|
||||
by [Michael Hartl](http://michaelhartl.com/). You can use this reference implementation to help track down errors if you end up having trouble with code in the tutorial. In particular, as a first debugging check I suggest getting the test suite to pass on your local machine:
|
||||
|
||||
$ cd /tmp
|
||||
$ git clone git@github.com:railstutorial/sample_app_2nd_ed.git
|
||||
$ cd sample_app_2nd_ed
|
||||
$ bundle install
|
||||
$ bundle exec rake db:migrate
|
||||
$ bundle exec rake db:test:prepare
|
||||
$ bundle exec rspec spec/
|
||||
|
||||
If the tests don't pass, it means there may be something wrong with your system. If they do pass, then you can debug your code by comparing it with the reference implementation.
|
||||
261
README.rdoc
261
README.rdoc
|
|
@ -1,261 +0,0 @@
|
|||
== Welcome to Rails
|
||||
|
||||
Rails is a web-application framework that includes everything needed to create
|
||||
database-backed web applications according to the Model-View-Control pattern.
|
||||
|
||||
This pattern splits the view (also called the presentation) into "dumb"
|
||||
templates that are primarily responsible for inserting pre-built data in between
|
||||
HTML tags. The model contains the "smart" domain objects (such as Account,
|
||||
Product, Person, Post) that holds all the business logic and knows how to
|
||||
persist themselves to a database. The controller handles the incoming requests
|
||||
(such as Save New Account, Update Product, Show Post) by manipulating the model
|
||||
and directing data to the view.
|
||||
|
||||
In Rails, the model is handled by what's called an object-relational mapping
|
||||
layer entitled Active Record. This layer allows you to present the data from
|
||||
database rows as objects and embellish these data objects with business logic
|
||||
methods. You can read more about Active Record in
|
||||
link:files/vendor/rails/activerecord/README.html.
|
||||
|
||||
The controller and view are handled by the Action Pack, which handles both
|
||||
layers by its two parts: Action View and Action Controller. These two layers
|
||||
are bundled in a single package due to their heavy interdependence. This is
|
||||
unlike the relationship between the Active Record and Action Pack that is much
|
||||
more separate. Each of these packages can be used independently outside of
|
||||
Rails. You can read more about Action Pack in
|
||||
link:files/vendor/rails/actionpack/README.html.
|
||||
|
||||
|
||||
== Getting Started
|
||||
|
||||
1. At the command prompt, create a new Rails application:
|
||||
<tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
|
||||
|
||||
2. Change directory to <tt>myapp</tt> and start the web server:
|
||||
<tt>cd myapp; rails server</tt> (run with --help for options)
|
||||
|
||||
3. Go to http://localhost:3000/ and you'll see:
|
||||
"Welcome aboard: You're riding Ruby on Rails!"
|
||||
|
||||
4. Follow the guidelines to start developing your application. You can find
|
||||
the following resources handy:
|
||||
|
||||
* The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
|
||||
* Ruby on Rails Tutorial Book: http://www.railstutorial.org/
|
||||
|
||||
|
||||
== Debugging Rails
|
||||
|
||||
Sometimes your application goes wrong. Fortunately there are a lot of tools that
|
||||
will help you debug it and get it back on the rails.
|
||||
|
||||
First area to check is the application log files. Have "tail -f" commands
|
||||
running on the server.log and development.log. Rails will automatically display
|
||||
debugging and runtime information to these files. Debugging info will also be
|
||||
shown in the browser on requests from 127.0.0.1.
|
||||
|
||||
You can also log your own messages directly into the log file from your code
|
||||
using the Ruby logger class from inside your controllers. Example:
|
||||
|
||||
class WeblogController < ActionController::Base
|
||||
def destroy
|
||||
@weblog = Weblog.find(params[:id])
|
||||
@weblog.destroy
|
||||
logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
|
||||
end
|
||||
end
|
||||
|
||||
The result will be a message in your log file along the lines of:
|
||||
|
||||
Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
|
||||
|
||||
More information on how to use the logger is at http://www.ruby-doc.org/core/
|
||||
|
||||
Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
|
||||
several books available online as well:
|
||||
|
||||
* Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
|
||||
* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
|
||||
|
||||
These two books will bring you up to speed on the Ruby language and also on
|
||||
programming in general.
|
||||
|
||||
|
||||
== Debugger
|
||||
|
||||
Debugger support is available through the debugger command when you start your
|
||||
Mongrel or WEBrick server with --debugger. This means that you can break out of
|
||||
execution at any point in the code, investigate and change the model, and then,
|
||||
resume execution! You need to install ruby-debug to run the server in debugging
|
||||
mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
|
||||
|
||||
class WeblogController < ActionController::Base
|
||||
def index
|
||||
@posts = Post.all
|
||||
debugger
|
||||
end
|
||||
end
|
||||
|
||||
So the controller will accept the action, run the first line, then present you
|
||||
with a IRB prompt in the server window. Here you can do things like:
|
||||
|
||||
>> @posts.inspect
|
||||
=> "[#<Post:0x14a6be8
|
||||
@attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
|
||||
#<Post:0x14a6620
|
||||
@attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
|
||||
>> @posts.first.title = "hello from a debugger"
|
||||
=> "hello from a debugger"
|
||||
|
||||
...and even better, you can examine how your runtime objects actually work:
|
||||
|
||||
>> f = @posts.first
|
||||
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
||||
>> f.
|
||||
Display all 152 possibilities? (y or n)
|
||||
|
||||
Finally, when you're ready to resume execution, you can enter "cont".
|
||||
|
||||
|
||||
== Console
|
||||
|
||||
The console is a Ruby shell, which allows you to interact with your
|
||||
application's domain model. Here you'll have all parts of the application
|
||||
configured, just like it is when the application is running. You can inspect
|
||||
domain models, change values, and save to the database. Starting the script
|
||||
without arguments will launch it in the development environment.
|
||||
|
||||
To start the console, run <tt>rails console</tt> from the application
|
||||
directory.
|
||||
|
||||
Options:
|
||||
|
||||
* Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
|
||||
made to the database.
|
||||
* Passing an environment name as an argument will load the corresponding
|
||||
environment. Example: <tt>rails console production</tt>.
|
||||
|
||||
To reload your controllers and models after launching the console run
|
||||
<tt>reload!</tt>
|
||||
|
||||
More information about irb can be found at:
|
||||
link:http://www.rubycentral.org/pickaxe/irb.html
|
||||
|
||||
|
||||
== dbconsole
|
||||
|
||||
You can go to the command line of your database directly through <tt>rails
|
||||
dbconsole</tt>. You would be connected to the database with the credentials
|
||||
defined in database.yml. Starting the script without arguments will connect you
|
||||
to the development database. Passing an argument will connect you to a different
|
||||
database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
|
||||
PostgreSQL and SQLite 3.
|
||||
|
||||
== Description of Contents
|
||||
|
||||
The default directory structure of a generated Ruby on Rails application:
|
||||
|
||||
|-- app
|
||||
| |-- assets
|
||||
| |-- images
|
||||
| |-- javascripts
|
||||
| `-- stylesheets
|
||||
| |-- controllers
|
||||
| |-- helpers
|
||||
| |-- mailers
|
||||
| |-- models
|
||||
| `-- views
|
||||
| `-- layouts
|
||||
|-- config
|
||||
| |-- environments
|
||||
| |-- initializers
|
||||
| `-- locales
|
||||
|-- db
|
||||
|-- doc
|
||||
|-- lib
|
||||
| `-- tasks
|
||||
|-- log
|
||||
|-- public
|
||||
|-- script
|
||||
|-- test
|
||||
| |-- fixtures
|
||||
| |-- functional
|
||||
| |-- integration
|
||||
| |-- performance
|
||||
| `-- unit
|
||||
|-- tmp
|
||||
| |-- cache
|
||||
| |-- pids
|
||||
| |-- sessions
|
||||
| `-- sockets
|
||||
`-- vendor
|
||||
|-- assets
|
||||
`-- stylesheets
|
||||
`-- plugins
|
||||
|
||||
app
|
||||
Holds all the code that's specific to this particular application.
|
||||
|
||||
app/assets
|
||||
Contains subdirectories for images, stylesheets, and JavaScript files.
|
||||
|
||||
app/controllers
|
||||
Holds controllers that should be named like weblogs_controller.rb for
|
||||
automated URL mapping. All controllers should descend from
|
||||
ApplicationController which itself descends from ActionController::Base.
|
||||
|
||||
app/models
|
||||
Holds models that should be named like post.rb. Models descend from
|
||||
ActiveRecord::Base by default.
|
||||
|
||||
app/views
|
||||
Holds the template files for the view that should be named like
|
||||
weblogs/index.html.erb for the WeblogsController#index action. All views use
|
||||
eRuby syntax by default.
|
||||
|
||||
app/views/layouts
|
||||
Holds the template files for layouts to be used with views. This models the
|
||||
common header/footer method of wrapping views. In your views, define a layout
|
||||
using the <tt>layout :default</tt> and create a file named default.html.erb.
|
||||
Inside default.html.erb, call <% yield %> to render the view using this
|
||||
layout.
|
||||
|
||||
app/helpers
|
||||
Holds view helpers that should be named like weblogs_helper.rb. These are
|
||||
generated for you automatically when using generators for controllers.
|
||||
Helpers can be used to wrap functionality for your views into methods.
|
||||
|
||||
config
|
||||
Configuration files for the Rails environment, the routing map, the database,
|
||||
and other dependencies.
|
||||
|
||||
db
|
||||
Contains the database schema in schema.rb. db/migrate contains all the
|
||||
sequence of Migrations for your schema.
|
||||
|
||||
doc
|
||||
This directory is where your application documentation will be stored when
|
||||
generated using <tt>rake doc:app</tt>
|
||||
|
||||
lib
|
||||
Application specific libraries. Basically, any kind of custom code that
|
||||
doesn't belong under controllers, models, or helpers. This directory is in
|
||||
the load path.
|
||||
|
||||
public
|
||||
The directory available for the web server. Also contains the dispatchers and the
|
||||
default HTML files. This should be set as the DOCUMENT_ROOT of your web
|
||||
server.
|
||||
|
||||
script
|
||||
Helper scripts for automation and generation.
|
||||
|
||||
test
|
||||
Unit and functional tests along with fixtures. When using the rails generate
|
||||
command, template test files will be generated for you and placed in this
|
||||
directory.
|
||||
|
||||
vendor
|
||||
External libraries that the application depends on. Also includes the plugins
|
||||
subdirectory. If the app has frozen rails, those gems also go here, under
|
||||
vendor/rails/. This directory is in the load path.
|
||||
2
Rakefile
2
Rakefile
|
|
@ -4,4 +4,4 @@
|
|||
|
||||
require File.expand_path('../config/application', __FILE__)
|
||||
|
||||
JamWeb::Application.load_tasks
|
||||
SampleApp::Application.load_tasks
|
||||
|
|
|
|||
|
|
@ -12,4 +12,5 @@
|
|||
//
|
||||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require bootstrap
|
||||
//= require_tree .
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
||||
|
|
@ -10,4 +10,4 @@
|
|||
*
|
||||
*= require_self
|
||||
*= require_tree .
|
||||
*/
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,242 @@
|
|||
@import "bootstrap";
|
||||
|
||||
/* mixins, variables, etc. */
|
||||
|
||||
$grayMediumLight: #eaeaea;
|
||||
|
||||
@mixin box_sizing {
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* universal */
|
||||
|
||||
html {
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
body {
|
||||
padding-top: 60px;
|
||||
}
|
||||
|
||||
section {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
textarea {
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.center {
|
||||
text-align: center;
|
||||
h1 {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
/* typography */
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3em;
|
||||
letter-spacing: -2px;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.7em;
|
||||
letter-spacing: -1px;
|
||||
margin-bottom: 30px;
|
||||
text-align: center;
|
||||
font-weight: normal;
|
||||
color: $grayLight;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1.1em;
|
||||
line-height: 1.7em;
|
||||
}
|
||||
|
||||
|
||||
/* header */
|
||||
|
||||
#logo {
|
||||
float: left;
|
||||
margin-right: 10px;
|
||||
font-size: 1.7em;
|
||||
color: white;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: -1px;
|
||||
padding-top: 9px;
|
||||
font-weight: bold;
|
||||
line-height: 1;
|
||||
&:hover {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* footer */
|
||||
|
||||
footer {
|
||||
margin-top: 45px;
|
||||
padding-top: 5px;
|
||||
border-top: 1px solid $grayMediumLight;
|
||||
color: $grayLight;
|
||||
a {
|
||||
color: $gray;
|
||||
&:hover {
|
||||
color: $grayDarker;
|
||||
}
|
||||
}
|
||||
small {
|
||||
float: left;
|
||||
}
|
||||
ul {
|
||||
float: right;
|
||||
list-style: none;
|
||||
li {
|
||||
float: left;
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* miscellaneous */
|
||||
|
||||
.debug_dump {
|
||||
clear: both;
|
||||
float: left;
|
||||
width: 100%;
|
||||
margin-top: 45px;
|
||||
@include box_sizing;
|
||||
}
|
||||
|
||||
/* sidebar */
|
||||
|
||||
aside {
|
||||
section {
|
||||
padding: 10px 0;
|
||||
border-top: 1px solid $grayLighter;
|
||||
&:first-child {
|
||||
border: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
span {
|
||||
display: block;
|
||||
margin-bottom: 3px;
|
||||
line-height: 1;
|
||||
}
|
||||
h1 {
|
||||
font-size: 1.6em;
|
||||
text-align: left;
|
||||
letter-spacing: -1px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.gravatar {
|
||||
float: left;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.stats {
|
||||
overflow: auto;
|
||||
a {
|
||||
float: left;
|
||||
padding: 0 10px;
|
||||
border-left: 1px solid $grayLighter;
|
||||
color: gray;
|
||||
&:first-child {
|
||||
padding-left: 0;
|
||||
border: 0;
|
||||
}
|
||||
&:hover {
|
||||
text-decoration: none;
|
||||
color: $blue;
|
||||
}
|
||||
}
|
||||
strong {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.user_avatars {
|
||||
overflow: auto;
|
||||
margin-top: 10px;
|
||||
.gravatar {
|
||||
margin: 1px 1px;
|
||||
}
|
||||
}
|
||||
|
||||
/* forms */
|
||||
|
||||
input, textarea, select, .uneditable-input {
|
||||
border: 1px solid #bbb;
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
height: auto;
|
||||
margin-bottom: 15px;
|
||||
@include box_sizing;
|
||||
}
|
||||
|
||||
#error_explanation {
|
||||
color:#f00;
|
||||
ul {
|
||||
list-style: none;
|
||||
margin: 0 0 18px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.field_with_errors {
|
||||
@extend .control-group;
|
||||
@extend .error;
|
||||
}
|
||||
|
||||
/* users index */
|
||||
|
||||
.users {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
li {
|
||||
overflow: auto;
|
||||
padding: 10px 0;
|
||||
border-top: 1px solid $grayLighter;
|
||||
&:last-child {
|
||||
border-bottom: 1px solid $grayLighter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* microposts */
|
||||
|
||||
.microposts {
|
||||
list-style: none;
|
||||
margin: 10px 0 0 0;
|
||||
|
||||
li {
|
||||
padding: 10px 0;
|
||||
border-top: 1px solid #e8e8e8;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.timestamp {
|
||||
color: $grayLight;
|
||||
}
|
||||
|
||||
aside {
|
||||
textarea {
|
||||
height: 100px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the Sessions controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the StaticPages controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the Users controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery
|
||||
include SessionsHelper
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
class SessionsController < ApplicationController
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
user = User.find_by_email(params[:session][:email])
|
||||
if user && user.authenticate(params[:session][:password])
|
||||
sign_in user
|
||||
redirect_back_or user
|
||||
else
|
||||
flash.now[:error] = 'Invalid email/password combination'
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
sign_out
|
||||
redirect_to root_url
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
class StaticPagesController < ApplicationController
|
||||
|
||||
def home
|
||||
if signed_in?
|
||||
# current_user is reference to the current user... use it to ask stuff about the user and show something
|
||||
end
|
||||
end
|
||||
|
||||
def help
|
||||
end
|
||||
|
||||
def about
|
||||
end
|
||||
|
||||
def contact
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
class UsersController < ApplicationController
|
||||
before_filter :signed_in_user,
|
||||
only: [:index, :edit, :update, :destroy, :following, :followers]
|
||||
before_filter :correct_user, only: [:edit, :update]
|
||||
before_filter :admin_user, only: :destroy
|
||||
|
||||
def index
|
||||
@users = User.paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
@microposts = @user.microposts.paginate(page: params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(params[:user])
|
||||
if @user.save
|
||||
sign_in @user
|
||||
flash[:success] = "Welcome to the Sample App!"
|
||||
redirect_to @user
|
||||
else
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @user.update_attributes(params[:user])
|
||||
flash[:success] = "Profile updated"
|
||||
sign_in @user
|
||||
redirect_to @user
|
||||
else
|
||||
render 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
User.find(params[:id]).destroy
|
||||
flash[:success] = "User destroyed."
|
||||
redirect_to users_url
|
||||
end
|
||||
|
||||
def following
|
||||
@title = "Following"
|
||||
@user = User.find(params[:id])
|
||||
@users = @user.followed_users.paginate(page: params[:page])
|
||||
render 'show_follow'
|
||||
end
|
||||
|
||||
def followers
|
||||
@title = "Followers"
|
||||
@user = User.find(params[:id])
|
||||
@users = @user.followers.paginate(page: params[:page])
|
||||
render 'show_follow'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def correct_user
|
||||
@user = User.find(params[:id])
|
||||
redirect_to(root_url) unless current_user?(@user)
|
||||
end
|
||||
|
||||
def admin_user
|
||||
redirect_to(root_url) unless current_user.admin?
|
||||
end
|
||||
end
|
||||
|
|
@ -1,2 +1,12 @@
|
|||
module ApplicationHelper
|
||||
|
||||
# Returns the full title on a per-page basis.
|
||||
def full_title(page_title)
|
||||
base_title = "Ruby on Rails Tutorial Sample App"
|
||||
if page_title.empty?
|
||||
base_title
|
||||
else
|
||||
"#{base_title} | #{page_title}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
module SessionsHelper
|
||||
|
||||
def sign_in(user)
|
||||
cookies.permanent[:remember_token] = user.remember_token
|
||||
self.current_user = user
|
||||
end
|
||||
|
||||
def signed_in?
|
||||
!current_user.nil?
|
||||
end
|
||||
|
||||
def current_user=(user)
|
||||
@current_user = user
|
||||
end
|
||||
|
||||
def current_user
|
||||
@current_user ||= User.find_by_remember_token(cookies[:remember_token])
|
||||
end
|
||||
|
||||
def current_user?(user)
|
||||
user == current_user
|
||||
end
|
||||
|
||||
def signed_in_user
|
||||
unless signed_in?
|
||||
store_location
|
||||
redirect_to signin_url, notice: "Please sign in."
|
||||
end
|
||||
end
|
||||
|
||||
def sign_out
|
||||
current_user = nil
|
||||
cookies.delete(:remember_token)
|
||||
end
|
||||
|
||||
def redirect_back_or(default)
|
||||
redirect_to(session[:return_to] || default)
|
||||
session.delete(:return_to)
|
||||
end
|
||||
|
||||
def store_location
|
||||
session[:return_to] = request.url
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
module StaticPagesHelper
|
||||
end
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
module UsersHelper
|
||||
|
||||
# Returns the Gravatar (http://gravatar.com/) for the given user.
|
||||
def gravatar_for(user, options = { size: 50 })
|
||||
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
|
||||
size = options[:size]
|
||||
gravatar =
|
||||
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
|
||||
image_tag(gravatar_url, alt: user.name, class: "gravatar")
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
class Relationship < ActiveRecord::Base
|
||||
attr_accessible :followed_id
|
||||
|
||||
belongs_to :follower, class_name: "User"
|
||||
belongs_to :followed, class_name: "User"
|
||||
|
||||
validates :follower_id, presence: true
|
||||
validates :followed_id, presence: true
|
||||
end
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
class User < ActiveRecord::Base
|
||||
attr_accessible :name, :email, :password, :password_confirmation
|
||||
has_secure_password
|
||||
has_many :microposts, dependent: :destroy
|
||||
has_many :relationships, foreign_key: "follower_id", dependent: :destroy
|
||||
has_many :followed_users, through: :relationships, source: :followed
|
||||
has_many :reverse_relationships, foreign_key: "followed_id",
|
||||
class_name: "Relationship",
|
||||
dependent: :destroy
|
||||
has_many :followers, through: :reverse_relationships, source: :follower
|
||||
|
||||
before_save { |user| user.email = email.downcase }
|
||||
before_save :create_remember_token
|
||||
|
||||
validates :name, presence: true, length: { maximum: 50 }
|
||||
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
||||
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
|
||||
uniqueness: { case_sensitive: false }
|
||||
validates :password, length: { minimum: 6 }
|
||||
validates :password_confirmation, presence: true
|
||||
|
||||
def feed
|
||||
Micropost.from_users_followed_by(self)
|
||||
end
|
||||
|
||||
def following?(other_user)
|
||||
relationships.find_by_followed_id(other_user.id)
|
||||
end
|
||||
|
||||
def follow!(other_user)
|
||||
relationships.create!(followed_id: other_user.id)
|
||||
end
|
||||
|
||||
def unfollow!(other_user)
|
||||
relationships.find_by_followed_id(other_user.id).destroy
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_remember_token
|
||||
self.remember_token = SecureRandom.urlsafe_base64
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<footer class="footer">
|
||||
<small>
|
||||
<a href="http://railstutorial.org/">Rails Tutorial</a>
|
||||
by Michael Hartl
|
||||
</small>
|
||||
<nav>
|
||||
<ul>
|
||||
<li><%= link_to "About", about_path %></li>
|
||||
<li><%= link_to "Contact", contact_path %></li>
|
||||
<li><a href="http://news.railstutorial.org/">News</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</footer>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<header>
|
||||
<header class="navbar navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<%= link_to "sample app", root_path, id: "logo" %>
|
||||
<nav>
|
||||
<ul class="nav pull-right">
|
||||
<li><%= link_to "Home", root_path %></li>
|
||||
<li><%= link_to "Help", help_path %></li>
|
||||
<% if signed_in? %>
|
||||
<li><%= link_to "Users", users_path %></li>
|
||||
<li id="fat-menu" class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
Account <b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><%= link_to "Profile", current_user %></li>
|
||||
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
|
||||
<li class="divider"></li>
|
||||
<li>
|
||||
<%= link_to "Sign out", signout_path, method: "delete" %>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<% else %>
|
||||
<li><%= link_to "Sign in", signin_path %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
|
|
@ -1,14 +1,21 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>JamWeb</title>
|
||||
<%= stylesheet_link_tag "application", :media => "all" %>
|
||||
<%= javascript_include_tag "application" %>
|
||||
<%= csrf_meta_tags %>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%= yield %>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
<head>
|
||||
<title><%= full_title(yield(:title)) %></title>
|
||||
<%= stylesheet_link_tag "application", media: "all" %>
|
||||
<%= javascript_include_tag "application" %>
|
||||
<%= csrf_meta_tags %>
|
||||
<%= render 'layouts/shim' %>
|
||||
</head>
|
||||
<body>
|
||||
<%= render 'layouts/header' %>
|
||||
<div class="container">
|
||||
<% flash.each do |key, value| %>
|
||||
<%= content_tag(:div, value, class: "alert alert-#{key}") %>
|
||||
<% end %>
|
||||
<%= yield %>
|
||||
<%= render 'layouts/footer' %>
|
||||
<%= debug(params) if Rails.env.development? %>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$("#follow_form").html("<%= escape_javascript(render('users/unfollow')) %>")
|
||||
$("#followers").html('<%= @user.followers.count %>')
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$("#follow_form").html("<%= escape_javascript(render('users/follow')) %>")
|
||||
$("#followers").html('<%= @user.followers.count %>')
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<% provide(:title, "Sign in") %>
|
||||
<h1>Sign in</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 offset3">
|
||||
<%= form_for(:session, url: sessions_path) do |f| %>
|
||||
|
||||
<%= f.label :email %>
|
||||
<%= f.text_field :email %>
|
||||
|
||||
<%= f.label :password %>
|
||||
<%= f.password_field :password %>
|
||||
|
||||
<%= f.submit "Sign in", class: "btn btn-large btn-primary" %>
|
||||
<% end %>
|
||||
|
||||
<p>New user? <%= link_to "Sign up now!", signup_path %></p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<% if object.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<div class="alert alert-error">
|
||||
The form contains <%= pluralize(object.errors.count, "error") %>.
|
||||
</div>
|
||||
<ul>
|
||||
<% object.errors.full_messages.each do |msg| %>
|
||||
<li>* <%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<a href="<%= user_path(current_user) %>">
|
||||
<%= gravatar_for current_user, size: 52 %>
|
||||
</a>
|
||||
<h1>
|
||||
<%= current_user.name %>
|
||||
</h1>
|
||||
<span>
|
||||
<%= link_to "view my profile", current_user %>
|
||||
</span>
|
||||
<span>
|
||||
This space not taken.
|
||||
</span>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<% provide(:title, 'About Us') %>
|
||||
<h1>About Us</h1>
|
||||
<p>
|
||||
The <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
|
||||
is a project to make a book and screencasts to teach web development
|
||||
with <a href="http://rubyonrails.org/">Ruby on Rails</a>. This
|
||||
is the sample application for the tutorial.
|
||||
</p>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<% provide(:title, 'Contact') %>
|
||||
<h1>Contact</h1>
|
||||
<p>
|
||||
Contact Jamkazam at
|
||||
<a href="mailto:info@jamkazam.com">info@jamkazam.com</a>.
|
||||
</p>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<% provide(:title, 'Help') %>
|
||||
<h1>Help</h1>
|
||||
<p>
|
||||
To get help, wait for this section to provide a link to our help page.
|
||||
</p>
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<% if signed_in? %>
|
||||
<div class="row">
|
||||
<aside class="span4">
|
||||
<section>
|
||||
<%= render 'shared/user_info' %>
|
||||
</section>
|
||||
</aside>
|
||||
<div class="span8">
|
||||
<h3>Empty section</h3>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<div class="center hero-unit">
|
||||
<h1>Are you ready to Jam!?</h1>
|
||||
|
||||
<%= link_to "Sign up now!", signup_path,
|
||||
class: "btn btn-large btn-primary" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<li>
|
||||
<%= gravatar_for user, size: 52 %>
|
||||
<%= link_to user.name, user %>
|
||||
<% if current_user.admin? && !current_user?(user) %>
|
||||
| <%= link_to "delete", user, method: :delete,
|
||||
data: { confirm: "You sure?" } %>
|
||||
<% end %>
|
||||
</li>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
<% provide(:title, "Edit user") %>
|
||||
<h1>Update your profile</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 offset3">
|
||||
<%= form_for(@user) do |f| %>
|
||||
<%= render 'shared/error_messages', object: f.object %>
|
||||
|
||||
<%= f.label :name %>
|
||||
<%= f.text_field :name %>
|
||||
|
||||
<%= f.label :email %>
|
||||
<%= f.text_field :email %>
|
||||
|
||||
<%= f.label :password %>
|
||||
<%= f.password_field :password %>
|
||||
|
||||
<%= f.label :password_confirmation, "Confirm Password" %>
|
||||
<%= f.password_field :password_confirmation %>
|
||||
|
||||
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
|
||||
<% end %>
|
||||
|
||||
<%= gravatar_for @user %>
|
||||
<a href="http://gravatar.com/emails">change</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<% provide(:title, 'All users') %>
|
||||
<h1>All users</h1>
|
||||
|
||||
<%= will_paginate %>
|
||||
|
||||
<ul class="users">
|
||||
<%= render @users %>
|
||||
</ul>
|
||||
|
||||
<%= will_paginate %>
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<% provide(:title, 'Sign up') %>
|
||||
<h1>Sign up</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 offset3">
|
||||
<%= form_for(@user) do |f| %>
|
||||
<%= render 'shared/error_messages', object: f.object %>
|
||||
<%= f.label :name %>
|
||||
<%= f.text_field :name %>
|
||||
|
||||
<%= f.label :email %>
|
||||
<%= f.text_field :email %>
|
||||
|
||||
<%= f.label :password %>
|
||||
<%= f.password_field :password %>
|
||||
|
||||
<%= f.label :password_confirmation, "Confirmation" %>
|
||||
<%= f.password_field :password_confirmation %>
|
||||
|
||||
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<% provide(:title, @user.name) %>
|
||||
<div class="row">
|
||||
<aside class="span4">
|
||||
<section>
|
||||
<h1>
|
||||
<%= gravatar_for @user %>
|
||||
<%= @user.name %>
|
||||
</h1>
|
||||
</section>
|
||||
</aside>
|
||||
<div class="span8">
|
||||
This space not taken.
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<% provide(:title, @title) %>
|
||||
<div class="row">
|
||||
<aside class="span4">
|
||||
<section>
|
||||
<%= gravatar_for @user %>
|
||||
<h1><%= @user.name %></h1>
|
||||
<span><%= link_to "view my profile", @user %></span>
|
||||
<span><b>Microposts:</b> <%= @user.microposts.count %></span>
|
||||
</section>
|
||||
<section>
|
||||
<%= render 'shared/stats' %>
|
||||
<% if @users.any? %>
|
||||
<div class="user_avatars">
|
||||
<% @users.each do |user| %>
|
||||
<%= link_to gravatar_for(user, size: 30), user %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</section>
|
||||
</aside>
|
||||
<div class="span8">
|
||||
<h3><%= @title %></h3>
|
||||
<% if @users.any? %>
|
||||
<ul class="users">
|
||||
<%= render @users %>
|
||||
</ul>
|
||||
<%= will_paginate %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# This file is used by Rack-based servers to start the application.
|
||||
|
||||
require ::File.expand_path('../config/environment', __FILE__)
|
||||
run JamWeb::Application
|
||||
run SampleApp::Application
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
require File.expand_path('../boot', __FILE__)
|
||||
|
||||
require 'rails/all'
|
||||
# Pick the frameworks you want:
|
||||
require "active_record/railtie"
|
||||
require "action_controller/railtie"
|
||||
require "action_mailer/railtie"
|
||||
require "active_resource/railtie"
|
||||
require "sprockets/railtie"
|
||||
# require "rails/test_unit/railtie"
|
||||
|
||||
if defined?(Bundler)
|
||||
# If you precompile assets before deploying to production, use this line
|
||||
|
|
@ -9,7 +15,7 @@ if defined?(Bundler)
|
|||
# Bundler.require(:default, :assets, Rails.env)
|
||||
end
|
||||
|
||||
module JamWeb
|
||||
module SampleApp
|
||||
class Application < Rails::Application
|
||||
# Settings in config/environments/* take precedence over those specified here.
|
||||
# Application configuration should go into files in config/initializers
|
||||
|
|
@ -39,9 +45,6 @@ module JamWeb
|
|||
# Configure sensitive parameters which will be filtered from the log file.
|
||||
config.filter_parameters += [:password]
|
||||
|
||||
# Enable escaping HTML in JSON.
|
||||
config.active_support.escape_html_entities_in_json = true
|
||||
|
||||
# Use SQL instead of Active Record's schema dumper when creating the database.
|
||||
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
||||
# like if you have constraints or database-specific column types
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
<%
|
||||
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
||||
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
||||
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
|
||||
%>
|
||||
default: <%= std_opts %> features
|
||||
wip: --tags @wip:3 --wip features
|
||||
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
|
||||
|
|
@ -7,7 +7,7 @@ development:
|
|||
adapter: postgresql
|
||||
database: jam
|
||||
username: postgres
|
||||
password: postgres
|
||||
password: postgres
|
||||
host: localhost
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
|
@ -15,7 +15,7 @@ development:
|
|||
# Warning: The database defined as "test" will be erased and
|
||||
# re-generated from your development database when you run "rake".
|
||||
# Do not set this db to the same as development or production.
|
||||
test:
|
||||
test: &test
|
||||
adapter: postgresql
|
||||
database: jam_web_test
|
||||
username: postgres
|
||||
|
|
@ -29,3 +29,6 @@ production:
|
|||
database: db/production.sqlite3
|
||||
pool: 5
|
||||
timeout: 5000
|
||||
|
||||
cucumber:
|
||||
<<: *test
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
require File.expand_path('../application', __FILE__)
|
||||
|
||||
# Initialize the rails application
|
||||
JamWeb::Application.initialize!
|
||||
SampleApp::Application.initialize!
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
JamWeb::Application.configure do
|
||||
SampleApp::Application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb
|
||||
|
||||
# In the development environment your application's code is reloaded on
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
JamWeb::Application.configure do
|
||||
SampleApp::Application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb
|
||||
|
||||
# Code is not reloaded between requests
|
||||
|
|
@ -20,7 +20,7 @@ JamWeb::Application.configure do
|
|||
# Generate digests for assets URLs
|
||||
config.assets.digest = true
|
||||
|
||||
# Defaults to nil and saved in location specified by config.assets.prefix
|
||||
# Defaults to Rails.root.join("public/assets")
|
||||
# config.assets.manifest = YOUR_PATH
|
||||
|
||||
# Specifies the header that your server uses for sending files
|
||||
|
|
@ -28,7 +28,7 @@ JamWeb::Application.configure do
|
|||
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
|
||||
|
||||
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
||||
# config.force_ssl = true
|
||||
config.force_ssl = true
|
||||
|
||||
# See everything in the log (default is :info)
|
||||
# config.log_level = :debug
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
JamWeb::Application.configure do
|
||||
SampleApp::Application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb
|
||||
|
||||
# The test environment is used exclusively to run your application's
|
||||
|
|
@ -34,4 +34,9 @@ JamWeb::Application.configure do
|
|||
|
||||
# Print deprecation notices to the stderr
|
||||
config.active_support.deprecation = :stderr
|
||||
|
||||
require 'bcrypt'
|
||||
silence_warnings do
|
||||
BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,4 +4,4 @@
|
|||
# If you change this key, all old signed cookies will become invalid!
|
||||
# Make sure the secret is at least 30 characters and all random,
|
||||
# no regular words or you'll be exposed to dictionary attacks.
|
||||
JamWeb::Application.config.secret_token = 'e0002c1a06f1ce827626d7fba4ddd19729300c736d3f384d74157d87e2e2ecbc6f6ba314fc7331130499070e77660aa3873b384498317dc22464ad16ea4d5485'
|
||||
SampleApp::Application.config.secret_token = 'ced345e01611593c1b783bae98e4e56dbaee787747e92a141565f7c61d0ab2c6f98f7396fb4b178258301e2713816e158461af58c14b695901692f91e72b6200'
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
JamWeb::Application.config.session_store :cookie_store, key: '_jam-web_session'
|
||||
SampleApp::Application.config.session_store :cookie_store, key: '_sample_app_session'
|
||||
|
||||
# Use the database for sessions instead of the cookie-based default,
|
||||
# which shouldn't be used to store highly confidential information
|
||||
# (create the session table with "rails generate session_migration")
|
||||
# JamWeb::Application.config.session_store :active_record_store
|
||||
# SampleApp::Application.config.session_store :active_record_store
|
||||
|
|
|
|||
|
|
@ -2,4 +2,7 @@
|
|||
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
||||
|
||||
en:
|
||||
hello: "Hello world"
|
||||
activerecord:
|
||||
attributes:
|
||||
user:
|
||||
password_digest: "Password"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,23 @@
|
|||
JamWeb::Application.routes.draw do
|
||||
SampleApp::Application.routes.draw do
|
||||
resources :users do
|
||||
member do
|
||||
get :following, :followers
|
||||
end
|
||||
end
|
||||
resources :sessions, only: [:new, :create, :destroy]
|
||||
resources :microposts, only: [:create, :destroy]
|
||||
resources :relationships, only: [:create, :destroy]
|
||||
|
||||
root to: 'static_pages#home'
|
||||
|
||||
match '/signup', to: 'users#new'
|
||||
match '/signin', to: 'sessions#new'
|
||||
match '/signout', to: 'sessions#destroy', via: :delete
|
||||
|
||||
match '/help', to: 'static_pages#help'
|
||||
match '/about', to: 'static_pages#about'
|
||||
match '/contact', to: 'static_pages#contact'
|
||||
|
||||
# The priority is based upon order of creation:
|
||||
# first created -> highest priority.
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
class CreateUsers < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :users do |t|
|
||||
t.string :name
|
||||
t.string :email
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class AddIndexToUsersEmail < ActiveRecord::Migration
|
||||
def change
|
||||
add_index :users, :email, unique: true
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class AddPasswordDigestToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :password_digest, :string
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
class AddRememberTokenToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :remember_token, :string
|
||||
add_index :users, :remember_token
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class AddAdminToUsers < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :users, :admin, :boolean, default: false
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
class CreateMicroposts < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :microposts do |t|
|
||||
t.string :content
|
||||
t.integer :user_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :microposts, [:user_id, :created_at]
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
class CreateRelationships < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :relationships do |t|
|
||||
t.integer :follower_id
|
||||
t.integer :followed_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :relationships, :follower_id
|
||||
add_index :relationships, :followed_id
|
||||
add_index :relationships, [:follower_id, :followed_id], unique: true
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
# encoding: UTF-8
|
||||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120308215846) do
|
||||
|
||||
create_table "microposts", :force => true do |t|
|
||||
t.string "content"
|
||||
t.integer "user_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "microposts", ["user_id", "created_at"], :name => "index_microposts_on_user_id_and_created_at"
|
||||
|
||||
create_table "relationships", :force => true do |t|
|
||||
t.integer "follower_id"
|
||||
t.integer "followed_id"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "relationships", ["followed_id"], :name => "index_relationships_on_followed_id"
|
||||
add_index "relationships", ["follower_id", "followed_id"], :name => "index_relationships_on_follower_id_and_followed_id", :unique => true
|
||||
add_index "relationships", ["follower_id"], :name => "index_relationships_on_follower_id"
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "name"
|
||||
t.string "email"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.string "password_digest"
|
||||
t.string "remember_token"
|
||||
t.boolean "admin", :default => false
|
||||
end
|
||||
|
||||
add_index "users", ["email"], :name => "index_users_on_email", :unique => true
|
||||
add_index "users", ["remember_token"], :name => "index_users_on_remember_token"
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Feature: Signing in
|
||||
|
||||
Scenario: Unsuccessful signin
|
||||
Given a user visits the signin page
|
||||
When he submits invalid signin information
|
||||
Then he should see an error message
|
||||
|
||||
Scenario: Successful signin
|
||||
Given a user visits the signin page
|
||||
And the user has an account
|
||||
And the user submits valid signin information
|
||||
Then he should see his profile page
|
||||
And he should see a signout link
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
Given /^a user visits the signin page$/ do
|
||||
visit signin_path
|
||||
end
|
||||
|
||||
When /^he submits invalid signin information$/ do
|
||||
click_button "Sign in"
|
||||
end
|
||||
|
||||
Then /^he should see an error message$/ do
|
||||
page.should have_selector('div.alert.alert-error')
|
||||
end
|
||||
|
||||
Given /^the user has an account$/ do
|
||||
@user = User.create(name: "Example User", email: "user@example.com",
|
||||
password: "foobar", password_confirmation: "foobar")
|
||||
end
|
||||
|
||||
When /^the user submits valid signin information$/ do
|
||||
visit signin_path
|
||||
fill_in "Email", with: @user.email
|
||||
fill_in "Password", with: @user.password
|
||||
click_button "Sign in"
|
||||
end
|
||||
|
||||
Then /^he should see his profile page$/ do
|
||||
page.should have_selector('title', text: @user.name)
|
||||
end
|
||||
|
||||
Then /^he should see a signout link$/ do
|
||||
page.should have_link('Sign out', href: signout_path)
|
||||
end
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
||||
# It is recommended to regenerate this file in the future when you upgrade to a
|
||||
# newer version of cucumber-rails. Consider adding your own code to a new file
|
||||
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
||||
# files.
|
||||
|
||||
require 'cucumber/rails'
|
||||
|
||||
# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In
|
||||
# order to ease the transition to Capybara we set the default here. If you'd
|
||||
# prefer to use XPath just remove this line and adjust any selectors in your
|
||||
# steps to use the XPath syntax.
|
||||
Capybara.default_selector = :css
|
||||
|
||||
# By default, any exception happening in your Rails application will bubble up
|
||||
# to Cucumber so that your scenario will fail. This is a different from how
|
||||
# your application behaves in the production environment, where an error page will
|
||||
# be rendered instead.
|
||||
#
|
||||
# Sometimes we want to override this default behaviour and allow Rails to rescue
|
||||
# exceptions and display an error page (just like when the app is running in production).
|
||||
# Typical scenarios where you want to do this is when you test your error pages.
|
||||
# There are two ways to allow Rails to rescue exceptions:
|
||||
#
|
||||
# 1) Tag your scenario (or feature) with @allow-rescue
|
||||
#
|
||||
# 2) Set the value below to true. Beware that doing this globally is not
|
||||
# recommended as it will mask a lot of errors for you!
|
||||
#
|
||||
ActionController::Base.allow_rescue = false
|
||||
|
||||
# Remove/comment out the lines below if your app doesn't have a database.
|
||||
# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead.
|
||||
begin
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
rescue NameError
|
||||
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
|
||||
end
|
||||
|
||||
# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios.
|
||||
# See the DatabaseCleaner documentation for details. Example:
|
||||
#
|
||||
# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do
|
||||
# DatabaseCleaner.strategy = :truncation, {:except => %w[widgets]}
|
||||
# end
|
||||
#
|
||||
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
|
||||
# DatabaseCleaner.strategy = :transaction
|
||||
# end
|
||||
#
|
||||
|
||||
# Possible values are :truncation and :transaction
|
||||
# The :transaction strategy is faster, but might give you threading problems.
|
||||
# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
|
||||
Cucumber::Rails::Database.javascript_strategy = :truncation
|
||||
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
|
||||
# It is recommended to regenerate this file in the future when you upgrade to a
|
||||
# newer version of cucumber-rails. Consider adding your own code to a new file
|
||||
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
|
||||
# files.
|
||||
|
||||
|
||||
unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks
|
||||
|
||||
vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
|
||||
$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil?
|
||||
|
||||
begin
|
||||
require 'cucumber/rake/task'
|
||||
|
||||
namespace :cucumber do
|
||||
Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t|
|
||||
t.binary = vendored_cucumber_bin # If nil, the gem's binary is used.
|
||||
t.fork = true # You may get faster startup if you set this to false
|
||||
t.profile = 'default'
|
||||
end
|
||||
|
||||
Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t|
|
||||
t.binary = vendored_cucumber_bin
|
||||
t.fork = true # You may get faster startup if you set this to false
|
||||
t.profile = 'wip'
|
||||
end
|
||||
|
||||
Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t|
|
||||
t.binary = vendored_cucumber_bin
|
||||
t.fork = true # You may get faster startup if you set this to false
|
||||
t.profile = 'rerun'
|
||||
end
|
||||
|
||||
desc 'Run all features'
|
||||
task :all => [:ok, :wip]
|
||||
|
||||
task :statsetup do
|
||||
require 'rails/code_statistics'
|
||||
::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features')
|
||||
::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features')
|
||||
end
|
||||
end
|
||||
desc 'Alias for cucumber:ok'
|
||||
task :cucumber => 'cucumber:ok'
|
||||
|
||||
task :default => :cucumber
|
||||
|
||||
task :features => :cucumber do
|
||||
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
|
||||
end
|
||||
|
||||
# In case we don't have ActiveRecord, append a no-op task that we can depend upon.
|
||||
task 'db:test:prepare' do
|
||||
end
|
||||
|
||||
task :stats => 'cucumber:statsetup'
|
||||
rescue LoadError
|
||||
desc 'cucumber rake task not available (cucumber not installed)'
|
||||
task :cucumber do
|
||||
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
namespace :db do
|
||||
desc "Fill database with sample data"
|
||||
task populate: :environment do
|
||||
make_users
|
||||
make_microposts
|
||||
make_relationships
|
||||
end
|
||||
end
|
||||
|
||||
def make_users
|
||||
admin = User.create!(name: "Example User",
|
||||
email: "example@railstutorial.org",
|
||||
password: "foobar",
|
||||
password_confirmation: "foobar")
|
||||
admin.toggle!(:admin)
|
||||
99.times do |n|
|
||||
name = Faker::Name.name
|
||||
email = "example-#{n+1}@railstutorial.org"
|
||||
password = "password"
|
||||
User.create!(name: name,
|
||||
email: email,
|
||||
password: password,
|
||||
password_confirmation: password)
|
||||
end
|
||||
end
|
||||
|
||||
def make_microposts
|
||||
users = User.all(limit: 6)
|
||||
50.times do
|
||||
content = Faker::Lorem.sentence(5)
|
||||
users.each { |user| user.microposts.create!(content: content) }
|
||||
end
|
||||
end
|
||||
|
||||
def make_relationships
|
||||
users = User.all
|
||||
user = users.first
|
||||
followed_users = users[2..50]
|
||||
followers = users[3..40]
|
||||
followed_users.each { |followed| user.follow!(followed) }
|
||||
followers.each { |follower| follower.follow!(user) }
|
||||
end
|
||||
|
|
@ -1,241 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Ruby on Rails: Welcome aboard</title>
|
||||
<style type="text/css" media="screen">
|
||||
body {
|
||||
margin: 0;
|
||||
margin-bottom: 25px;
|
||||
padding: 0;
|
||||
background-color: #f0f0f0;
|
||||
font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
|
||||
font-size: 13px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 28px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
a {color: #03c}
|
||||
a:hover {
|
||||
background-color: #03c;
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
|
||||
#page {
|
||||
background-color: #f0f0f0;
|
||||
width: 750px;
|
||||
margin: 0;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
#content {
|
||||
float: left;
|
||||
background-color: white;
|
||||
border: 3px solid #aaa;
|
||||
border-top: none;
|
||||
padding: 25px;
|
||||
width: 500px;
|
||||
}
|
||||
|
||||
#sidebar {
|
||||
float: right;
|
||||
width: 175px;
|
||||
}
|
||||
|
||||
#footer {
|
||||
clear: both;
|
||||
}
|
||||
|
||||
#header, #about, #getting-started {
|
||||
padding-left: 75px;
|
||||
padding-right: 30px;
|
||||
}
|
||||
|
||||
|
||||
#header {
|
||||
background-image: url("assets/rails.png");
|
||||
background-repeat: no-repeat;
|
||||
background-position: top left;
|
||||
height: 64px;
|
||||
}
|
||||
#header h1, #header h2 {margin: 0}
|
||||
#header h2 {
|
||||
color: #888;
|
||||
font-weight: normal;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
|
||||
#about h3 {
|
||||
margin: 0;
|
||||
margin-bottom: 10px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#about-content {
|
||||
background-color: #ffd;
|
||||
border: 1px solid #fc0;
|
||||
margin-left: -55px;
|
||||
margin-right: -10px;
|
||||
}
|
||||
#about-content table {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
font-size: 11px;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
#about-content td {
|
||||
padding: 10px;
|
||||
padding-top: 3px;
|
||||
padding-bottom: 3px;
|
||||
}
|
||||
#about-content td.name {color: #555}
|
||||
#about-content td.value {color: #000}
|
||||
|
||||
#about-content ul {
|
||||
padding: 0;
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
#about-content.failure {
|
||||
background-color: #fcc;
|
||||
border: 1px solid #f00;
|
||||
}
|
||||
#about-content.failure p {
|
||||
margin: 0;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
|
||||
#getting-started {
|
||||
border-top: 1px solid #ccc;
|
||||
margin-top: 25px;
|
||||
padding-top: 15px;
|
||||
}
|
||||
#getting-started h1 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
}
|
||||
#getting-started h2 {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
font-weight: normal;
|
||||
color: #333;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
#getting-started ol {
|
||||
margin-left: 0;
|
||||
padding-left: 0;
|
||||
}
|
||||
#getting-started li {
|
||||
font-size: 18px;
|
||||
color: #888;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
#getting-started li h2 {
|
||||
margin: 0;
|
||||
font-weight: normal;
|
||||
font-size: 18px;
|
||||
color: #333;
|
||||
}
|
||||
#getting-started li p {
|
||||
color: #555;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
|
||||
#sidebar ul {
|
||||
margin-left: 0;
|
||||
padding-left: 0;
|
||||
}
|
||||
#sidebar ul h3 {
|
||||
margin-top: 25px;
|
||||
font-size: 16px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
#sidebar li {
|
||||
list-style-type: none;
|
||||
}
|
||||
#sidebar ul.links li {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.filename {
|
||||
font-style: italic;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
function about() {
|
||||
info = document.getElementById('about-content');
|
||||
if (window.XMLHttpRequest)
|
||||
{ xhr = new XMLHttpRequest(); }
|
||||
else
|
||||
{ xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
|
||||
xhr.open("GET","rails/info/properties",false);
|
||||
xhr.send("");
|
||||
info.innerHTML = xhr.responseText;
|
||||
info.style.display = 'block'
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
<div id="sidebar">
|
||||
<ul id="sidebar-items">
|
||||
<li>
|
||||
<h3>Browse the documentation</h3>
|
||||
<ul class="links">
|
||||
<li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
|
||||
<li><a href="http://api.rubyonrails.org/">Rails API</a></li>
|
||||
<li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
|
||||
<li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="content">
|
||||
<div id="header">
|
||||
<h1>Welcome aboard</h1>
|
||||
<h2>You’re riding Ruby on Rails!</h2>
|
||||
</div>
|
||||
|
||||
<div id="about">
|
||||
<h3><a href="rails/info/properties" onclick="about(); return false">About your application’s environment</a></h3>
|
||||
<div id="about-content" style="display: none"></div>
|
||||
</div>
|
||||
|
||||
<div id="getting-started">
|
||||
<h1>Getting started</h1>
|
||||
<h2>Here’s how to get rolling:</h2>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
<h2>Use <code>rails generate</code> to create your models and controllers</h2>
|
||||
<p>To see all available options, run it without parameters.</p>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
|
||||
<p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<h2>Create your database</h2>
|
||||
<p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="footer"> </div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first
|
||||
if vendored_cucumber_bin
|
||||
load File.expand_path(vendored_cucumber_bin)
|
||||
else
|
||||
require 'rubygems' unless ENV['NO_RUBYGEMS']
|
||||
require 'cucumber'
|
||||
load Cucumber::BINARY
|
||||
end
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe RelationshipsController do
|
||||
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:other_user) { FactoryGirl.create(:user) }
|
||||
|
||||
before { sign_in user }
|
||||
|
||||
describe "creating a relationship with Ajax" do
|
||||
|
||||
it "should increment the Relationship count" do
|
||||
expect do
|
||||
xhr :post, :create, relationship: { followed_id: other_user.id }
|
||||
end.to change(Relationship, :count).by(1)
|
||||
end
|
||||
|
||||
it "should respond with success" do
|
||||
xhr :post, :create, relationship: { followed_id: other_user.id }
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
|
||||
describe "destroying a relationship with Ajax" do
|
||||
|
||||
before { user.follow!(other_user) }
|
||||
let(:relationship) { user.relationships.find_by_followed_id(other_user) }
|
||||
|
||||
it "should decrement the Relationship count" do
|
||||
expect do
|
||||
xhr :delete, :destroy, id: relationship.id
|
||||
end.to change(Relationship, :count).by(-1)
|
||||
end
|
||||
|
||||
it "should respond with success" do
|
||||
xhr :delete, :destroy, id: relationship.id
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
FactoryGirl.define do
|
||||
factory :user do
|
||||
sequence(:name) { |n| "Person #{n}" }
|
||||
sequence(:email) { |n| "person_#{n}@example.com"}
|
||||
password "foobar"
|
||||
password_confirmation "foobar"
|
||||
|
||||
factory :admin do
|
||||
admin true
|
||||
end
|
||||
end
|
||||
|
||||
factory :micropost do
|
||||
content "Lorem ipsum"
|
||||
user
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ApplicationHelper do
|
||||
|
||||
describe "full_title" do
|
||||
it "should include the page name" do
|
||||
full_title("foo").should =~ /foo/
|
||||
end
|
||||
|
||||
it "should includes the base name" do
|
||||
full_title("foo").should =~ /^Ruby on Rails Tutorial Sample App/
|
||||
end
|
||||
|
||||
it "should not include a bar for the home page" do
|
||||
full_title("").should_not =~ /\|/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Micropost do
|
||||
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before { @micropost = user.microposts.build(content: "Lorem ipsum") }
|
||||
|
||||
subject { @micropost }
|
||||
|
||||
it { should respond_to(:content) }
|
||||
it { should respond_to(:user_id) }
|
||||
it { should respond_to(:user) }
|
||||
its(:user) { should == user }
|
||||
|
||||
it { should be_valid }
|
||||
|
||||
describe "accessible attributes" do
|
||||
it "should not allow access to user_id" do
|
||||
expect do
|
||||
Micropost.new(user_id: user.id)
|
||||
end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
||||
end
|
||||
end
|
||||
|
||||
describe "when user_id is not present" do
|
||||
before { @micropost.user_id = nil }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "when user_id is not present" do
|
||||
before { @micropost.user_id = nil }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "with blank content" do
|
||||
before { @micropost.content = " " }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "with content that is too long" do
|
||||
before { @micropost.content = "a" * 141 }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Relationship do
|
||||
|
||||
let(:follower) { FactoryGirl.create(:user) }
|
||||
let(:followed) { FactoryGirl.create(:user) }
|
||||
let(:relationship) { follower.relationships.build(followed_id: followed.id) }
|
||||
|
||||
subject { relationship }
|
||||
|
||||
it { should be_valid }
|
||||
|
||||
describe "accessible attributes" do
|
||||
it "should not allow access to follower_id" do
|
||||
expect do
|
||||
Relationship.new(follower_id: follower.id)
|
||||
end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
||||
end
|
||||
end
|
||||
|
||||
describe "follower methods" do
|
||||
it { should respond_to(:follower) }
|
||||
it { should respond_to(:followed) }
|
||||
its(:follower) { should == follower }
|
||||
its(:followed) { should == followed }
|
||||
end
|
||||
|
||||
describe "when followed id is not present" do
|
||||
before { relationship.followed_id = nil }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "when follower id is not present" do
|
||||
before { relationship.follower_id = nil }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe User do
|
||||
|
||||
before do
|
||||
@user = User.new(name: "Example User", email: "user@example.com",
|
||||
password: "foobar", password_confirmation: "foobar")
|
||||
end
|
||||
|
||||
subject { @user }
|
||||
|
||||
it { should respond_to(:name) }
|
||||
it { should respond_to(:email) }
|
||||
it { should respond_to(:password_digest) }
|
||||
it { should respond_to(:password) }
|
||||
it { should respond_to(:password_confirmation) }
|
||||
it { should respond_to(:remember_token) }
|
||||
it { should respond_to(:admin) }
|
||||
it { should respond_to(:authenticate) }
|
||||
it { should respond_to(:microposts) }
|
||||
it { should respond_to(:feed) }
|
||||
it { should respond_to(:relationships) }
|
||||
it { should respond_to(:followed_users) }
|
||||
it { should respond_to(:reverse_relationships) }
|
||||
it { should respond_to(:followers) }
|
||||
it { should respond_to(:following?) }
|
||||
it { should respond_to(:follow!) }
|
||||
it { should respond_to(:unfollow!) }
|
||||
|
||||
it { should be_valid }
|
||||
it { should_not be_admin }
|
||||
|
||||
describe "accessible attributes" do
|
||||
it "should not allow access to admin" do
|
||||
expect do
|
||||
User.new(admin: true)
|
||||
end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with admin attribute set to 'true'" do
|
||||
before do
|
||||
@user.save!
|
||||
@user.toggle!(:admin)
|
||||
end
|
||||
|
||||
it { should be_admin }
|
||||
end
|
||||
|
||||
describe "when name is not present" do
|
||||
before { @user.name = " " }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "when email is not present" do
|
||||
before { @user.email = " " }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "when name is too long" do
|
||||
before { @user.name = "a" * 51 }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "when email format is invalid" do
|
||||
it "should be invalid" do
|
||||
addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
|
||||
addresses.each do |invalid_address|
|
||||
@user.email = invalid_address
|
||||
@user.should_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when email format is valid" do
|
||||
it "should be valid" do
|
||||
addresses = %w[user@foo.COM A_US-ER@f.b.org frst.lst@foo.jp a+b@baz.cn]
|
||||
addresses.each do |valid_address|
|
||||
@user.email = valid_address
|
||||
@user.should be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "when email address is already taken" do
|
||||
before do
|
||||
user_with_same_email = @user.dup
|
||||
user_with_same_email.email = @user.email.upcase
|
||||
user_with_same_email.save
|
||||
end
|
||||
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "email address with mixed case" do
|
||||
let(:mixed_case_email) { "Foo@ExAMPle.CoM" }
|
||||
|
||||
it "should be saved as all lower-case" do
|
||||
@user.email = mixed_case_email
|
||||
@user.save
|
||||
@user.reload.email.should == mixed_case_email.downcase
|
||||
end
|
||||
end
|
||||
|
||||
describe "when password is not present" do
|
||||
before { @user.password = @user.password_confirmation = " " }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "when password doesn't match confirmation" do
|
||||
before { @user.password_confirmation = "mismatch" }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "when password confirmation is nil" do
|
||||
before { @user.password_confirmation = nil }
|
||||
it { should_not be_valid }
|
||||
end
|
||||
|
||||
describe "with a password that's too short" do
|
||||
before { @user.password = @user.password_confirmation = "a" * 5 }
|
||||
it { should be_invalid }
|
||||
end
|
||||
|
||||
describe "return value of authenticate method" do
|
||||
before { @user.save }
|
||||
let(:found_user) { User.find_by_email(@user.email) }
|
||||
|
||||
describe "with valid password" do
|
||||
it { should == found_user.authenticate(@user.password) }
|
||||
end
|
||||
|
||||
describe "with invalid password" do
|
||||
let(:user_for_invalid_password) { found_user.authenticate("invalid") }
|
||||
|
||||
it { should_not == user_for_invalid_password }
|
||||
specify { user_for_invalid_password.should be_false }
|
||||
end
|
||||
end
|
||||
|
||||
describe "remember token" do
|
||||
before { @user.save }
|
||||
its(:remember_token) { should_not be_blank }
|
||||
end
|
||||
|
||||
|
||||
describe "micropost associations" do
|
||||
|
||||
before { @user.save }
|
||||
let!(:older_micropost) do
|
||||
FactoryGirl.create(:micropost, user: @user, created_at: 1.day.ago)
|
||||
end
|
||||
let!(:newer_micropost) do
|
||||
FactoryGirl.create(:micropost, user: @user, created_at: 1.hour.ago)
|
||||
end
|
||||
|
||||
it "should have the right microposts in the right order" do
|
||||
@user.microposts.should == [newer_micropost, older_micropost]
|
||||
end
|
||||
|
||||
it "should destroy associated microposts" do
|
||||
microposts = @user.microposts
|
||||
@user.destroy
|
||||
microposts.each do |micropost|
|
||||
Micropost.find_by_id(micropost.id).should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "status" do
|
||||
let(:unfollowed_post) do
|
||||
FactoryGirl.create(:micropost, user: FactoryGirl.create(:user))
|
||||
end
|
||||
|
||||
let(:followed_user) { FactoryGirl.create(:user) }
|
||||
|
||||
before do
|
||||
@user.follow!(followed_user)
|
||||
3.times { followed_user.microposts.create!(content: "Lorem ipsum") }
|
||||
end
|
||||
|
||||
its(:feed) { should include(newer_micropost) }
|
||||
its(:feed) { should include(older_micropost) }
|
||||
its(:feed) { should_not include(unfollowed_post) }
|
||||
its(:feed) do
|
||||
followed_user.microposts.each do |micropost|
|
||||
should include(micropost)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "following" do
|
||||
let(:other_user) { FactoryGirl.create(:user) }
|
||||
before do
|
||||
@user.save
|
||||
@user.follow!(other_user)
|
||||
end
|
||||
|
||||
it { should be_following(other_user) }
|
||||
its(:followed_users) { should include(other_user) }
|
||||
|
||||
describe "followed user" do
|
||||
subject { other_user }
|
||||
its(:followers) { should include(@user) }
|
||||
end
|
||||
|
||||
describe "and unfollowing" do
|
||||
before { @user.unfollow!(other_user) }
|
||||
|
||||
it { should_not be_following(other_user) }
|
||||
its(:followed_users) { should_not include(other_user) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "Authentication" do
|
||||
|
||||
subject { page }
|
||||
|
||||
describe "signin page" do
|
||||
before { visit signin_path }
|
||||
|
||||
it { should have_selector('h1', text: 'Sign in') }
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
end
|
||||
|
||||
describe "signin" do
|
||||
before { visit signin_path }
|
||||
|
||||
describe "with invalid information" do
|
||||
before { click_button "Sign in" }
|
||||
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
|
||||
|
||||
describe "after visiting another page" do
|
||||
before { click_link "Home" }
|
||||
it { should_not have_selector('div.alert.alert-error') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with valid information" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before do
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_button "Sign in"
|
||||
end
|
||||
|
||||
it { should have_selector('title', text: user.name) }
|
||||
|
||||
it { should have_link('Users', href: users_path) }
|
||||
it { should have_link('Profile', href: user_path(user)) }
|
||||
it { should have_link('Settings', href: edit_user_path(user)) }
|
||||
it { should have_link('Sign out', href: signout_path) }
|
||||
it { should_not have_link('Sign in', href: signin_path) }
|
||||
|
||||
describe "followed by signout" do
|
||||
before { click_link "Sign out" }
|
||||
it { should have_link('Sign in') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "authorization" do
|
||||
|
||||
describe "for non-signed-in users" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
|
||||
describe "when attempting to visit a protected page" do
|
||||
before do
|
||||
visit edit_user_path(user)
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_button "Sign in"
|
||||
end
|
||||
|
||||
describe "after signing in" do
|
||||
|
||||
it "should render the desired protected page" do
|
||||
page.should have_selector('title', text: 'Edit user')
|
||||
end
|
||||
|
||||
describe "when signing in again" do
|
||||
before do
|
||||
delete signout_path
|
||||
visit signin_path
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_button "Sign in"
|
||||
end
|
||||
|
||||
it "should render the default (profile) page" do
|
||||
page.should have_selector('title', text: user.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "in the Users controller" do
|
||||
|
||||
describe "visiting the edit page" do
|
||||
before { visit edit_user_path(user) }
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
end
|
||||
|
||||
describe "submitting to the update action" do
|
||||
before { put user_path(user) }
|
||||
specify { response.should redirect_to(signin_url) }
|
||||
end
|
||||
|
||||
describe "visiting user index" do
|
||||
before { visit users_path }
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
end
|
||||
|
||||
describe "visiting the following page" do
|
||||
before { visit following_user_path(user) }
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
end
|
||||
|
||||
describe "visiting the followers page" do
|
||||
before { visit followers_user_path(user) }
|
||||
it { should have_selector('title', text: 'Sign in') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "in the Microposts controller" do
|
||||
|
||||
describe "submitting to the create action" do
|
||||
before { post microposts_path }
|
||||
specify { response.should redirect_to(signin_url) }
|
||||
end
|
||||
|
||||
describe "submitting to the destroy action" do
|
||||
before { delete micropost_path(FactoryGirl.create(:micropost)) }
|
||||
specify { response.should redirect_to(signin_url) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "in the Relationships controller" do
|
||||
describe "submitting to the create action" do
|
||||
before { post relationships_path }
|
||||
specify { response.should redirect_to(signin_url) }
|
||||
end
|
||||
|
||||
describe "submitting to the destroy action" do
|
||||
before { delete relationship_path(1) }
|
||||
specify { response.should redirect_to(signin_url) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "as wrong user" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
|
||||
before { sign_in user }
|
||||
|
||||
describe "visiting Users#edit page" do
|
||||
before { visit edit_user_path(wrong_user) }
|
||||
it { should have_selector('title', text: full_title('')) }
|
||||
end
|
||||
|
||||
describe "submitting a PUT request to the Users#update action" do
|
||||
before { put user_path(wrong_user) }
|
||||
specify { response.should redirect_to(root_url) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "as non-admin user" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:non_admin) { FactoryGirl.create(:user) }
|
||||
|
||||
before { sign_in non_admin }
|
||||
|
||||
describe "submitting a DELETE request to the Users#destroy action" do
|
||||
before { delete user_path(user) }
|
||||
specify { response.should redirect_to(root_url) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "Micropost pages" do
|
||||
|
||||
subject { page }
|
||||
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before { sign_in user }
|
||||
|
||||
describe "micropost creation" do
|
||||
before { visit root_path }
|
||||
|
||||
describe "with invalid information" do
|
||||
|
||||
it "should not create a micropost" do
|
||||
expect { click_button "Post" }.not_to change(Micropost, :count)
|
||||
end
|
||||
|
||||
describe "error messages" do
|
||||
before { click_button "Post" }
|
||||
it { should have_content('error') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with valid information" do
|
||||
|
||||
before { fill_in 'micropost_content', with: "Lorem ipsum" }
|
||||
it "should create a micropost" do
|
||||
expect { click_button "Post" }.to change(Micropost, :count).by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "micropost destruction" do
|
||||
before { FactoryGirl.create(:micropost, user: user) }
|
||||
|
||||
describe "as correct user" do
|
||||
before { visit root_path }
|
||||
|
||||
it "should delete a micropost" do
|
||||
expect { click_link "delete" }.to change(Micropost, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "Static pages" do
|
||||
|
||||
subject { page }
|
||||
|
||||
describe "Home page" do
|
||||
before { visit root_path }
|
||||
|
||||
it { should have_selector('h1', text: 'Sample App') }
|
||||
it { should have_selector('title', text: full_title('')) }
|
||||
it { should_not have_selector 'title', text: '| Home' }
|
||||
|
||||
describe "for signed-in users" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before do
|
||||
FactoryGirl.create(:micropost, user: user, content: "Lorem ipsum")
|
||||
FactoryGirl.create(:micropost, user: user, content: "Dolor sit amet")
|
||||
sign_in user
|
||||
visit root_path
|
||||
end
|
||||
|
||||
it "should render the user's feed" do
|
||||
user.feed.each do |item|
|
||||
page.should have_selector("li##{item.id}", text: item.content)
|
||||
end
|
||||
end
|
||||
|
||||
describe "follower/following counts" do
|
||||
let(:other_user) { FactoryGirl.create(:user) }
|
||||
before do
|
||||
other_user.follow!(user)
|
||||
visit root_path
|
||||
end
|
||||
|
||||
it { should have_link("0 following", href: following_user_path(user)) }
|
||||
it { should have_link("1 followers", href: followers_user_path(user)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Help page" do
|
||||
before { visit help_path }
|
||||
|
||||
it { should have_selector('h1', text: 'Help') }
|
||||
it { should have_selector('title', text: full_title('Help')) }
|
||||
end
|
||||
|
||||
describe "About page" do
|
||||
before { visit about_path }
|
||||
|
||||
it { should have_selector('h1', text: 'About') }
|
||||
it { should have_selector('title', text: full_title('About Us')) }
|
||||
end
|
||||
|
||||
describe "Contact page" do
|
||||
before { visit contact_path }
|
||||
|
||||
it { should have_selector('h1', text: 'Contact') }
|
||||
it { should have_selector('title', text: full_title('Contact')) }
|
||||
end
|
||||
|
||||
it "should have the right links on the layout" do
|
||||
visit root_path
|
||||
click_link "About"
|
||||
page.should have_selector 'title', text: full_title('About Us')
|
||||
click_link "Help"
|
||||
page.should have_selector 'title', text: full_title('Help')
|
||||
click_link "Contact"
|
||||
page.should have_selector 'title', text: full_title('Contact')
|
||||
click_link "Home"
|
||||
click_link "Sign up now!"
|
||||
page.should have_selector 'title', text: full_title('Sign up')
|
||||
click_link "sample app"
|
||||
page.should have_selector 'h1', text: 'Sample App'
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,263 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "User pages" do
|
||||
|
||||
subject { page }
|
||||
|
||||
describe "index" do
|
||||
|
||||
before do
|
||||
sign_in FactoryGirl.create(:user)
|
||||
FactoryGirl.create(:user, name: "Bob", email: "bob@example.com")
|
||||
FactoryGirl.create(:user, name: "Ben", email: "ben@example.com")
|
||||
visit users_path
|
||||
end
|
||||
|
||||
it { should have_selector('title', text: 'All users') }
|
||||
|
||||
describe "pagination" do
|
||||
|
||||
before(:all) { 30.times { FactoryGirl.create(:user) } }
|
||||
after(:all) { User.delete_all }
|
||||
|
||||
let(:first_page) { User.paginate(page: 1) }
|
||||
let(:second_page) { User.paginate(page: 2) }
|
||||
|
||||
it { should have_link('Next') }
|
||||
its(:html) { should match('>2</a>') }
|
||||
|
||||
it "should list each user" do
|
||||
User.all[0..2].each do |user|
|
||||
page.should have_selector('li', text: user.name)
|
||||
end
|
||||
end
|
||||
|
||||
it "should list the first page of users" do
|
||||
first_page.each do |user|
|
||||
page.should have_selector('li', text: user.name)
|
||||
end
|
||||
end
|
||||
|
||||
it "should not list the second page of users" do
|
||||
second_page.each do |user|
|
||||
page.should_not have_selector('li', text: user.name)
|
||||
end
|
||||
end
|
||||
|
||||
describe "showing the second page" do
|
||||
before { visit users_path(page: 2) }
|
||||
|
||||
it "should list the second page of users" do
|
||||
second_page.each do |user|
|
||||
page.should have_selector('li', text: user.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete links" do
|
||||
|
||||
it { should_not have_link('delete') }
|
||||
|
||||
describe "as an admin user" do
|
||||
let(:admin) { FactoryGirl.create(:admin) }
|
||||
before do
|
||||
sign_in admin
|
||||
visit users_path
|
||||
end
|
||||
|
||||
it { should have_link('delete', href: user_path(User.first)) }
|
||||
it "should be able to delete another user" do
|
||||
expect { click_link('delete') }.to change(User, :count).by(-1)
|
||||
end
|
||||
it { should_not have_link('delete', href: user_path(admin)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "profile page" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let!(:m1) { FactoryGirl.create(:micropost, user: user, content: "Foo") }
|
||||
let!(:m2) { FactoryGirl.create(:micropost, user: user, content: "Bar") }
|
||||
|
||||
before { visit user_path(user) }
|
||||
|
||||
it { should have_selector('h1', text: user.name) }
|
||||
it { should have_selector('title', text: user.name) }
|
||||
|
||||
describe "microposts" do
|
||||
it { should have_content(m1.content) }
|
||||
it { should have_content(m2.content) }
|
||||
it { should have_content(user.microposts.count) }
|
||||
end
|
||||
|
||||
it { should have_selector('h1', text: user.name) }
|
||||
it { should have_selector('title', text: user.name) }
|
||||
|
||||
describe "follow/unfollow buttons" do
|
||||
let(:other_user) { FactoryGirl.create(:user) }
|
||||
before { sign_in user }
|
||||
|
||||
describe "following a user" do
|
||||
before { visit user_path(other_user) }
|
||||
|
||||
it "should increment the followed user count" do
|
||||
expect do
|
||||
click_button "Follow"
|
||||
end.to change(user.followed_users, :count).by(1)
|
||||
end
|
||||
|
||||
it "should increment the other user's followers count" do
|
||||
expect do
|
||||
click_button "Follow"
|
||||
end.to change(other_user.followers, :count).by(1)
|
||||
end
|
||||
|
||||
describe "toggling the button" do
|
||||
before { click_button "Follow" }
|
||||
it { should have_selector('input', value: 'Unfollow') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "unfollowing a user" do
|
||||
before do
|
||||
user.follow!(other_user)
|
||||
visit user_path(other_user)
|
||||
end
|
||||
|
||||
it "should decrement the followed user count" do
|
||||
expect do
|
||||
click_button "Unfollow"
|
||||
end.to change(user.followed_users, :count).by(-1)
|
||||
end
|
||||
|
||||
it "should decrement the other user's followers count" do
|
||||
expect do
|
||||
click_button "Unfollow"
|
||||
end.to change(other_user.followers, :count).by(-1)
|
||||
end
|
||||
|
||||
describe "toggling the button" do
|
||||
before { click_button "Unfollow" }
|
||||
it { should have_selector('input', value: 'Follow') }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "signup page" do
|
||||
before { visit signup_path }
|
||||
|
||||
it { should have_selector('h1', text: 'Sign up') }
|
||||
it { should have_selector('title', text: full_title('Sign up')) }
|
||||
end
|
||||
|
||||
describe "signup" do
|
||||
|
||||
before { visit signup_path }
|
||||
|
||||
let(:submit) { "Create my account" }
|
||||
|
||||
describe "with invalid information" do
|
||||
it "should not create a user" do
|
||||
expect { click_button submit }.not_to change(User, :count)
|
||||
end
|
||||
|
||||
describe "error messages" do
|
||||
before { click_button submit }
|
||||
|
||||
it { should have_selector('title', text: 'Sign up') }
|
||||
it { should have_content('error') }
|
||||
end
|
||||
end
|
||||
|
||||
describe "with valid information" do
|
||||
before do
|
||||
fill_in "Name", with: "Example User"
|
||||
fill_in "Email", with: "user@example.com"
|
||||
fill_in "Password", with: "foobar"
|
||||
fill_in "Confirmation", with: "foobar"
|
||||
end
|
||||
|
||||
it "should create a user" do
|
||||
expect { click_button submit }.to change(User, :count).by(1)
|
||||
end
|
||||
|
||||
describe "after saving the user" do
|
||||
before { click_button submit }
|
||||
|
||||
let(:user) { User.find_by_email('user@example.com') }
|
||||
|
||||
it { should have_selector('title', text: user.name) }
|
||||
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
|
||||
it { should have_link('Sign out') }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
before do
|
||||
sign_in user
|
||||
visit edit_user_path(user)
|
||||
end
|
||||
|
||||
describe "page" do
|
||||
it { should have_selector('h1', text: "Update your profile") }
|
||||
it { should have_selector('title', text: "Edit user") }
|
||||
it { should have_link('change', href: 'http://gravatar.com/emails') }
|
||||
end
|
||||
|
||||
describe "with invalid information" do
|
||||
before { click_button "Save changes" }
|
||||
|
||||
it { should have_content('error') }
|
||||
end
|
||||
|
||||
describe "with valid information" do
|
||||
let(:new_name) { "New Name" }
|
||||
let(:new_email) { "new@example.com" }
|
||||
before do
|
||||
fill_in "Name", with: new_name
|
||||
fill_in "Email", with: new_email
|
||||
fill_in "Password", with: user.password
|
||||
fill_in "Confirm Password", with: user.password
|
||||
click_button "Save changes"
|
||||
end
|
||||
|
||||
it { should have_selector('title', text: new_name) }
|
||||
it { should have_selector('div.alert.alert-success') }
|
||||
it { should have_link('Sign out', href: signout_path) }
|
||||
specify { user.reload.name.should == new_name }
|
||||
specify { user.reload.email.should == new_email }
|
||||
end
|
||||
end
|
||||
|
||||
describe "following/followers" do
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:other_user) { FactoryGirl.create(:user) }
|
||||
before { user.follow!(other_user) }
|
||||
|
||||
describe "followed users" do
|
||||
before do
|
||||
sign_in user
|
||||
visit following_user_path(user)
|
||||
end
|
||||
|
||||
it { should have_selector('title', text: full_title('Following')) }
|
||||
it { should have_selector('h3', text: 'Following') }
|
||||
it { should have_link(other_user.name, href: user_path(other_user)) }
|
||||
end
|
||||
|
||||
describe "followers" do
|
||||
before do
|
||||
sign_in other_user
|
||||
visit followers_user_path(other_user)
|
||||
end
|
||||
|
||||
it { should have_selector('title', text: full_title('Followers')) }
|
||||
it { should have_selector('h3', text: 'Followers') }
|
||||
it { should have_link(user.name, href: user_path(user)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
require 'rubygems'
|
||||
require 'spork'
|
||||
#uncomment the following line to use spork with the debugger
|
||||
#require 'spork/ext/ruby-debug'
|
||||
|
||||
Spork.prefork do
|
||||
# Loading more in this block will cause your tests to run faster. However,
|
||||
# if you change any configuration or code from libraries loaded here, you'll
|
||||
# need to restart spork for it take effect.
|
||||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||
ENV["RAILS_ENV"] ||= 'test'
|
||||
require File.expand_path("../../config/environment", __FILE__)
|
||||
require 'rspec/rails'
|
||||
require 'rspec/autorun'
|
||||
|
||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||
# in spec/support/ and its subdirectories.
|
||||
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
||||
|
||||
RSpec.configure do |config|
|
||||
# ## Mock Framework
|
||||
#
|
||||
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
||||
#
|
||||
# config.mock_with :mocha
|
||||
# config.mock_with :flexmock
|
||||
# config.mock_with :rr
|
||||
config.mock_with :rspec
|
||||
|
||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
# examples within a transaction, remove the following line or assign false
|
||||
# instead of true.
|
||||
config.use_transactional_fixtures = true
|
||||
|
||||
# If true, the base class of anonymous controllers will be inferred
|
||||
# automatically. This will be the default behavior in future versions of
|
||||
# rspec-rails.
|
||||
config.infer_base_class_for_anonymous_controllers = false
|
||||
end
|
||||
end
|
||||
|
||||
Spork.each_run do
|
||||
# This code will be run each time you run your specs.
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
include ApplicationHelper
|
||||
|
||||
def sign_in(user)
|
||||
visit signin_path
|
||||
fill_in "Email", with: user.email
|
||||
fill_in "Password", with: user.password
|
||||
click_button "Sign in"
|
||||
# Sign in when not using Capybara as well.
|
||||
cookies[:remember_token] = user.remember_token
|
||||
end
|
||||
Loading…
Reference in New Issue