Sha256: e31b709e987e3a5d6037f556a21d722f2c020b98d16390ab83776cbf440c4da0

Contents?: true

Size: 1.62 KB

Versions: 2

Compression:

Stored size: 1.62 KB

Contents

require 'spec_helper'

describe ActiveGit::Inflector do

  before :each do
    @file_helper = FileHelper.new
    ActiveGit.configuration.working_path = @file_helper.create_temp_folder
  end

  after :each do
    @file_helper.remove_temp_folders
  end

  let(:working_path) { '/home/git' }

  it 'Git path' do
    ActiveGit::Inflector.dirname(Country, working_path).should eq "#{working_path}/countries"
  end

  it 'Git path for nested model' do
    ActiveGit::Inflector.dirname(Crm::Customer, working_path).should eq "#{working_path}/crm/customers"
  end

  it 'Git relative path' do
    ActiveGit::Inflector.relative_dirname(Country).should eq "countries"
  end

  it 'Git file' do
    country = Country.create! name: 'Argentina'
    ActiveGit::Inflector.filename(country, working_path).should eq "#{working_path}/countries/#{country.id}.json"
  end

  it 'Git file for nested model' do
    customer = Crm::Customer.create! name: 'Monster Inc.'
    ActiveGit::Inflector.filename(customer, working_path).should eq "#{working_path}/crm/customers/#{customer.id}.json"
  end

  it 'Git relative file' do
    country = Country.create! name: 'Argentina'
    ActiveGit::Inflector.relative_filename(country).should eq "countries/#{country.id}.json"
  end

  it 'Model from filename' do
    ActiveGit::Inflector.model("#{working_path}/countries/1.json", working_path).should be Country
  end

  it 'Nested model from filename' do
    ActiveGit::Inflector.model("#{working_path}/crm/customers/1.json", working_path).should be Crm::Customer
  end

  it 'Model id' do
    ActiveGit::Inflector.model_id("#{working_path}/crm/customers/1.json").should eq '1'
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_git-0.0.10 spec/inflector_spec.rb
active_git-0.0.9 spec/inflector_spec.rb