Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
phawk committed Dec 17, 2017
1 parent d83ef6a commit e242f12
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/base_controller.rb
Expand Up @@ -13,7 +13,7 @@ class BaseController < ActionController::Base
private

def serialize_collection(scope)
scope.map { |obj| ActiveModel::SerializableResource.new(obj, root: :root_key_name).serializable_hash[:root_key_name] }
scope.map { |obj| ActiveModelSerializers::SerializableResource.new(obj, root: :root_key_name).serializable_hash[:root_key_name] }
end

def render_errors(object)
Expand Down
4 changes: 2 additions & 2 deletions app/serializers/comment_serializer.rb
Expand Up @@ -4,12 +4,12 @@ class CommentSerializer < ActiveModel::Serializer
attributes :id, :content, :markdown, :commentable_type, :commentable_id, :owner_id, :created_at, :updated_at, :team_id, :owner, :attachments

def owner
ActiveModel::SerializableResource.new(object.owner).serializable_hash[:user]
ActiveModelSerializers::SerializableResource.new(object.owner).serializable_hash[:user]
end

def attachments
object.attachments.map do |a|
ActiveModel::SerializableResource.new(a).serializable_hash[:attachment]
ActiveModelSerializers::SerializableResource.new(a).serializable_hash[:attachment]
end
end

Expand Down
28 changes: 14 additions & 14 deletions spec/models/user_spec.rb
Expand Up @@ -3,20 +3,20 @@
RSpec.describe User do
let(:user) { build(:user) }

it { should have_many(:created_projects) }
it { should have_many(:stories) }
it { should have_many(:notifications) }
it { should have_and_belong_to_many(:projects) }

it { should validate_presence_of(:first_name) }
it { should validate_presence_of(:last_name) }
it { should validate_presence_of(:notification_frequency) }
it { should validate_presence_of(:username) }

it { should allow_value("freddy1997").for(:username) }
it { should allow_value("freddy_1997").for(:username) }
it { should allow_value("freddy-1997").for(:username) }
it { should_not allow_value("@freddyZ").for(:username) }
it { is_expected.to have_many(:created_projects) }
it { is_expected.to have_many(:stories) }
it { is_expected.to have_many(:notifications) }
it { is_expected.to have_and_belong_to_many(:projects) }

it { is_expected.to validate_presence_of(:first_name) }
it { is_expected.to validate_presence_of(:last_name) }
it { is_expected.to validate_presence_of(:notification_frequency) }
it { is_expected.to validate_presence_of(:username) }

it { is_expected.to allow_value("freddy1997").for(:username) }
it { is_expected.to allow_value("freddy_1997").for(:username) }
it { is_expected.to allow_value("freddy-1997").for(:username) }
it { is_expected.not_to allow_value("@freddyZ").for(:username) }

it "must be valid" do
expect(user).to be_valid
Expand Down
6 changes: 6 additions & 0 deletions spec/rails_helper.rb
Expand Up @@ -16,6 +16,12 @@
require 'support/feature_helper'
require 'support/api_helper'

Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
Expand Down

0 comments on commit e242f12

Please sign in to comment.