mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 13:38:24 -04:00
Use faker gem, in account types - and add controller specs
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
class AccountType < ActiveRecord::Base
|
||||
#
|
||||
# Relationships
|
||||
has_many :products
|
||||
|
||||
#
|
||||
# Validations
|
||||
validates :name, presence: true, uniqueness: true
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user