Giter Site home page Giter Site logo

baban / flextures Goto Github PK

View Code? Open in Web Editor NEW
22.0 4.0 3.0 307 KB

This plug-in can load and dump test data in databases, loading function is very flexible, dump function is very simple

License: MIT License

Ruby 100.00%
fixtures ruby rails csv csv-export csv-import yaml yaml-export yaml-import

flextures's Introduction

flextures

Ruby 2.3 higher Rails 4.2 higher MIT Licence

Description

This plug-in aim to resolve many problems, durling rails developping about fixtures. Basic commands is simple. Each commands load or dump fixtures.

rake db:flextures:load
rake db:flextures:dump

Major different point is four.

  1. Fixture file prefered CSV to YAML.
  2. Even if, not match column's structure, loading don't stop and auto padding data.
  3. Fixture file name can change, if file name is not equal table name.
  4. Fixture data can translate to use filter, like factory girl.

Table of Contents

Requirements

  • ruby2.3 higher

Usage

How to install

This program is implemented Rails Plug-in. If You want to install this plug-in. Please use bundler.

In Gemfile

gem "flextures"

And execute below commands.

bundle install
bundle exec rails generate flextures:initializer

(Development emnvoriment must be ruby2.1 higer and rails3 higher)

rake command

load command input fixtures file under "spec/fixtures/". (Loading directory can change configuration file)

rake db:flextures:load
rake db:flextures:dump

rake command can set options. For example, this option set dump file name. (Option dump only "users.csv")

rake db:flextures:dump TABLE=users

Other options...

option description
TABLE set table name
MODEL set model name
DIR set directory name
FILE set fixture file name
FORMAT change dump file format(csv or yml)
OPTION other options
T alias TABLE option
D alias DIR option
F alias FIXTURES option

if you change table colum information next comannd regenerate (load fixture and dump) fixtures

rake db:flextures:generate T=users

Other information please see wiki ...

Unit test support

Fixture load function implemented for Unittes Tools (for example, RSpec, Shoulda).

describe ItemShopController do
  flextures :users, :items
end

flexture function can write like a "fixture" function, implemented in RSpec. But, "flexture" function ignore columns change.

Flextures function can change load file name.

describe ItemShopController do
  flextures :items, :users => :users_for_itemshop # load "users_for_itemshop.csv"
end

Other option information Please see wiki ...

Flextures load & dump filter

load filter

In config/flextures.factory.rb

Factory filter translate fixture data and set database.

For example, this code set current time to last_login_date column.

Flextures::Factory.define :users do |f|
  f.last_login_date = DateTime.now
end

This sample, generate name and sex automatically, and other tables data generate

require 'faker'
Flextures::Factory.define :users do |f|
  f.name= Faker::Name.name if !f.name  # gemerate name
  f.sex= [0,1].shuffle.first if !f.sex # generate sex
  # factory filter can generate data, use has_many association
  f.items<< [ Item.new( master_item_id: 1, count: 5 ), Item.new( master_item_id: 2, count: 3 ) ]
end

dump filter

if you need to convert table data into other data format, you use dump filter. (dump filter is same file as load filter)

dump filter has hash arguments, it is formatted colum name key and convert method, proc, lambda value

file is config/flextures.factory.rb

Flextures::DumpFilter.define :users, {
  :encrypted_password => lambda { |v| Base64.encode64(v) }
}

Other options please see wiki ...

Configuration file

In config/initializers/flextures.rb, configuration file can change load and dump directory

Flextures::Configuration.configure do |config|
  # Load and dump directory change "spec/fixtures/" to "test/fixtures/"
  config.load_directory = "test/fixtures/"
  config.dump_directory = "test/fixtures/"
end

Other options please see wiki ...

Contributing

https://github.com/baban/flextures/graphs/contributors

Licence

This software is released under the MIT Licence.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.