Use faker gem, in account types - and add controller specs

This commit is contained in:
Brenda Wallace
2017-11-26 20:39:49 +13:00
committed by Shiny
parent 00e6aeed5c
commit 33816d4312
5 changed files with 41 additions and 6 deletions

View File

@@ -134,6 +134,7 @@ group :development, :test do
gem 'coveralls', require: false # coverage analysis
gem 'database_cleaner'
gem 'factory_bot_rails' # for creating test data
gem 'faker'
gem 'haml-i18n-extractor'
gem 'haml-rails' # HTML templating language
gem 'haml_lint' # Checks haml files for goodness

View File

@@ -181,6 +181,8 @@ GEM
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faker (1.8.4)
i18n (~> 0.5)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
ffi (1.9.18)
@@ -578,6 +580,7 @@ DEPENDENCIES
elasticsearch-model
elasticsearch-rails
factory_bot_rails
faker
figaro
flickraw
font-awesome-sass
@@ -633,7 +636,6 @@ DEPENDENCIES
will_paginate
xmlrpc
RUBY VERSION
ruby 2.4.1p111

View File

@@ -1,6 +1,12 @@
class AccountType < ActiveRecord::Base
#
# Relationships
has_many :products
#
# Validations
validates :name, presence: true, uniqueness: true
def to_s
name
end

View File

@@ -1,10 +1,30 @@
require 'rails_helper'
describe AccountTypesController do
# This automatically creates a "Free" account type
login_member(:admin_member)
subject { response }
def valid_attributes
{ "name" => "MyString" }
context 'anon' do
describe '#index' do
before { get :index }
it { is_expected.not_to be_success }
end
end
context 'member' do
login_member(:member)
describe '#index' do
before { get :index }
it { is_expected.not_to be_success }
end
end
context 'admin' do
login_member(:admin_member)
describe '#index' do
let!(:aaa) { FactoryBot.create :account_type, name: 'aaa' }
let!(:zzz) { FactoryBot.create :account_type, name: 'zzz' }
before { get :index }
it { is_expected.to be_success }
it { expect(assigns[:account_types].first).to eql(aaa) }
it { expect(assigns[:account_types].last).to eql(zzz) }
end
end
end

View File

@@ -2,10 +2,16 @@
FactoryBot.define do
factory :account_type do
name "Free"
name { Faker::Name.unique.name }
is_paid false
is_permanent_paid false
factory :free_account_type do
name "Free"
is_paid false
is_permanent_paid false
end
factory :paid_account_type do
name "Paid"
is_paid true