looky-lu 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +1 -0
- data/lib/app/models/State.rb +11 -0
- data/lib/data/lu/states.rb +61 -0
- data/lib/db/migrations/create_states.rb.erb +10 -0
- data/lib/generators/lookylu/base_generator.rb +28 -0
- data/lib/generators/lookylu/state_data_generator.rb +37 -0
- data/lib/generators/lookylu/state_generator.rb +43 -0
- data/lib/generators/lookylu/templates/states_migration.erb +10 -0
- data/lib/generators/lookylu/templates/states_model.erb +11 -0
- data/lib/looky-lu.rb +8 -0
- data/lib/looky-lu/engine.rb +6 -0
- data/lib/looky-lu/version.rb +3 -0
- data/looky-lu.gemspec +34 -0
- data/spec/generators/base_generator_spec.rb +32 -0
- data/spec/generators/state_data_generator_spec.rb +55 -0
- data/spec/generators/state_generator_spec.rb +53 -0
- data/spec/models/state_spec.rb +23 -0
- data/spec/spec_helper.rb +55 -0
- data/spec/support/database.yml +3 -0
- data/spec/support/schema.rb +15 -0
- metadata +246 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OTcyZjU5ZDgyZWQ0MjYxMmYzMDI3YjgxNTk2ZTRjNWY3ZDE5Mjc4Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjgyZjIwZDFiMTliNWJmNjNhMDgxNmFmMGNlNTFkOGY5MjliZDg2Mg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjExYzczOTRhOTE2MjA4MmUzNmY5MTJkMDQyYzA5NGFjMWI5MDVhZTJmM2Y5
|
10
|
+
NTQzZmE2ZjAxYzgzMDU2ZWY4ZTAxMTQ1YTczYmQ3NTE4ZThiNzhjZjA4ZmIw
|
11
|
+
MzdiODY1ZWUyYjFlZmQwNWUyYWViMDMxNzZlZTY1N2MyN2MyZmE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjE3MWIwNjFmNDZmNDBhYjdlNWFmZGYyYzc4MjI5M2UwYzc5NzNiNjk3ZjEx
|
14
|
+
NTI0MDFjM2NhOTFhMmU0Y2ZlNTJmODhlYWFmMWNjNDVkODJmZmRkMjkyZDJm
|
15
|
+
NTFkY2M3OWQwZmUxNjYxYmFkMThiOTc1ZTA0Zjg4NjYxOTFmYjk=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Agape Red
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/agapered/looky-lu.png?branch=master)](https://travis-ci.org/agapered/looky-lu)
|
2
|
+
[![Coverage Status](https://coveralls.io/repos/agapered/looky-lu/badge.png?branch=master)](https://coveralls.io/r/agapered/looky-lu?branch=master)
|
3
|
+
|
4
|
+
|
5
|
+
## What is it? ##
|
6
|
+
|
7
|
+
looky-lu will generate standard look up data abilities for your rails application
|
8
|
+
|
9
|
+
## What is it for? ##
|
10
|
+
|
11
|
+
Recently we went through the pain of having to create a look up table for the different states in the United States.
|
12
|
+
|
13
|
+
This gem will allow you to easily add that kind of data to your project
|
14
|
+
|
15
|
+
## How to use it ##
|
16
|
+
|
17
|
+
To create and populate a State model object
|
18
|
+
|
19
|
+
```
|
20
|
+
rails g lookylu:state
|
21
|
+
rake db:migrate
|
22
|
+
rails g lookylu:state_data State
|
23
|
+
```
|
24
|
+
|
25
|
+
## Additional Options ##
|
26
|
+
|
27
|
+
```
|
28
|
+
rails g lookylu:state -h
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
## Who are you? ##
|
33
|
+
|
34
|
+
We are [Agape Red](https://twitter.com/agape_red). [Check us out](http://agapered.com/)
|
35
|
+
|
36
|
+
## I'm a dev, I can help ##
|
37
|
+
|
38
|
+
Awesome! Thanks! Here are the steps I ask:
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Make sure the tests pass (`bundle exec rspec`)
|
44
|
+
5. Coverage not 100%? Sounds like a problem
|
45
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
7. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module LookyLu
|
2
|
+
class States
|
3
|
+
|
4
|
+
def self.united_states
|
5
|
+
[
|
6
|
+
{name: 'Alabama', abbreviation: 'AL'},
|
7
|
+
{name: 'Alaska', abbreviation: 'AK'},
|
8
|
+
{name: 'Arizona', abbreviation: 'AZ'},
|
9
|
+
{name: 'Arkansas', abbreviation: 'AR'},
|
10
|
+
{name: 'California', abbreviation: 'CA'},
|
11
|
+
{name: 'Colorado', abbreviation: 'CO'},
|
12
|
+
{name: 'Connecticut', abbreviation: 'CT'},
|
13
|
+
{name: 'Delaware', abbreviation: 'DE'},
|
14
|
+
{name: 'District of Columbia', abbreviation: 'DC'},
|
15
|
+
{name: 'Florida', abbreviation: 'FL'},
|
16
|
+
{name: 'Georgia', abbreviation: 'GA'},
|
17
|
+
{name: 'Hawaii', abbreviation: 'HI'},
|
18
|
+
{name: 'Idaho', abbreviation: 'ID'},
|
19
|
+
{name: 'Illinois', abbreviation: 'IL'},
|
20
|
+
{name: 'Indiana', abbreviation: 'IN'},
|
21
|
+
{name: 'Iowa', abbreviation: 'IA'},
|
22
|
+
{name: 'Kansas', abbreviation: 'KS'},
|
23
|
+
{name: 'Kentucky', abbreviation: 'KY'},
|
24
|
+
{name: 'Louisiana', abbreviation: 'LA'},
|
25
|
+
{name: 'Maine', abbreviation: 'ME'},
|
26
|
+
{name: 'Maryland', abbreviation: 'MD'},
|
27
|
+
{name: 'Massachusetts', abbreviation: 'MA'},
|
28
|
+
{name: 'Michigan', abbreviation: 'MI'},
|
29
|
+
{name: 'Minnesota', abbreviation: 'MN'},
|
30
|
+
{name: 'Mississippi', abbreviation: 'MS'},
|
31
|
+
{name: 'Missouri', abbreviation: 'MO'},
|
32
|
+
{name: 'Montana', abbreviation: 'MT'},
|
33
|
+
{name: 'Nebraska', abbreviation: 'NE'},
|
34
|
+
{name: 'Nevada', abbreviation: 'NV'},
|
35
|
+
{name: 'New Hampshire', abbreviation: 'NH'},
|
36
|
+
{name: 'New Jersey', abbreviation: 'NJ'},
|
37
|
+
{name: 'New Mexico', abbreviation: 'NM'},
|
38
|
+
{name: 'New York', abbreviation: 'NY'},
|
39
|
+
{name: 'North Carolina', abbreviation: 'NC'},
|
40
|
+
{name: 'North Dakota', abbreviation: 'ND'},
|
41
|
+
{name: 'Ohio', abbreviation: 'OH'},
|
42
|
+
{name: 'Oklahoma', abbreviation: 'OK'},
|
43
|
+
{name: 'Oregon', abbreviation: 'OR'},
|
44
|
+
{name: 'Pennsylvania', abbreviation: 'PA'},
|
45
|
+
{name: 'Rhode Island', abbreviation: 'RI'},
|
46
|
+
{name: 'South Carolina', abbreviation: 'SC'},
|
47
|
+
{name: 'South Dakota', abbreviation: 'SD'},
|
48
|
+
{name: 'Tennessee', abbreviation: 'TN'},
|
49
|
+
{name: 'Texas', abbreviation: 'TX'},
|
50
|
+
{name: 'Utah', abbreviation: 'UT'},
|
51
|
+
{name: 'Vermont', abbreviation: 'VT'},
|
52
|
+
{name: 'Virginia', abbreviation: 'VA'},
|
53
|
+
{name: 'Washington', abbreviation: 'WA'},
|
54
|
+
{name: 'West Virginia', abbreviation: 'WV'},
|
55
|
+
{name: 'Wisconsin', abbreviation: 'WI'},
|
56
|
+
{name: 'Wyoming', abbreviation: 'WY'}
|
57
|
+
]
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
include ActionView::Helpers::TextHelper
|
2
|
+
|
3
|
+
module Lookylu
|
4
|
+
module Generators
|
5
|
+
class BaseGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
argument :object_name, type: :string, default: 'state'
|
8
|
+
|
9
|
+
def file_name
|
10
|
+
object_name.underscore
|
11
|
+
end
|
12
|
+
|
13
|
+
def model_name
|
14
|
+
file_name.camelize
|
15
|
+
end
|
16
|
+
|
17
|
+
def plural_name
|
18
|
+
file_name.pluralize
|
19
|
+
end
|
20
|
+
|
21
|
+
def plural_model_name
|
22
|
+
model_name.pluralize
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'data/lu/states'
|
2
|
+
require 'generators/lookylu/base_generator'
|
3
|
+
|
4
|
+
module Lookylu
|
5
|
+
module Generators
|
6
|
+
class StateDataGenerator < Lookylu::Generators::BaseGenerator
|
7
|
+
|
8
|
+
def populate_data
|
9
|
+
connect_to_db
|
10
|
+
unless ActiveRecord::Base.connection.table_exists? plural_name
|
11
|
+
raise "Table #{plural_name} does not exist. Please build the needed migration and migrate your database"
|
12
|
+
end
|
13
|
+
begin
|
14
|
+
class_object = eval(object_name)
|
15
|
+
LookyLu::States.united_states.each do |data|
|
16
|
+
class_object.where(data).first_or_create
|
17
|
+
end
|
18
|
+
puts "There are now #{pluralize(class_object.count, model_name)}"
|
19
|
+
rescue => e
|
20
|
+
raise "Could not find object for #{model_name}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def connect_to_db
|
28
|
+
ActiveRecord::Base.establish_connection db_config
|
29
|
+
end
|
30
|
+
|
31
|
+
def db_config
|
32
|
+
Rails.configuration.database_configuration[::Rails.env]
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'generators/lookylu/base_generator'
|
2
|
+
|
3
|
+
module Lookylu
|
4
|
+
module Generators
|
5
|
+
class StateGenerator < Lookylu::Generators::BaseGenerator
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
desc 'Build the state LU items'
|
9
|
+
|
10
|
+
class_option :model, :type => :boolean, :default => true, :desc => "Generate a default model object."
|
11
|
+
|
12
|
+
|
13
|
+
def generate_migration
|
14
|
+
if Dir.glob(migration_location('*')).empty?
|
15
|
+
template "states_migration.erb", migration_location(next_migration_number)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def generate_model
|
20
|
+
if options.model
|
21
|
+
if Dir.glob(model_location).empty?
|
22
|
+
template 'states_model.erb', model_location
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def next_migration_number
|
30
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
31
|
+
end
|
32
|
+
|
33
|
+
def migration_location version
|
34
|
+
"db/migrate/#{version}_lookylu_create_#{plural_name}.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
def model_location
|
38
|
+
"app/models/#{model_name}.rb"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= model_name %> < ActiveRecord::Base
|
2
|
+
|
3
|
+
attr_accessible :name, :abbreviation
|
4
|
+
|
5
|
+
validates :name, uniqueness: {scope: :abbreviation}
|
6
|
+
|
7
|
+
scope :for_abbreviation, ->(abbrev){where(abbreviation: abbrev)}
|
8
|
+
|
9
|
+
scope :for_name, ->(name){where(name: name)}
|
10
|
+
|
11
|
+
end
|
data/lib/looky-lu.rb
ADDED
data/looky-lu.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'looky-lu/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "looky-lu"
|
8
|
+
spec.version = LookyLu::VERSION
|
9
|
+
spec.authors = ["David Hopp"]
|
10
|
+
spec.email = ["david.hopp@agapered.com"]
|
11
|
+
spec.description = "looky-lu will generate standard look up data abilities for your rails application"
|
12
|
+
spec.summary = ""
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rails'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
spec.add_development_dependency 'simplecov'
|
26
|
+
spec.add_development_dependency 'simplecov-rcov'
|
27
|
+
spec.add_development_dependency "activerecord", "~> 3.0"
|
28
|
+
spec.add_development_dependency "sqlite3-ruby"
|
29
|
+
spec.add_development_dependency 'database_cleaner'
|
30
|
+
spec.add_development_dependency 'coveralls'
|
31
|
+
|
32
|
+
spec.add_dependency 'rails'
|
33
|
+
spec.add_dependency 'activerecord'
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/lookylu/base_generator'
|
3
|
+
require 'data/lu/states'
|
4
|
+
require 'app/models/State'
|
5
|
+
|
6
|
+
describe Lookylu::Generators::BaseGenerator do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@gen = Lookylu::Generators::BaseGenerator.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should build file name' do
|
13
|
+
@gen.object_name = 'ObjectName'
|
14
|
+
@gen.file_name.should == 'object_name'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should build model name' do
|
18
|
+
@gen.object_name = 'object_name'
|
19
|
+
@gen.model_name.should == 'ObjectName'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should build plural name' do
|
23
|
+
@gen.object_name = 'ObjectName'
|
24
|
+
@gen.plural_name.should == 'object_names'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should build plural model name' do
|
28
|
+
@gen.object_name = 'object_name'
|
29
|
+
@gen.plural_model_name.should == 'ObjectNames'
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/lookylu/state_data_generator'
|
3
|
+
require 'data/lu/states'
|
4
|
+
require 'app/models/State'
|
5
|
+
|
6
|
+
describe Lookylu::Generators::StateDataGenerator do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@gen = Lookylu::Generators::StateDataGenerator.new
|
10
|
+
@gen.object_name = 'State'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should pull the database configs' do
|
14
|
+
Rails.should_receive(:configuration).and_return(double('configuration', database_configuration: {}))
|
15
|
+
@gen.send(:db_config)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should connect to the database' do
|
19
|
+
pending 'How to test this?'
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'populate data' do
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
Lookylu::Generators::StateDataGenerator.any_instance.stub(:db_config).and_return(database_config)
|
26
|
+
end
|
27
|
+
|
28
|
+
after(:each) do
|
29
|
+
load_db
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should fail if table is not there' do
|
33
|
+
@gen.send(:connect_to_db)
|
34
|
+
ActiveRecord::Base.connection.drop_table @gen.plural_name
|
35
|
+
|
36
|
+
expect {@gen.populate_data}.
|
37
|
+
to raise_error "Table #{@gen.plural_name} does not exist. Please build the needed migration and migrate your database"
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should add object data' do
|
41
|
+
Object.any_instance.should_receive(:puts).with("There are now #{@gen.pluralize(LookyLu::States.united_states.count, @gen.plural_model_name)}")
|
42
|
+
|
43
|
+
@gen.populate_data
|
44
|
+
State.count.should == LookyLu::States.united_states.count
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should not fail if object does not exist' do
|
48
|
+
@gen.object_name = 'no_model'
|
49
|
+
expect {@gen.populate_data}.
|
50
|
+
to raise_error "Could not find object for #{@gen.model_name}"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'generators/lookylu/state_generator'
|
3
|
+
require 'data/lu/states'
|
4
|
+
require 'app/models/State'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
|
8
|
+
describe Lookylu::Generators::StateGenerator do
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
@gen = Lookylu::Generators::StateGenerator.new
|
12
|
+
@gen.object_name = 'ObjectName'
|
13
|
+
end
|
14
|
+
#.send(:method_name, args)
|
15
|
+
|
16
|
+
it 'should get model location' do
|
17
|
+
@gen.send(:model_location).should == "app/models/ObjectName.rb"
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should get migration_location' do
|
21
|
+
version = '12345'
|
22
|
+
@gen.send(:migration_location, version).should == "db/migrate/#{version}_lookylu_create_object_names.rb"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should build next migration number' do
|
26
|
+
time = Time.new('2013-05-10 19:58:31 +0000')
|
27
|
+
Time.should_receive(:now).and_return(time)
|
28
|
+
@gen.send(:next_migration_number).should == 20130101000000
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'file create' do
|
32
|
+
|
33
|
+
after(:each) do
|
34
|
+
FileUtils.rm_rf 'spec/testing'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should generate model file' do
|
38
|
+
@gen.stub(:model_location).and_return("spec/testing/#{@gen.model_name}.rb")
|
39
|
+
@gen.generate_model
|
40
|
+
File.exists?("spec/testing/#{@gen.model_name}.rb").should be true
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should generate the migration file' do
|
44
|
+
@gen.stub(:migration_location).and_return("spec/testing/#{20130101000000}_lookylu_create_#{@gen.plural_name}.rb")
|
45
|
+
@gen.generate_migration
|
46
|
+
File.exists?("spec/testing/#{20130101000000}_lookylu_create_#{@gen.plural_name}.rb").should be true
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'data/lu/states'
|
3
|
+
require 'app/models/State'
|
4
|
+
|
5
|
+
describe State do
|
6
|
+
|
7
|
+
describe 'scopes' do
|
8
|
+
before(:each) do
|
9
|
+
LookyLu::States.united_states.take(10).each do |s|
|
10
|
+
State.where(s).first_or_create
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should find by abbreviation' do
|
15
|
+
State.for_abbreviation('AL').count.should == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should find by name' do
|
19
|
+
State.for_name('Alabama').count.should == 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear!('rails')
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter "/spec/"
|
10
|
+
end
|
11
|
+
|
12
|
+
ENV["RAILS_ENV"] = 'test'
|
13
|
+
|
14
|
+
require 'active_record'
|
15
|
+
require 'database_cleaner'
|
16
|
+
require 'rails'
|
17
|
+
require 'rails/all'
|
18
|
+
require 'rails/generators'
|
19
|
+
require "rails/test_help"
|
20
|
+
|
21
|
+
|
22
|
+
ActiveRecord::Base.establish_connection(YAML.load_file("spec/support/database.yml")[ENV['RAILS_ENV']])
|
23
|
+
load 'spec/support/schema.rb'
|
24
|
+
|
25
|
+
|
26
|
+
if ENV['RCOV'] == 'true'
|
27
|
+
require 'simplecov-rcov'
|
28
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec.configure do |config|
|
32
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
33
|
+
config.run_all_when_everything_filtered = true
|
34
|
+
config.filter_run :focus
|
35
|
+
|
36
|
+
config.before(:suite) do
|
37
|
+
DatabaseCleaner.strategy = :transaction
|
38
|
+
DatabaseCleaner.clean_with(:truncation)
|
39
|
+
DatabaseCleaner.clean
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def database_config
|
44
|
+
YAML.load_file("spec/support/database.yml")[ENV['RAILS_ENV']]
|
45
|
+
end
|
46
|
+
|
47
|
+
def connect_to_db
|
48
|
+
ActiveRecord::Base.establish_connection database_config
|
49
|
+
end
|
50
|
+
|
51
|
+
def load_db
|
52
|
+
load 'spec/support/schema.rb'
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
self.verbose = false
|
3
|
+
|
4
|
+
create_table "states", :force => true do |t|
|
5
|
+
t.string "name"
|
6
|
+
t.string "abbreviation"
|
7
|
+
t.datetime "created_at", :null => false
|
8
|
+
t.datetime "updated_at", :null => false
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table 'no_models', :force => true do |t|
|
12
|
+
t.datetime "created_at", null: false
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,246 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: looky-lu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Hopp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov-rcov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activerecord
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3-ruby
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: database_cleaner
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: coveralls
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rails
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: activerecord
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: looky-lu will generate standard look up data abilities for your rails
|
182
|
+
application
|
183
|
+
email:
|
184
|
+
- david.hopp@agapered.com
|
185
|
+
executables: []
|
186
|
+
extensions: []
|
187
|
+
extra_rdoc_files: []
|
188
|
+
files:
|
189
|
+
- .gitignore
|
190
|
+
- .rspec
|
191
|
+
- .travis.yml
|
192
|
+
- Gemfile
|
193
|
+
- LICENSE.txt
|
194
|
+
- README.md
|
195
|
+
- Rakefile
|
196
|
+
- lib/app/models/State.rb
|
197
|
+
- lib/data/lu/states.rb
|
198
|
+
- lib/db/migrations/create_states.rb.erb
|
199
|
+
- lib/generators/lookylu/base_generator.rb
|
200
|
+
- lib/generators/lookylu/state_data_generator.rb
|
201
|
+
- lib/generators/lookylu/state_generator.rb
|
202
|
+
- lib/generators/lookylu/templates/states_migration.erb
|
203
|
+
- lib/generators/lookylu/templates/states_model.erb
|
204
|
+
- lib/looky-lu.rb
|
205
|
+
- lib/looky-lu/engine.rb
|
206
|
+
- lib/looky-lu/version.rb
|
207
|
+
- looky-lu.gemspec
|
208
|
+
- spec/generators/base_generator_spec.rb
|
209
|
+
- spec/generators/state_data_generator_spec.rb
|
210
|
+
- spec/generators/state_generator_spec.rb
|
211
|
+
- spec/models/state_spec.rb
|
212
|
+
- spec/spec_helper.rb
|
213
|
+
- spec/support/database.yml
|
214
|
+
- spec/support/schema.rb
|
215
|
+
homepage: ''
|
216
|
+
licenses:
|
217
|
+
- MIT
|
218
|
+
metadata: {}
|
219
|
+
post_install_message:
|
220
|
+
rdoc_options: []
|
221
|
+
require_paths:
|
222
|
+
- lib
|
223
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - ! '>='
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: '0'
|
228
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
|
+
requirements:
|
230
|
+
- - ! '>='
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: '0'
|
233
|
+
requirements: []
|
234
|
+
rubyforge_project:
|
235
|
+
rubygems_version: 2.0.3
|
236
|
+
signing_key:
|
237
|
+
specification_version: 4
|
238
|
+
summary: ''
|
239
|
+
test_files:
|
240
|
+
- spec/generators/base_generator_spec.rb
|
241
|
+
- spec/generators/state_data_generator_spec.rb
|
242
|
+
- spec/generators/state_generator_spec.rb
|
243
|
+
- spec/models/state_spec.rb
|
244
|
+
- spec/spec_helper.rb
|
245
|
+
- spec/support/database.yml
|
246
|
+
- spec/support/schema.rb
|