Sha256: 1e7dee38826485d74e88f51bfe61986c2a444ac8ef5a0b3e0235dd9329513be4

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

# -*- coding: utf-8 -*-
require 'spec_helper'

describe 'Schemaless::Worker' do

  it 'should create cc on bikes' do
    Schemaless::Worker.run!
    expect { Bike.create!(name: 'Gina', cc: 600) }.to_not raise_error
    expect(Bike.count).to eq(1)
  end

  it 'should re-run nicely' do
    Schemaless::Worker.run!
    Schemaless::Worker.run!
    expect { Bike.create!(name: 'Gina', cc: 600) }.to_not raise_error
    expect(Bike.count).to eq(1)
  end

  it 'should work in sandbox mode' do
    Schemaless.sandbox = true
    Schemaless::Worker.run!
    expect { Bike.create!(name: 'Gina', cc: 600) }.to raise_error
    expect(Bike.count).to be_zero
  end

  it 'should create a foreign key with belongs_to' do
    Schemaless::Worker.run!
    user = User.create!(name: 'Lemmy')
    expect { Bike.create(name: 'Dark', user: user)  }.to_not raise_error
  end

  describe 'Field creation' do

    it 'should create table if inexistant' do
      # ActiveRecord::Migration.drop_table(:bikes)
      Schemaless::Worker.run!
      expect { Bike.create!(name: 'Gina', cc: 600) }.to_not raise_error
      expect(Bike.count).to eq(1)
    end

  end

  describe 'Migrations' do

    it 'should create migration files' do
      pending
      Schemaless::Worker.generate!
      expect(File.exist?('spec/dummy/db/migrate/fu')).to eq(true)
    end

    it 'should not touch database schema version' do
      expect { Schemaless::Worker.run! }
        .to_not change(ActiveRecord::Migrator, :get_all_versions)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
schemaless-0.0.5 spec/schemaless/worker_spec.rb
schemaless-0.0.3 spec/schemaless/worker_spec.rb