Sha256: 996ae2bf9bb7c833a1db199a6afe49e50795a66d06b570182a9386964372af7d

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require 'rails_helper'

RSpec.describe TbCommerce::Product, type: :model do

  describe '.search' do
    it 'should return the product for matching title' do
      product = FactoryGirl.create(:tb_commerce_product, :title => 'Hello, World!')
      expect(TbCommerce::Product.search('Hello, World!').first).to eq(product)
    end
    
    it 'should return the product for matching description' do
      product = FactoryGirl.create(:tb_commerce_product, :description => 'Hello, World!')
      expect(TbCommerce::Product.search('Hello, World!').first).to eq(product)
    end

    it 'should not return any results' do
      product = FactoryGirl.create(:tb_commerce_product)
      expect(TbCommerce::Product.search('Fail').length).to eq(0)
    end
  end

  describe '#generate_slug_from_title' do
    it 'should generate a url slug for the product' do
      product = FactoryGirl.create(:tb_commerce_product)
      expect(product.slug).to be_a(String)
    end

    it 'should also change the slug if the title changes' do
      product = FactoryGirl.create(:tb_commerce_product)
      expect{
        product.update_attribute(:title, 'New Product Title')
      }.to change(product, :slug)
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tb_commerce-0.0.4 spec/models/tb_commerce/product_spec.rb
tb_commerce-0.0.3 spec/models/tb_commerce/product_spec.rb
tb_commerce-0.0.2 spec/models/tb_commerce/product_spec.rb