-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
faa4601
commit c8c6db8
Showing
9 changed files
with
258 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,39 @@ | ||
require File.expand_path("../boot", __FILE__) | ||
|
||
# Pick the frameworks you want: | ||
require "active_model/railtie" | ||
require "active_job/railtie" | ||
require "active_record/railtie" | ||
require "action_controller/railtie" | ||
require "action_mailer/railtie" | ||
require "action_view/railtie" | ||
require "sprockets/railtie" | ||
# require "rails/test_unit/railtie" | ||
|
||
# Require the gems listed in Gemfile, including any gems | ||
# you"ve limited to :test, :development, or :production. | ||
Bundler.require(*Rails.groups) | ||
|
||
module Crb | ||
class Application < Rails::Application | ||
# Settings in config/environments/* take precedence over those specified here. | ||
# Application configuration should go into files in config/initializers | ||
# -- all .rb files in that directory are automatically loaded. | ||
|
||
config.middleware.delete Rack::Lock | ||
|
||
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. | ||
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. | ||
|
||
config.time_zone = "Hanoi" | ||
config.active_record.default_timezone = :local | ||
# config.active_record.time_zone_aware_attributes = false | ||
|
||
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. | ||
|
||
config.i18n.load_path += Dir[Rails.root.join("config", "locales", "*.{rb,yml}").to_s] | ||
config.i18n.default_locale = :en | ||
|
||
# Do not swallow errors in after_commit/after_rollback callbacks. | ||
config.active_record.raise_in_transactional_callbacks = true | ||
|
||
# Include the authenticity token in remote forms. | ||
config.action_view.embed_authenticity_token_in_remote_forms = true | ||
|
||
config.generators do |g| | ||
g.test_framework :rspec, | ||
fixtures: true, | ||
view_specs: true, | ||
helper_specs: false, | ||
routing_specs: false, | ||
controller_specs: true, | ||
request_specs: true | ||
g.fixture_replacement :factory_girl, dir: "spec/factories" | ||
end | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
FactoryGirl.define do | ||
factory :user do | ||
name {Faker::Company.name} | ||
email {Faker::Internet.email} | ||
sequence(:name) {|n| "example#{n}"} | ||
sequence(:email) {|n| "example#{n}@gmail.com"} | ||
password 123456 | ||
password_confirmation 123456 | ||
role Settings.user_roles.normal | ||
|
||
factory :user_with_avatar do | ||
avatar { File.new("#{Rails.root}/spec/factories/avatar.png") } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require "rails_helper" | ||
|
||
describe User do | ||
let(:user) {create :user} | ||
subject {user} | ||
|
||
describe "#user" do | ||
context "has a valid user" do | ||
it {is_expected.to be_an User} | ||
end | ||
end | ||
|
||
describe "#name" do | ||
describe "#validate presence" do | ||
before do | ||
subject.name = nil | ||
subject.save | ||
end | ||
context "should invalid withouth name" do | ||
it {expect(subject.errors[:name].size).to eq 1} | ||
end | ||
end | ||
|
||
describe "#validate length" do | ||
context "should invalid when maxinum length large than 100" do | ||
before do | ||
subject.name = "abcdefghij" * 100 | ||
subject.save | ||
end | ||
it {expect(subject.errors[:name].size).to eq 1} | ||
end | ||
|
||
context "should valid when maxinum length smaller than 100" do | ||
before do | ||
subject.name = "abcdefghij" * 5 | ||
subject.save | ||
end | ||
it {expect(subject.errors[:name].size).to eq 0} | ||
end | ||
end | ||
end | ||
|
||
describe "#avatar_size_method" do | ||
context "#validate" do | ||
it {allow(subject).to receive(:avatar_size)} | ||
end | ||
end | ||
|
||
describe "#avatar" do | ||
before {@another_user = create :user_with_avatar} | ||
context "should validate upload avatar" do | ||
it {expect(@another_user).to be_valid} | ||
end | ||
end | ||
|
||
describe "#user_role" do | ||
context "response to check user is normal" do | ||
it {expect(subject.admin?).to eq false} | ||
it {expect(subject.normal?).to eq true} | ||
end | ||
|
||
context "response to check user is admin" do | ||
before do | ||
subject.role = Settings.user_roles.admin | ||
subject.save | ||
end | ||
it {expect(subject.admin?).to eq true} | ||
it {expect(subject.normal?).to eq false} | ||
end | ||
end | ||
|
||
describe ".with_ids" do | ||
context "return the user if equal with id finding" do | ||
before {@another_user = subject.id} | ||
it {expect(User.with_ids(@another_user)).to include subject} | ||
end | ||
end | ||
|
||
describe ".without_user" do | ||
context "return the user if equl with id finding" do | ||
before {@another_user = 12} | ||
it {expect(User.without_user(@another_user)).to include subject} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
ENV["RAILS_ENV"] ||= "test" | ||
require File.expand_path("../../config/environment", __FILE__) | ||
|
||
abort("The Rails environment is running in production mode!") if Rails.env.production? | ||
|
||
require "spec_helper" | ||
require "rspec/rails" | ||
require "devise" | ||
require "factory_girl_rails" | ||
require "sidekiq" | ||
require "capybara/rspec" | ||
require "rails_admin" | ||
|
||
ActiveRecord::Migration.maintain_test_schema! | ||
|
||
RSpec.configure do |config| | ||
config.include Devise::TestHelpers, type: :controller | ||
config.include Devise::TestHelpers, type: :view | ||
config.include FactoryGirl::Syntax::Methods | ||
config.fixture_path = "#{::Rails.root}/spec/fixtures" | ||
config.use_transactional_fixtures = true | ||
config.infer_spec_type_from_file_location! | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# 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, consider making | ||
# a separate helper file that requires the additional dependencies and performs | ||
# the additional setup, and require it from the spec files 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| | ||
# 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| | ||
# This option will default to `true` in RSpec 4. It makes the `description` | ||
# and `failure_message` of custom matchers include text for helper methods | ||
# defined using `chain`, e.g.: | ||
# be_bigger_than(2).and_smaller_than(4).description | ||
# # => "be bigger than 2 and smaller than 4" | ||
# ...rather than: | ||
# # => "be bigger than 2" | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
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| | ||
# Prevents you from mocking or stubbing a method that does not exist on | ||
# a real object. This is generally recommended, and will default to | ||
# `true` in RSpec 4. | ||
mocks.verify_partial_doubles = true | ||
end | ||
|
||
# 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 | ||
# Allows RSpec to persist some state between runs in order to support | ||
# the `--only-failures` and `--next-failure` CLI options. We recommend | ||
# you configure your source control system to ignore this file. | ||
config.example_status_persistence_file_path = "spec/examples.txt" | ||
# Limits the available syntax to the non-monkey patched syntax that is | ||
# recommended. For more details, see: | ||
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax | ||
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ | ||
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching | ||
config.disable_monkey_patching! | ||
# 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 | ||
=end | ||
end |