Sha256: 3c4293a44551dab7af3e4835b9e60105bd9bc6bb978670128d5e08d3d523ba92

Contents?: true

Size: 1.33 KB

Versions: 30

Compression:

Stored size: 1.33 KB

Contents

require 'test_helper'
require 'generators/adminpanel/contact/contact_generator'

class ContactGeneratorTest < Rails::Generators::TestCase
  tests Adminpanel::ContactGenerator
  destination Rails.root.join('tmp/generators')
  setup :prepare_destination

  def test_the_generation_of_the_attr_accessor_params
    run_generator %w(body email name age country)
    assert_file(
      'app/models/contact.rb',
      /attr_accessor :email, :name, :age, :country, :body/
    )
  end

  def test_generation_of_validations
    run_generator %w(body email name age country)
    assert_file(
      'app/models/contact.rb',
      /validates_presence_of :email/,
      /validates_presence_of :body/,
      /validates_presence_of :age/,
      /validates_presence_of :name/,
      /validates_presence_of :country/
    )
  end

  def test_generation_of_email_validations
    run_generator %w(email body)
    assert_file(
      'app/models/contact.rb',
      /# validations for email/,
      /VALID_EMAIL_REGEX = \/\\A\[\\w\+\\-.\]\+@\[a-z\\d\\-.\]\+\\.\[a-z\]\+\\z\/i/,
      /validates_format_of :email, with: VALID_EMAIL_REGEX, message: "\#{I18n.t\('model.attributes.email'\)} \#{I18n.t\('activerecord.errors.messages.invalid'\)}"/
    )
  end

  def test_generation

  end

  def test_runs_without_errors
    assert_nothing_raised do
      run_generator
    end
  end

end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
adminpanel-3.6.1 test/generators/contact_generator_test.rb
adminpanel-3.6.0 test/generators/contact_generator_test.rb
adminpanel-3.5.1 test/generators/contact_generator_test.rb
adminpanel-3.5.0 test/generators/contact_generator_test.rb
adminpanel-3.4.7 test/generators/contact_generator_test.rb
adminpanel-3.4.6 test/generators/contact_generator_test.rb
adminpanel-3.4.5 test/generators/contact_generator_test.rb
adminpanel-3.4.4 test/generators/contact_generator_test.rb
adminpanel-3.4.3 test/generators/contact_generator_test.rb
adminpanel-3.4.2 test/generators/contact_generator_test.rb
adminpanel-3.4.1 test/generators/contact_generator_test.rb
adminpanel-3.4.0 test/generators/contact_generator_test.rb
adminpanel-3.3.4 test/generators/contact_generator_test.rb
adminpanel-3.3.3 test/generators/contact_generator_test.rb
adminpanel-3.3.0 test/generators/contact_generator_test.rb
adminpanel-3.2.1 test/generators/contact_generator_test.rb
adminpanel-3.2.0 test/generators/contact_generator_test.rb
adminpanel-3.1.0 test/generators/contact_generator_test.rb
adminpanel-3.0.0 test/generators/contact_generator_test.rb
adminpanel-2.6.1 test/generators/contact_generator_test.rb