diff --git a/Gemfile b/Gemfile index af99703..458758e 100644 --- a/Gemfile +++ b/Gemfile @@ -57,6 +57,11 @@ gem 'omniauth-soundcloud', '~> 1.0.0' gem 'omniauth-live_connect' gem 'omniauth-yahoo', '~> 0.0.5' gem "pundit" +gem "rspec" +gem "rspec-core" +gem "rspec-rails" +gem "guard-rspec" +gem 'spring-commands-rspec' # support for pg gem 'pg' diff --git a/Gemfile.lock b/Gemfile.lock index d15951a..fe5fd64 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -35,6 +35,9 @@ GEM bootstrap-sass (3.2.0.1) sass (~> 3.2) builder (3.2.2) + celluloid (0.15.2) + timers (~> 1.1.0) + coderay (1.1.0) coffee-rails (4.0.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -48,12 +51,24 @@ GEM railties (>= 3.2.6, < 5) thread_safe (~> 0.1) warden (~> 1.2.3) + diff-lcs (1.2.5) erubis (2.7.0) execjs (2.2.1) faraday (0.9.0) multipart-post (>= 1.2, < 3) + ffi (1.9.3) font-awesome-sass (4.1.0) sass (~> 3.2) + formatador (0.2.5) + guard (2.6.1) + formatador (>= 0.2.4) + listen (~> 2.7) + lumberjack (~> 1.0) + pry (>= 0.9.12) + thor (>= 0.18.1) + guard-rspec (4.3.1) + guard (~> 2.1) + rspec (>= 2.14, < 4.0) hashie (3.3.1) hike (1.2.3) i18n (0.6.11) @@ -66,9 +81,15 @@ GEM json (1.8.1) jwt (1.0.0) libv8 (3.16.14.3) + listen (2.7.9) + celluloid (>= 0.15.2) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + lumberjack (1.0.9) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) + method_source (0.8.2) mime-types (1.25.1) minitest (5.4.0) multi_json (1.10.1) @@ -108,6 +129,10 @@ GEM orm_adapter (0.5.0) pg (0.17.1) polyglot (0.3.5) + pry (0.10.1) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) pundit (0.3.0) activesupport (>= 3.0.0) rack (1.5.2) @@ -129,9 +154,32 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.3.2) + rb-fsevent (0.9.4) + rb-inotify (0.9.5) + ffi (>= 0.5.0) rdoc (4.1.1) json (~> 1.4) ref (1.0.5) + rspec (3.0.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-core (3.0.4) + rspec-support (~> 3.0.0) + rspec-expectations (3.0.4) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.0.0) + rspec-mocks (3.0.4) + rspec-support (~> 3.0.0) + rspec-rails (3.0.2) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 3.0.0) + rspec-expectations (~> 3.0.0) + rspec-mocks (~> 3.0.0) + rspec-support (~> 3.0.0) + rspec-support (3.0.4) sass (3.2.19) sass-rails (4.0.3) railties (>= 4.0.0, < 5.0) @@ -141,7 +189,10 @@ GEM sdoc (0.4.1) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + slop (3.6.0) spring (1.1.3) + spring-commands-rspec (1.0.2) + spring (>= 0.9.1) sprockets (2.11.0) hike (~> 1.2) multi_json (~> 1.0) @@ -158,6 +209,7 @@ GEM thor (0.19.1) thread_safe (0.3.4) tilt (1.4.1) + timers (1.1.0) treetop (1.4.15) polyglot polyglot (>= 0.3.1) @@ -182,6 +234,7 @@ DEPENDENCIES devise execjs font-awesome-sass + guard-rspec hashie (~> 3.3.1) jbuilder (~> 2.0) jquery-rails @@ -195,9 +248,13 @@ DEPENDENCIES pg pundit rails (= 4.1.4) + rspec + rspec-core + rspec-rails sass-rails (~> 4.0.3) sdoc (~> 0.4.0) spring + spring-commands-rspec sqlite3 therubyracer turbolinks diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..c6ea068 --- /dev/null +++ b/Guardfile @@ -0,0 +1,30 @@ +# Note: The cmd option is now required due to the increasing number of ways +# rspec may be run, below are examples of the most common uses. +# * bundler: 'bundle exec rspec' +# * bundler binstubs: 'bin/rspec' +# * spring: 'bin/rsspec' (This will use spring if running and you have +# installed the spring binstubs per the docs) +# * zeus: 'zeus rspec' (requires the server to be started separetly) +# * 'just' rspec: 'rspec' +guard :rspec, cmd: 'bundle exec rspec' 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{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_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('config/routes.rb') { "spec/routing" } + watch('app/controllers/application_controller.rb') { "spec/controllers" } + watch('spec/rails_helper.rb') { "spec" } + + # Capybara features specs + watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" } + + # Turnip features and steps + watch(%r{^spec/acceptance/(.+)\.feature$}) + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } +end + diff --git a/app/models/comment.rb b/app/models/comment.rb new file mode 100644 index 0000000..5550fe0 --- /dev/null +++ b/app/models/comment.rb @@ -0,0 +1,4 @@ +class Comment < ActiveRecord::Base + belongs_to :user + belongs_to :link +end diff --git a/app/models/like.rb b/app/models/like.rb new file mode 100644 index 0000000..5e7cc10 --- /dev/null +++ b/app/models/like.rb @@ -0,0 +1,5 @@ +class Like < ActiveRecord::Base + belongs_to :user + belongs_to :comment + belongs_to :link +end diff --git a/app/models/message.rb b/app/models/message.rb new file mode 100644 index 0000000..2a9052b --- /dev/null +++ b/app/models/message.rb @@ -0,0 +1,4 @@ +class Message < ActiveRecord::Base + belongs_to :sender, :class_name => "User" + belongs_to :receiver, :class_name => "User" +end diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..20060eb --- /dev/null +++ b/bin/rspec @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby +begin + load File.expand_path("../spring", __FILE__) +rescue LoadError +end +require 'bundler/setup' +load Gem.bin_path('rspec-core', 'rspec') diff --git a/db/migrate/20140904201612_create_comments.rb b/db/migrate/20140904201612_create_comments.rb new file mode 100644 index 0000000..fb2a8ff --- /dev/null +++ b/db/migrate/20140904201612_create_comments.rb @@ -0,0 +1,12 @@ +class CreateComments < ActiveRecord::Migration + def change + create_table :comments do |t| + t.text :comment + t.datetime :when + t.belongs_to :user + t.belongs_to :link + + t.timestamps + end + end +end diff --git a/db/migrate/20140904201944_create_likes.rb b/db/migrate/20140904201944_create_likes.rb new file mode 100644 index 0000000..4607aff --- /dev/null +++ b/db/migrate/20140904201944_create_likes.rb @@ -0,0 +1,10 @@ +class CreateLikes < ActiveRecord::Migration + def change + create_table :likes do |t| + t.belongs_to :user + t.belongs_to :comment, null: true + t.belongs_to :link, null: true + t.timestamps + end + end +end diff --git a/db/migrate/20140904203245_create_messages.rb b/db/migrate/20140904203245_create_messages.rb new file mode 100644 index 0000000..e5e9e70 --- /dev/null +++ b/db/migrate/20140904203245_create_messages.rb @@ -0,0 +1,12 @@ +class CreateMessages < ActiveRecord::Migration + def change + create_table :messages do |t| + t.string :name + t.text :content + t.belongs_to :sender, :class_name => "User" + t.belongs_to :receiver, :class_name => "User" + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 95fde23..7fc1f37 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,11 +11,38 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140830165824) do +ActiveRecord::Schema.define(version: 20140904203245) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" + create_table "comments", force: true do |t| + t.text "comment" + t.datetime "when" + t.integer "user_id" + t.integer "link_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "identities", force: true do |t| + t.integer "user_id" + t.string "provider" + t.string "uid" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree + + create_table "likes", force: true do |t| + t.integer "user_id" + t.integer "comment_id" + t.integer "link_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "links", force: true do |t| t.integer "user_id" t.string "name" @@ -41,6 +68,15 @@ t.datetime "updated_at" end + create_table "messages", force: true do |t| + t.string "name" + t.text "content" + t.integer "sender_id" + t.integer "receiver_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "music_types", force: true do |t| t.string "name" t.datetime "created_at" @@ -60,8 +96,14 @@ t.inet "last_sign_in_ip" t.datetime "created_at" t.datetime "updated_at" + t.string "name" + t.string "confirmation_token" + t.datetime "confirmed_at" + t.datetime "confirmation_sent_at" + t.string "unconfirmed_email" end + add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb new file mode 100644 index 0000000..16c4a46 --- /dev/null +++ b/spec/models/comment_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Comment, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/like_spec.rb b/spec/models/like_spec.rb new file mode 100644 index 0000000..8b6cce0 --- /dev/null +++ b/spec/models/like_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Like, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb new file mode 100644 index 0000000..37e8e9f --- /dev/null +++ b/spec/models/message_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Message, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb new file mode 100644 index 0000000..4d1d439 --- /dev/null +++ b/spec/rails_helper.rb @@ -0,0 +1,43 @@ +# This file is copied to spec/ when you run 'rails generate rspec:install' +ENV["RAILS_ENV"] ||= 'test' +require 'spec_helper' +require File.expand_path("../../config/environment", __FILE__) +require 'rspec/rails' + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } + +# Checks for pending migrations before tests are run. +# If you are not using ActiveRecord, you can remove this line. +ActiveRecord::Migration.maintain_test_schema! + +RSpec.configure do |config| + # 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 + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..cfb18dc --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,78 @@ +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause this +# file to always be loaded, without a need to explicitly require it in any files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, make a +# separate helper file that requires this one and then use it only in the specs +# that actually need it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed + + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # Enable only the newer, non-monkey-patching expect syntax. + # For more details, see: + # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax + expectations.syntax = :expect + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Enable only the newer, non-monkey-patching expect syntax. + # For more details, see: + # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + mocks.syntax = :expect + + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended. + mocks.verify_partial_doubles = true + end +=end +end diff --git a/test/models/user_spec.rb b/test/models/user_spec.rb new file mode 100644 index 0000000..39bed8b --- /dev/null +++ b/test/models/user_spec.rb @@ -0,0 +1,29 @@ +# spec/models/user_spec.rb + +# Prefix class methods with a '.' +describe User, '.active' do + it 'returns only active users' do + # setup + active_user = create(:user, active: true) + non_active_user = create(:user, active: false) + + # exercise + result = User.active + + # verify + expect(result).to eq [active_user] + + # teardown is handled for you by RSpec + end +end + +# Prefix instance methods with a '#' +describe User, '#name' do + it 'returns the concatenated first and last name' do + # setup + user = build(:user, first_name: 'Josh', last_name: 'Steiner') + + # excercise and verify + expect(user.name).to eq 'Josh Steiner' + end +end