Permalink
Browse files

Atualizando rspec para versão 3 e adequando a rails 4

  • Loading branch information...
nicolaslazartekaqui committed Jun 9, 2014
1 parent cb9048f commit 369695963a274407656261a5d9618434aaa66f51
View
2 .rspec
@@ -1,2 +1,2 @@
--color
--format documentation
--require spec_helper
@@ -20,7 +20,7 @@ def change_roles
user.role_ids -= [role_id]
end
end
# If it is an global role
unless @site
user.roles.where(site_id: nil).each{|r| user.role_ids -= [r.id] }
@@ -49,7 +49,7 @@ def index
order(sort_column + " " + sort_direction).page(params[:page]).
per((params[:per_page] || per_page_default ))
if @site
if @site
@users = @users.by_site(@site.id)
end
@@ -94,11 +94,12 @@ def update
def destroy
@user = User.find(params[:id])
@user.destroy
flash[:success] = t("destroyed_param", param: @user.first_name)
record_activity("destroyed_user", @user)
rescue ActiveRecord::DeleteRestrictionError
flash[:warning] = t("user_cant_be_deleted")
ensure
if @user.errors.full_messages.empty?
flash[:success] = t("destroyed_param", param: @user.first_name)
record_activity("destroyed_user", @user)
else
flash[:warning] = t("user_cant_be_deleted")
end
redirect_to admin_users_path
end
@@ -107,7 +108,7 @@ def destroy
def sort_column
User.column_names.include?(params[:sort]) ? params[:sort] : 'id'
end
def user_params
params[:user].slice(:login, :email, :password, :password_confirmation, :first_name, :last_name, :phone, :mobile, :locale_id)
end
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe ActivityRecord do
it { expect(subject).to belong_to(:user) }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Component do
it { expect(subject).to belong_to(:site) }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Extension do
it { expect(subject).to belong_to(:site) }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Grouping do
it { expect(subject).to validate_presence_of(:name) }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Locale do
it { expect(subject).to have_and_belong_to_many(:sites) }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe MenuItem do
it { expect(subject).to belong_to(:menu) }
View
@@ -1,9 +1,8 @@
require 'spec_helper'
require 'rails_helper'
describe Menu do
it { expect(subject).to validate_presence_of(:name) }
it { expect(subject).to validate_presence_of(:site_id) }
it { expect(subject).to validate_numericality_of(:site_id) }
it { expect(subject).to validate_presence_of(:site) }
it { expect(subject).to belong_to(:site) }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Notification do
it { expect(subject).to belong_to(:user) }
View
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Page do
it { expect(subject).to belong_to(:owner).class_name('Site') }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe PagesRepository do
it { expect(subject).to belong_to(:page) }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Repository do
it { expect(subject).to have_many(:page).with_foreign_key('repository_id') }
View
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Role do
it { expect(subject).to validate_presence_of(:name) }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Setting do
it { expect(subject).to validate_uniqueness_of(:name) }
View
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe Site do
skip 'Scopes' do
@@ -51,7 +51,7 @@
it { expect(subject).to belong_to(:main_site).class_name('Site').with_foreign_key('parent_id') }
it { expect(subject).to have_many(:roles) }
it { expect(subject).to have_many(:views) }
it { expect(subject).to have_many(:menus).dependent(:delete_all).order(:id) }
@@ -60,15 +60,16 @@
it { expect(subject).to have_many(:pages).dependent(:delete_all) }
it { expect(subject).to have_many(:pages_i18ns).through(:pages) }
#StickerBanners
skip { expect(subject).to have_many(:banners).order(:position) }
it { expect(subject).to have_many(:styles).dependent(:destroy).order('styles.position desc') }
it { expect(subject).to have_many(:styles).dependent(:destroy).order('styles.position DESC') }
context 'Component' do
it 'components should be ordered by place_holder, position asc' do
expect(subject).to have_many(:components).dependent(:destroy).order('place_holder, position asc')
expect(subject).to have_many(:components).dependent(:destroy)
.order([:place_holder, :position])
end
it { expect(subject).to have_many(:root_components).order(:position).class_name('Component') }
@@ -1,10 +1,10 @@
require 'spec_helper'
require 'rails_helper'
describe Style do
it { expect(subject).to belong_to(:site) }
it { expect(subject).to belong_to(:style) }
it { expect(subject).to have_many(:styles).dependent(:restrict) }
it { expect(subject).to have_many(:styles).dependent(:restrict_with_error) }
it { expect(subject).to have_many(:followers).through(:styles) }
it { expect(subject).to validate_presence_of(:site) }
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe UserLoginHistory do
it { expect(subject).to belong_to(:user) }
View
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe User do
it { expect(subject).to validate_presence_of(:email) }
@@ -96,7 +96,7 @@
end
context 'Pages' do
it { expect(subject).to have_many(:pages).with_foreign_key(:author_id).dependent(:restrict) }
it { expect(subject).to have_many(:pages).with_foreign_key(:author_id).dependent(:restrict_with_error) }
end
context 'Views' do
View
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'rails_helper'
describe View do
it { expect(subject).to belong_to(:site) }
View
@@ -0,0 +1,48 @@
# 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'
require 'paperclip/matchers'
# 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 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"
config.include FactoryGirl::Syntax::Methods
# 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!
# paperclip
config.include Paperclip::Shoulda::Matchers
end
View
@@ -1,46 +1,74 @@
# 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 }
# 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|
# ## 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
# 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
# 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
config.expect_with :rspec do |c|
c.syntax = :expect
# 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
config.include FactoryGirl::Syntax::Methods
# 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"
config.order = :random
config.include Paperclip::Shoulda::Matchers
# 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
No changes.

This file was deleted.

Oops, something went wrong.

0 comments on commit 3696959

Please sign in to comment.