data_display 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 26da40d9b4eee470047cc1f55f666aa071365285
4
+ data.tar.gz: 5c022f5f34854055622eadbf688607af7acbc8d1
5
+ SHA512:
6
+ metadata.gz: 5476108469e2894fd35a87ee99ca5bb5d2d8f65f4e3400000aa1205f5fa947fb89bfd7f2bcf3a86270b901801c814b56c21e8086e18af5173c080fff3be449ff
7
+ data.tar.gz: 16bc65050574a4911fa7343d1fd50725d14d94a285e19bfbe95194723df6268f83987df8ca10f17952badc3a4eb616ac8ddcb1897143db8e027151c00091c811
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ .DS_Store
2
+ .rvmrc
3
+ coverage
4
+ coverage.data
5
+ pkg
6
+ *~
7
+ *.swp
8
+ *watchr.rb
9
+ log/*
10
+ .rvmrc
11
+ .ruby-version
12
+ .bundle
13
+ Gemfile.lock
14
+ .yardoc
15
+ doc/
16
+ tmp
17
+ gemfiles/*.lock
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise 'rails-42' do
2
+ gem 'rails', '4.2.0'
3
+ end
4
+
5
+ appraise 'rails-41' do
6
+ gem 'rails', '4.1.0'
7
+ end
8
+
9
+ appraise 'rails-4' do
10
+ # gem 'rails', '4.0.0'
11
+ end
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 ramón soto
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,120 @@
1
+ # DataDisplay
2
+
3
+ A better way to show attributes
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'data_display'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Run the generator:
18
+
19
+ $ rails generate data_display:install
20
+
21
+ ## Usage
22
+
23
+ At first, you need to add `acts_as_displayable` in your models:
24
+
25
+ ```ruby
26
+ # For all attributes
27
+ class Product < ActiveRecord::Base
28
+ acts_as_displayable
29
+ end
30
+ ```
31
+ Or:
32
+
33
+ ```ruby
34
+ # For some attributes
35
+ class Product < ActiveRecord::Base
36
+ acts_as_displayable :name, :description, :price, :active, :published_at
37
+ end
38
+ ```
39
+
40
+ This generates the display methods to model attributes (eg [attribute] _display)
41
+
42
+ ```ruby
43
+ product = Product.new published_at: DateTime.now,
44
+ active: true,
45
+ title: nil,
46
+ price: 999990,
47
+ description: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus"
48
+
49
+ # Date, DateTime or Time
50
+ product.published_at_display
51
+ => "December 10, 2012 11:58"
52
+
53
+ product.published_at_display :short
54
+ => "10 Dec 11:58"
55
+
56
+ # YesClass or FalseClass
57
+ product.active_display
58
+ => "Yes"
59
+
60
+ # String
61
+ product.content_display
62
+ => "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ..."
63
+
64
+ product.content_display(:short)
65
+ => "Lorem ipsum dolor sit amet, consectetuer adipiscing elit...."
66
+
67
+ # NilClass
68
+ product.title_display
69
+ => "(empty)"
70
+
71
+ product.title_display(:short)
72
+ => "-"
73
+
74
+ # Fixnum or Float
75
+ product.price_display
76
+ => "9,999,990"
77
+
78
+ product.price_display(:currency)
79
+ => "$9,999,990.00"
80
+
81
+ ```
82
+
83
+ If you need to edit the format for dates or text, you can see the config/locales/data_display.en.yml (generated with `rails g data_display:install`)
84
+
85
+ ```yaml
86
+ en:
87
+ data_display:
88
+ true_class:
89
+ formats:
90
+ long: 'Yes'
91
+ short: 'Yes'
92
+ false_class:
93
+ formats:
94
+ long: 'No'
95
+ short: 'No'
96
+ nil_class:
97
+ formats:
98
+ long: '(empty)'
99
+ short: '-'
100
+ time:
101
+ formats:
102
+ long: ! '%B %d, %Y %H:%M'
103
+ short: ! '%d %b %H:%M'
104
+ date_time:
105
+ formats:
106
+ long: ! '%B %d, %Y %H:%M'
107
+ short: ! '%d %b %H:%M'
108
+ date:
109
+ formats:
110
+ long: ! '%B %d, %Y'
111
+ short: ! '%b %d'
112
+ ```
113
+
114
+ ## Contributing
115
+
116
+ 1. Fork it ( https://github.com/[my-github-username]/data_display/fork )
117
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
118
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
119
+ 4. Push to the branch (`git push origin my-new-feature`)
120
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'appraisal'
4
+
5
+ Rake::TestTask.new(:spec) do |s|
6
+ s.libs << 'spec'
7
+ s.pattern = 'spec/**/*_spec.rb'
8
+ end
9
+
10
+ desc 'Default: run unit specs.'
11
+ if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
12
+ task default: :appraisal
13
+ else
14
+ task default: :spec
15
+ end
16
+
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'data_display/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'data_display'
8
+ spec.version = DataDisplay::VERSION
9
+ spec.authors = ['ramón soto']
10
+ spec.email = ['ramon.soto@clouw.com']
11
+ spec.summary = %q{show attributes better}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+ spec.description = %q{show attributes better}
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_runtime_dependency 'rails', '~> 4.0'
22
+
23
+ spec.add_development_dependency 'appraisal'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'sqlite3'
26
+ spec.add_development_dependency 'mocha', '>= 1.1.0'
27
+ spec.add_development_dependency 'factory_girl', '~> 4.0'
28
+ spec.add_development_dependency 'minitest', '>= 4.0'
29
+
30
+ spec.required_ruby_version = '>= 1.9'
31
+ end
@@ -0,0 +1,5 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.1.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.2.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,114 @@
1
+ module DataDisplay
2
+ module Actions
3
+ class Display
4
+ include ActiveSupport::Inflector
5
+ include ActionView::Helpers::TextHelper
6
+ include ActionView::Helpers::NumberHelper
7
+
8
+ attr_reader :raw_value, :format
9
+
10
+ def initialize(raw_value, format)
11
+ @raw_value = raw_value
12
+ @format = format && format.to_sym
13
+ end
14
+
15
+ def value
16
+ respond_to?(method_name, true) ? send(method_name) : raw_value
17
+ end
18
+
19
+ private
20
+ def true_class_display
21
+ translate
22
+ end
23
+
24
+ def false_class_display
25
+ translate
26
+ end
27
+
28
+ def fixnum_display
29
+ number_display
30
+ end
31
+
32
+ def float_display
33
+ number_display
34
+ end
35
+
36
+ def number_display
37
+ case fixnum_format
38
+ when :delimiter
39
+ number_with_delimiter raw_value
40
+ when :currency
41
+ number_to_currency raw_value
42
+ end
43
+ end
44
+
45
+ def nil_class_display
46
+ translate
47
+ end
48
+
49
+ def date_display
50
+ localize
51
+ end
52
+
53
+ def time_display
54
+ localize
55
+ end
56
+
57
+ def date_time_display
58
+ localize
59
+ end
60
+
61
+ def string_display
62
+ truncate(raw_value, length: string_length)
63
+ end
64
+
65
+ def method_name
66
+ "#{class_name}_display"
67
+ end
68
+
69
+ def translate
70
+ I18n.translate "data_display.#{class_name}.formats.#{locale_format}"
71
+ end
72
+
73
+ def localize
74
+ I18n.localize raw_value, format: localize_format, scope: :data_display
75
+ end
76
+
77
+ def class_name
78
+ raw_value.class.name.underscore
79
+ end
80
+
81
+ def locale_format
82
+ format || :long
83
+ end
84
+
85
+ def localize_format
86
+ format || :long
87
+ end
88
+
89
+ def string_format
90
+ format || :long
91
+ end
92
+
93
+ def fixnum_format
94
+ format || :delimiter
95
+ end
96
+
97
+ def string_length
98
+ case string_format
99
+ when :short
100
+ 60
101
+ when :long
102
+ 180
103
+ else
104
+ raw_value.length
105
+ end
106
+ end
107
+ end
108
+
109
+ def __data_display__(value, format = nil)
110
+ display = Display.new value, format
111
+ display.value
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,25 @@
1
+ module DataDisplay
2
+ module Helpers
3
+ include DataDisplay::Actions
4
+
5
+ alias_method :data_display, :__data_display__
6
+ alias_method :dd, :__data_display__
7
+ public :data_display, :dd
8
+
9
+ LARGE_ACTIONS = [:edit, :new, :show, :delete, :update, :create]
10
+ SHORT_ACTIONS = [:index]
11
+ ACTIONS = LARGE_ACTIONS + SHORT_ACTIONS
12
+
13
+ def display_short?
14
+ ACTIONS.include?(current_action) and SHORT_ACTIONS.include?(current_action) or params_id?
15
+ end
16
+
17
+ def params_id?
18
+ params[:id].present?
19
+ end
20
+
21
+ def current_action
22
+ params[:action]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module DataDisplay
2
+ module ModelAdditions
3
+ include DataDisplay::Actions
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def acts_as_displayable(*args)
8
+ args = columns.map(&:name) if args.blank?
9
+ args.each do |attribute|
10
+ define_method "#{attribute}_display" do
11
+ __data_display__(send(attribute))
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,3 @@
1
+ module DataDisplay
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'active_support'
2
+ require 'action_view'
3
+ require 'data_display/actions'
4
+ require 'data_display/model_additions'
5
+
6
+ ActiveRecord::Base.send :include, DataDisplay::ModelAdditions if defined? ActiveRecord
7
+
8
+ # Testing
9
+ # Mongoid::Document.send(:include, DataDisplay::ModelAdditions) if defined?(Mongoid) && defined?(Mongoid::Document)
@@ -0,0 +1,21 @@
1
+ require 'rails/generators'
2
+ module DataDisplay
3
+ module Generators
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def generate_ability
8
+ if locale =~ /es$|es-/i
9
+ template "data_display.es.yml", "config/locales/data_display.#{locale}.yml"
10
+ else
11
+ template "data_display.en.yml", "config/locales/data_display.#{locale}.yml"
12
+ end
13
+ end
14
+
15
+ private
16
+ def locale
17
+ I18n.locale
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ <%= locale %>:
2
+ data_display:
3
+ true_class:
4
+ formats:
5
+ long: 'Yes'
6
+ short: 'Yes'
7
+ false_class:
8
+ formats:
9
+ long: 'No'
10
+ short: 'No'
11
+ nil_class:
12
+ formats:
13
+ long: '(empty)'
14
+ short: '-'
15
+ time:
16
+ formats:
17
+ long: ! '%B %d, %Y %H:%M'
18
+ short: ! '%d %b %H:%M'
19
+ date_time:
20
+ formats:
21
+ long: ! '%B %d, %Y %H:%M'
22
+ short: ! '%d %b %H:%M'
23
+ date:
24
+ formats:
25
+ long: ! '%B %d, %Y'
26
+ short: ! '%b %d'
@@ -0,0 +1,26 @@
1
+ <%= locale %>:
2
+ data_display:
3
+ true_class:
4
+ formats:
5
+ long: 'Si'
6
+ short: 'Si'
7
+ false_class:
8
+ formats:
9
+ long: 'No'
10
+ short: 'No'
11
+ nil_class:
12
+ formats:
13
+ long: '(vacío)'
14
+ short: '-'
15
+ time:
16
+ formats:
17
+ long: ! '%d de %B de %Y %H:%M'
18
+ short: ! '%d de %b %H:%M'
19
+ date_time:
20
+ formats:
21
+ long: ! '%d de %B de %Y %H:%M'
22
+ short: ! '%d de %b %H:%M'
23
+ date:
24
+ formats:
25
+ long: ! '%d de %B de %Y'
26
+ short: ! '%d de %b'
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+
3
+ describe DataDisplay::Actions do
4
+
5
+ let(:klass) { Class.new{ include DataDisplay::Actions } }
6
+ let(:actions) { klass.new }
7
+ let(:string) { 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus' }
8
+
9
+ describe '#__data_display__' do
10
+ it 'pass unknown object' do
11
+ object = Object.new
12
+ actions.__data_display__(object).must_equal object
13
+ end
14
+
15
+ it 'pass a true value' do
16
+ actions.__data_display__(true).must_equal 'Yes'
17
+ end
18
+
19
+ it 'pass a false value' do
20
+ actions.__data_display__(false).must_equal 'No'
21
+ end
22
+
23
+ describe 'when format is delimiter (default)' do
24
+ it 'pass fixnum value' do
25
+ fixnum = 25000000
26
+ actions.__data_display__(fixnum).must_equal '25,000,000'
27
+ end
28
+ end
29
+
30
+ describe 'when format is currency' do
31
+ it 'pass fixnum value' do
32
+ fixnum = 25000000
33
+ actions.__data_display__(fixnum, :currency).must_equal '$25,000,000.00'
34
+ end
35
+ end
36
+
37
+ describe 'when format is short' do
38
+ it 'pass a nil value' do
39
+ actions.__data_display__(nil, :short).must_equal '-'
40
+ end
41
+
42
+ it 'pass date value' do
43
+ date = Date.new(2001,2,3)
44
+ actions.__data_display__(date, :short).must_equal 'Feb 03'
45
+ end
46
+
47
+ it 'pass time value' do
48
+ time = Time.new(2002, 10, 31, 2, 2, 2, "+02:00")
49
+ actions.__data_display__(time, :short).must_equal '31 Oct 02:02'
50
+ end
51
+
52
+ it 'pass date_time value' do
53
+ date_time = DateTime.new(2003, 10, 31, 2, 2, 2, "+02:00")
54
+ actions.__data_display__(date_time, :short).must_equal '31 Oct 02:02'
55
+ end
56
+
57
+ it 'pass string value' do
58
+ truncate_string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit....'
59
+ actions.__data_display__(string, :short).must_equal truncate_string
60
+ end
61
+ end
62
+
63
+ describe 'when format is long (default)' do
64
+ it 'pass a nil value' do
65
+ actions.__data_display__(nil).must_equal '(empty)'
66
+ end
67
+
68
+ it 'pass date value' do
69
+ date = Date.new(2004,2,3)
70
+ actions.__data_display__(date).must_equal 'February 03, 2004'
71
+ end
72
+
73
+ it 'pass time value' do
74
+ time = Time.new(2007, 10, 31, 2, 2, 2, "+02:00")
75
+ actions.__data_display__(time).must_equal 'October 31, 2007 02:02'
76
+ end
77
+
78
+ it 'pass date_time value' do
79
+ date_time = DateTime.new(2009, 10, 31, 2, 2, 2, "+02:00")
80
+ actions.__data_display__(date_time).must_equal 'October 31, 2009 02:02'
81
+ end
82
+
83
+ it 'pass string value' do
84
+ truncate_string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ...'
85
+ actions.__data_display__(string).must_equal truncate_string
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,26 @@
1
+ en:
2
+ data_display:
3
+ true_class:
4
+ formats:
5
+ long: 'Yes'
6
+ short: 'Yes'
7
+ false_class:
8
+ formats:
9
+ long: 'No'
10
+ short: 'No'
11
+ nil_class:
12
+ formats:
13
+ long: '(empty)'
14
+ short: '-'
15
+ time:
16
+ formats:
17
+ long: ! '%B %d, %Y %H:%M'
18
+ short: ! '%d %b %H:%M'
19
+ date_time:
20
+ formats:
21
+ long: ! '%B %d, %Y %H:%M'
22
+ short: ! '%d %b %H:%M'
23
+ date:
24
+ formats:
25
+ long: ! '%B %d, %Y'
26
+ short: ! '%b %d'
@@ -0,0 +1,16 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ name 'kakashi'
4
+ email 'kakashi@konoha.jp'
5
+ password '000000'
6
+ birthday Date.new(1988, 9, 15)
7
+ admin false
8
+ end
9
+ end
10
+
11
+ FactoryGirl.define do
12
+ factory :article do
13
+ title 'Third Shinobi World War'
14
+ content 'The Third Shinobi World War (Daisanji Ninkai Taisen) is the third of the four shinobi wars that involved the majority of the shinobi villages. It takes place more than ten years prior to the beginning of the series and has been rarely shown in the series outside the Kakashi Gaiden. Because of a decline in national power, the reign of the Five Great Countries was crumbling. Along their borders, skirmishes with smaller nations broke out all the time. The prolonged war gradually spread its fires far and wide, until at last it developed into the Third Shinobi World War. This war turned into an unprecedented war of attrition, tormenting all nations with a shortage of war potential. Not even excluding a great power like Konoha, very young children, some of whom were barely out of the Academy were thrown unto the battlefield, eventually losing their short lives during the war'
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ require 'bundler/setup'
3
+ require 'rails/all'
4
+ require 'data_display'
5
+ require 'rails/generators/test_case'
6
+ require 'generators/data_display/install/install_generator'
7
+ require 'factory_girl'
8
+
9
+ # Database
10
+ ActiveRecord::Base.establish_connection(
11
+ adapter: "sqlite3",
12
+ database: ":memory:"
13
+ )
14
+ ActiveRecord::Migration.verbose = false
15
+
16
+ # Locale
17
+ I18n.load_path << "#{File.dirname(__FILE__)}/data_display.en.yml"
18
+
19
+ # Schema
20
+ load "schema.rb"
21
+
22
+ # Models
23
+ load 'models.rb'
24
+
25
+ # Factories
26
+ FactoryGirl.definition_file_paths = ["#{File.dirname(__FILE__)}/factories"]
27
+ FactoryGirl.find_definitions
@@ -0,0 +1,7 @@
1
+ class Article < ActiveRecord::Base
2
+ acts_as_displayable
3
+ end
4
+
5
+ class User < ActiveRecord::Base
6
+ acts_as_displayable :birthday, :admin, :created_at
7
+ end
@@ -0,0 +1,18 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table "users", force: true do |t|
3
+ t.string "name"
4
+ t.string "email"
5
+ t.string "password"
6
+ t.date "birthday"
7
+ t.boolean "admin"
8
+ t.datetime "created_at", null: false
9
+ t.datetime "updated_at", null: false
10
+ end
11
+
12
+ create_table "articles", force: true do |t|
13
+ t.string "title"
14
+ t.text "content"
15
+ t.datetime "created_at", null: false
16
+ t.datetime "updated_at", null: false
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ class DataDisplayGeneratorSpec < Rails::Generators::TestCase
2
+ tests DataDisplay::Generators::InstallGenerator
3
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
4
+ setup :prepare_destination
5
+ teardown { rm_rf(destination_root) }
6
+
7
+ test "Assert all files are properly created" do
8
+ %w(es es-CL en es-IN de).each do |locale|
9
+ assert_locale_file locale
10
+ end
11
+ end
12
+
13
+ private
14
+ def assert_locale_file(locale, delete = true)
15
+ I18n.stubs(:locale).returns(locale)
16
+ run_generator
17
+ assert_file "config/locales/data_display.#{locale}.yml" do |locale_file|
18
+ assert_match(/#{locale}/, locale_file)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe DataDisplay::ModelAdditions do
4
+ let(:user) { create(:user) }
5
+ let(:article){ create(:article) }
6
+
7
+ describe 'when model have some displayable attributes' do
8
+ it { user.methods.include?(:admin_display).must_equal true }
9
+ it { user.methods.include?(:birthday_display).must_equal true }
10
+ it { user.methods.include?(:created_at_display).must_equal true }
11
+
12
+ it { user.methods.exclude?(:password_display).must_equal true }
13
+ it { user.methods.exclude?(:updated_at_display).must_equal true }
14
+ it { user.methods.exclude?(:name_display).must_equal true }
15
+ it { user.methods.exclude?(:id_display).must_equal true }
16
+ it { user.methods.exclude?(:email_display).must_equal true }
17
+ end
18
+
19
+ describe 'when model have all displayable attributes' do
20
+ it { article.methods.include?(:title_display).must_equal true }
21
+ it { article.methods.include?(:content_display).must_equal true }
22
+
23
+ it { article.methods.include?(:id_display).must_equal true }
24
+ it { article.methods.include?(:created_at_display).must_equal true }
25
+ it { article.methods.include?(:updated_at_display).must_equal true }
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/unit'
3
+ require 'mocha/mini_test'
4
+ require 'dummy/init'
5
+
6
+ class HelperTest < MiniTest::Spec
7
+ include ActiveSupport::Testing::SetupAndTeardown
8
+ include ActionView::TestCase::Behavior
9
+ register_spec_type(/Helper/, self)
10
+ end
11
+
12
+ module MiniTest
13
+ class Spec
14
+ include FactoryGirl::Syntax::Methods
15
+ class << self
16
+ alias_method :context, :describe
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data_display
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ramón soto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
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: rake
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: sqlite3
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: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_girl
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '4.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '4.0'
111
+ description: show attributes better
112
+ email:
113
+ - ramon.soto@clouw.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Appraisals
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - data_display.gemspec
125
+ - gemfiles/rails_4.gemfile
126
+ - gemfiles/rails_41.gemfile
127
+ - gemfiles/rails_42.gemfile
128
+ - lib/data_display.rb
129
+ - lib/data_display/actions.rb
130
+ - lib/data_display/helpers.rb
131
+ - lib/data_display/model_additions.rb
132
+ - lib/data_display/version.rb
133
+ - lib/generators/data_display/install/install_generator.rb
134
+ - lib/generators/data_display/install/templates/data_display.en.yml
135
+ - lib/generators/data_display/install/templates/data_display.es.yml
136
+ - spec/actions_spec.rb
137
+ - spec/dummy/data_display.en.yml
138
+ - spec/dummy/factories.rb
139
+ - spec/dummy/init.rb
140
+ - spec/dummy/models.rb
141
+ - spec/dummy/schema.rb
142
+ - spec/generators/data_display_generator_spec.rb
143
+ - spec/model_additions_spec.rb
144
+ - spec/spec_helper.rb
145
+ homepage: ''
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '1.9'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.4.3
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: show attributes better
169
+ test_files:
170
+ - spec/actions_spec.rb
171
+ - spec/dummy/data_display.en.yml
172
+ - spec/dummy/factories.rb
173
+ - spec/dummy/init.rb
174
+ - spec/dummy/models.rb
175
+ - spec/dummy/schema.rb
176
+ - spec/generators/data_display_generator_spec.rb
177
+ - spec/model_additions_spec.rb
178
+ - spec/spec_helper.rb