moved all the specs to the right place

This commit is contained in:
Morgan Lieberthal 2015-08-27 14:48:25 -06:00
parent d358537d12
commit 978fad058c
15 changed files with 2 additions and 303 deletions

View File

@ -1,16 +0,0 @@
require_relative '../rails_helper'
RSpec.describe Draper::CollectionDecorator do
describe "#active_model_serializer" do
it "returns ActiveModel::ArraySerializer" do
collection_decorator = Draper::CollectionDecorator.new([])
if defined?(ActiveModel::ArraySerializerSupport)
collection_serializer = collection_decorator.active_model_serializer
else
collection_serializer = ActiveModel::Serializer.serializer_for(collection_decorator)
end
expect(collection_serializer).to be ActiveModel::ArraySerializer
end
end
end

View File

@ -1,64 +0,0 @@
require_relative '../rails_helper'
if defined?(Devise)
RSpec.describe "A decorator spec" do
it "can sign in a real user" do
user = User.new
sign_in user
expect(helper.current_user).to be user
end
it "can sign in a mock user" do
user = double("User")
sign_in :user, user
expect(helper.current_user).to be user
end
it "can sign in a real admin" do
admin = Admin.new
sign_in admin
expect(helper.current_admin).to be admin
end
it "can sign in a mock admin" do
admin = double("Admin")
sign_in :admin, admin
expect(helper.current_admin).to be admin
end
it "can sign out a real user" do
user = User.new
sign_in user
sign_out user
expect(helper.current_user).to be_nil
end
it "can sign out a mock user" do
user = double("User")
sign_in :user, user
sign_out :user
expect(helper.current_user).to be_nil
end
it "can sign out without a user" do
sign_out :user
expect(helper.current_user).to be_nil
end
it "is backwards-compatible" do
user = double("User")
ActiveSupport::Deprecation.silence do
sign_in user
end
expect(helper.current_user).to be user
end
end
end

View File

@ -1,21 +0,0 @@
require_relative '../rails_helper'
RSpec.describe "A decorator spec" do
it "can access helpers through `helper`" do
expect(helper.content_tag(:p, "Help!")).to eq "<p>Help!</p>"
end
it "can access helpers through `helpers`" do
expect(helpers.content_tag(:p, "Help!")).to eq "<p>Help!</p>"
end
it "can access helpers through `h`" do
expect(h.content_tag(:p, "Help!")).to eq "<p>Help!</p>"
end
it "gets the same helper object as a decorator" do
decorator = Draper::Decorator.new(Object.new)
expect(helpers).to be decorator.helpers
end
end

View File

@ -1,66 +0,0 @@
require_relative '../rails_helper'
RSpec.describe PostDecorator do
let(:decorator) { PostDecorator.new(object) }
let(:object) { Post.create }
it "can use built-in helpers" do
expect(decorator.truncated).to eq "Once upon a..."
end
it "can use built-in private helpers" do
expect(decorator.html_escaped).to eq "&lt;script&gt;danger&lt;/script&gt;"
end
it "can use user-defined helpers from app/helpers" do
expect(decorator.hello_world).to eq "Hello, world!"
end
it "can be passed to path helpers" do
expect(helpers.post_path(decorator)).to eq "/en/posts/#{object.id}"
end
it "can use path helpers with its model" do
expect(decorator.path_with_model).to eq "/en/posts/#{object.id}"
end
it "can use path helpers with its id" do
expect(decorator.path_with_id).to eq "/en/posts/#{object.id}"
end
it "can be passed to url helpers" do
expect(helpers.post_url(decorator)).to eq "http://www.example.com:12345/en/posts/#{object.id}"
end
it "can use url helpers with its model" do
expect(decorator.url_with_model).to eq "http://www.example.com:12345/en/posts/#{object.id}"
end
it "can use url helpers with its id" do
expect(decorator.url_with_id).to eq "http://www.example.com:12345/en/posts/#{object.id}"
end
it "can be passed implicitly to url_for" do
expect(decorator.link).to eq "<a href=\"/en/posts/#{object.id}\">#{object.id}</a>"
end
it "serializes overriden attributes" do
expect(decorator.serializable_hash["updated_at"]).to be :overridden
end
it "serializes to JSON" do
json = decorator.to_json
expect(json).to match /"updated_at":"overridden"/
end
it "serializes to XML" do
pending("Rails < 3.2 does not use `serializable_hash` in `to_xml`") if Rails.version.to_f < 3.2
xml = Capybara.string(decorator.to_xml)
expect(xml).to have_css "post > updated-at", text: "overridden"
end
it "uses a test view context from ApplicationController" do
expect(Draper::ViewContext.current.controller).to be_an ApplicationController
end
end

View File

@ -1,7 +0,0 @@
require_relative '../rails_helper'
RSpec.describe "A spec in this folder" do
it "is a decorator spec" do
expect(RSpec.current_example.metadata[:type]).to be :decorator
end
end

View File

@ -1,22 +0,0 @@
require_relative '../rails_helper'
def it_does_not_leak_view_context
2.times do
it "has an independent view context" do
expect(Draper::ViewContext.current).not_to be :leaked
Draper::ViewContext.current = :leaked
end
end
end
RSpec.describe "A decorator spec", type: :decorator do
it_does_not_leak_view_context
end
RSpec.describe "A controller spec", type: :controller do
it_does_not_leak_view_context
end
RSpec.describe "A mailer spec", type: :mailer do
it_does_not_leak_view_context
end

View File

@ -1,5 +1,6 @@
require 'spec_helper'
require_relative '../../dummy/spec/rails_helper'
require 'rspec/rails'
# require_relative '../../dummy/spec/rails_helper'
require 'ammeter/init'
require 'generators/rails/decorator_generator'

View File

@ -1,33 +0,0 @@
require_relative '../rails_helper'
RSpec.describe PostMailer do
describe "#decorated_email" do
let(:email_body) { Capybara.string(email.body.to_s) }
let(:email) { PostMailer.decorated_email(post).deliver }
let(:post) { Post.create }
it "decorates" do
expect(email_body).to have_content "Today"
end
it "can use path helpers with a model" do
expect(email_body).to have_css "#path_with_model", text: "/en/posts/#{post.id}"
end
it "can use path helpers with an id" do
expect(email_body).to have_css "#path_with_id", text: "/en/posts/#{post.id}"
end
it "can use url helpers with a model" do
expect(email_body).to have_css "#url_with_model", text: "http://www.example.com:12345/en/posts/#{post.id}"
end
it "can use url helpers with an id" do
expect(email_body).to have_css "#url_with_id", text: "http://www.example.com:12345/en/posts/#{post.id}"
end
it "uses the correct view context controller" do
expect(email_body).to have_css "#controller", text: "PostMailer"
end
end
end

View File

@ -1,8 +0,0 @@
require_relative '../spec_helper'
require_relative '../shared_examples/decoratable'
if defined?(Mongoid)
RSpec.describe MongoidPost do
it_behaves_like "a decoratable model"
end
end

View File

@ -1,6 +0,0 @@
require_relative '../spec_helper'
require_relative '../shared_examples/decoratable'
RSpec.describe Post do
it_behaves_like "a decoratable model"
end

View File

@ -1,32 +0,0 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort('Rails is running in production mode!') if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
# 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`.
#
# The following line is provided for convenience purposes. It has the downside
# of increasing the boot-up time by auto-requiring all files in the support
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
# 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|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
end

View File

@ -1,24 +0,0 @@
RSpec.shared_examples_for "a decoratable model" do
describe ".decorate" do
it "applies a collection decorator to a scope" do
described_class.create
decorated = described_class.limit(1).decorate
expect(decorated.size).to eq(1)
expect(decorated).to be_decorated
end
end
describe "#==" do
it "is true for other instances' decorators" do
pending "Mongoid < 3.1 overrides `#==`" if defined?(Mongoid) && Mongoid::VERSION.to_f < 3.1 && described_class < Mongoid::Document
described_class.create
one = described_class.first
other = described_class.first
expect(one).not_to be other
expect(one == other.decorate).to be_truthy
end
end
end