puffer 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/Gemfile.lock +45 -41
- data/README.md +2 -5
- data/VERSION +1 -1
- data/app/assets/stylesheets/puffer/application.css +1 -0
- data/app/assets/stylesheets/puffer/puffer_tree.css +65 -0
- data/{lib → app/controllers}/puffer/base.rb +3 -1
- data/app/controllers/puffer/{dashboard.rb → dashboard_base.rb} +1 -1
- data/app/controllers/puffer/dashboard_controller.rb +4 -0
- data/app/controllers/puffer/{sessions.rb → sessions_base.rb} +2 -2
- data/{lib/generators/puffer/install/templates → app/controllers/puffer}/sessions_controller.rb +2 -1
- data/app/controllers/puffer/tree_base.rb +50 -0
- data/app/helpers/puffer_helper.rb +2 -6
- data/app/helpers/puffer_tree_helper.rb +15 -0
- data/app/views/layouts/puffer.html.erb +54 -71
- data/app/views/layouts/puffer_base.html.erb +28 -0
- data/app/views/layouts/puffer_dashboard.html.erb +15 -32
- data/app/views/layouts/puffer_sessions.html.erb +7 -24
- data/app/views/puffer/base/index.html.erb +0 -1
- data/app/views/puffer/{dashboard → dashboard_base}/index.html.erb +0 -0
- data/app/views/puffer/{sessions → sessions_base}/new.html.erb +0 -0
- data/app/views/puffer/tree_base/_record.html.erb +27 -0
- data/app/views/puffer/tree_base/toggle.js.erb +6 -0
- data/app/views/puffer/tree_base/tree.html.erb +9 -0
- data/config/puffer_routes.rb +8 -0
- data/lib/puffer/controller/dsl.rb +11 -4
- data/lib/puffer/engine.rb +4 -0
- data/lib/puffer/extensions/controller.rb +0 -1
- data/lib/puffer/extensions/form.rb +1 -6
- data/lib/puffer/extensions/mapper.rb +7 -0
- data/lib/puffer/field.rb +87 -0
- data/lib/puffer/{fields.rb → field_set.rb} +2 -2
- data/lib/puffer.rb +2 -0
- data/puffer.gemspec +29 -22
- data/spec/dummy/app/controllers/admin/categories_controller.rb +4 -1
- data/spec/dummy/app/controllers/admin/posts_controller.rb +0 -2
- data/spec/dummy/app/controllers/puffer/sessions_controller.rb +1 -1
- data/spec/dummy/app/models/category.rb +2 -0
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/routes.rb +0 -7
- data/spec/dummy/db/migrate/{20100930132559_create_admin_users.rb → 20100930132559_create_users.rb} +1 -1
- data/spec/dummy/db/migrate/{20100930132656_create_admin_posts.rb → 20100930132656_create_posts.rb} +1 -1
- data/spec/dummy/db/migrate/{20100930132726_create_admin_categories.rb → 20100930132726_create_categories.rb} +6 -1
- data/spec/dummy/db/schema.rb +87 -0
- data/spec/dummy/db/seeds.rb +27 -0
- data/spec/lib/fields_spec.rb +13 -13
- metadata +62 -47
- data/config/routes.rb +0 -0
- data/lib/generators/puffer/install/USAGE +0 -6
- data/lib/generators/puffer/install/install_generator.rb +0 -13
- data/lib/generators/puffer/install/templates/dashboard_controller.rb +0 -3
- data/lib/puffer/controller/mapping.rb +0 -37
- data/lib/puffer/fields/field.rb +0 -89
- data/spec/dummy/app/controllers/puffer/dashboard_controller.rb +0 -3
@@ -0,0 +1,9 @@
|
|
1
|
+
<% @title = resource.human %>
|
2
|
+
<h1><%= @title %> Tree</h1>
|
3
|
+
<% if records.present? %>
|
4
|
+
<%= puffer_tree records, :class => 'puffer_tree' do |record, children| %>
|
5
|
+
<%= render :partial => 'record', :object => record, :locals => {:children => children} %>
|
6
|
+
<% end %>
|
7
|
+
<% else %>
|
8
|
+
<p>Sorry, but there is no records in <%= resource.human %></p>
|
9
|
+
<% end %>
|
@@ -29,21 +29,28 @@ module Puffer
|
|
29
29
|
block.bind(_collections).call if block_given?
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def define_fieldset *actions
|
33
|
+
options = actions.extract_options!
|
34
|
+
fallbacks = Array.wrap(options.delete(:fallbacks))
|
35
|
+
|
33
36
|
actions.each do |action|
|
34
37
|
class_attribute "_#{action}_fields"
|
35
|
-
send "_#{action}_fields=", Puffer::
|
38
|
+
send "_#{action}_fields=", Puffer::FieldSet.new unless send("_#{action}_fields?")
|
36
39
|
helper_method "#{action}_fields"
|
37
40
|
|
38
41
|
self.class.instance_eval do
|
39
42
|
define_method action do |&block|
|
40
|
-
@_fields = send("_#{action}_fields=", Puffer::
|
43
|
+
@_fields = send("_#{action}_fields=", Puffer::FieldSet.new)
|
41
44
|
block.call if block
|
42
45
|
remove_instance_variable :@_fields
|
43
46
|
end
|
44
47
|
|
45
48
|
define_method "#{action}_fields" do
|
46
|
-
|
49
|
+
actions = [action] + fallbacks
|
50
|
+
last = actions.pop
|
51
|
+
actions.map do |action|
|
52
|
+
send("_#{action}_fields").presence
|
53
|
+
end.compact.first || send("_#{last}_fields")
|
47
54
|
end
|
48
55
|
end
|
49
56
|
|
data/lib/puffer/engine.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
module Puffer
|
2
2
|
class Engine < Rails::Engine
|
3
3
|
config.autoload_paths << File.join(root, 'lib')
|
4
|
+
|
5
|
+
initializer 'puffer.add_puffer_namespace_routes', :after => :add_builtin_route do |app|
|
6
|
+
app.routes_reloader.paths.unshift File.join(root, 'config/puffer_routes.rb')
|
7
|
+
end
|
4
8
|
end
|
5
9
|
end
|
@@ -3,12 +3,7 @@ module Puffer
|
|
3
3
|
module FormBuilder
|
4
4
|
|
5
5
|
def puffer_field *args
|
6
|
-
field =
|
7
|
-
args.first
|
8
|
-
else
|
9
|
-
options = args.extract_options!
|
10
|
-
Puffer::Fields::Field.new args, options
|
11
|
-
end
|
6
|
+
field = args.first.is_a?(Puffer::Fields::Field) ? args.first : Puffer::Fields::Field.new(*args)
|
12
7
|
field.resource = object.class
|
13
8
|
field.input self
|
14
9
|
end
|
@@ -24,6 +24,13 @@ module Puffer
|
|
24
24
|
if controller.configuration.group
|
25
25
|
puffer = Rails.application.routes.puffer
|
26
26
|
namespace = @scope[:module]
|
27
|
+
|
28
|
+
unless puffer[namespace]
|
29
|
+
@scope[:module] = 'puffer'
|
30
|
+
root :to => 'dashboard#index'
|
31
|
+
@scope[:module] = namespace
|
32
|
+
end
|
33
|
+
|
27
34
|
puffer[namespace] ||= ActiveSupport::OrderedHash.new
|
28
35
|
puffer[namespace][controller.configuration.group] ||= []
|
29
36
|
puffer[namespace][controller.configuration.group] << controller
|
data/lib/puffer/field.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
module Puffer
|
2
|
+
class Field
|
3
|
+
|
4
|
+
attr_accessor :resource, :field_name, :options, :fields
|
5
|
+
|
6
|
+
def initialize field_name, *resource_and_options, &block
|
7
|
+
@field_name = field_name.to_s
|
8
|
+
@options = resource_and_options.extract_options!
|
9
|
+
@resource = resource_and_options.first
|
10
|
+
@fields = Puffer::FieldSet.new
|
11
|
+
block.bind(self).call if block
|
12
|
+
end
|
13
|
+
|
14
|
+
def field name, options = {}, &block
|
15
|
+
@fields.field(name, swallow_nil{reflection.klass}, options, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def native?
|
19
|
+
model == resource
|
20
|
+
end
|
21
|
+
|
22
|
+
def name
|
23
|
+
@name ||= field_name.split('.').last
|
24
|
+
end
|
25
|
+
|
26
|
+
def path
|
27
|
+
@path ||= field_name.split('.')[0..-2].join('.')
|
28
|
+
end
|
29
|
+
|
30
|
+
def human
|
31
|
+
@human ||= model && model.human_attribute_name(name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def order
|
35
|
+
@order ||= options[:order] || query_column
|
36
|
+
end
|
37
|
+
|
38
|
+
def type
|
39
|
+
@type ||= options[:type] ? options[:type].to_sym : (Puffer::Customs.type_for(self) || (column ? column.type : :string))
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
field_name
|
44
|
+
end
|
45
|
+
|
46
|
+
def reflection
|
47
|
+
@reflection ||= model && model.reflect_on_association(name.to_sym)
|
48
|
+
end
|
49
|
+
|
50
|
+
def collection?
|
51
|
+
[:has_many, :has_and_belongs_to_many].include? type
|
52
|
+
end
|
53
|
+
|
54
|
+
def input_options
|
55
|
+
options[:html] || {}
|
56
|
+
end
|
57
|
+
|
58
|
+
def input builder
|
59
|
+
Puffer::Customs.input_for(self).render builder, self
|
60
|
+
end
|
61
|
+
|
62
|
+
def model
|
63
|
+
@model ||= begin
|
64
|
+
associations = field_name.split('.')
|
65
|
+
associations.pop
|
66
|
+
temp = resource
|
67
|
+
while temp.reflect_on_association(association = swallow_nil{associations.shift.to_sym}) do
|
68
|
+
temp = temp.reflect_on_association(association).klass
|
69
|
+
end
|
70
|
+
temp
|
71
|
+
end if resource
|
72
|
+
end
|
73
|
+
|
74
|
+
def association_columns
|
75
|
+
@association_columns ||= fields
|
76
|
+
end
|
77
|
+
|
78
|
+
def column
|
79
|
+
@column ||= model && model.columns_hash[name]
|
80
|
+
end
|
81
|
+
|
82
|
+
def query_column
|
83
|
+
"#{model.table_name}.#{name}" if column
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
data/lib/puffer.rb
CHANGED
data/puffer.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{puffer}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.21"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["pyromaniac"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-08-01}
|
13
13
|
s.description = %q{In Soviet Russia puffer admins you}
|
14
14
|
s.email = %q{kinwizard@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -33,11 +33,18 @@ Gem::Specification.new do |s|
|
|
33
33
|
"app/assets/javascripts/puffer/right.js",
|
34
34
|
"app/assets/stylesheets/puffer/application.css",
|
35
35
|
"app/assets/stylesheets/puffer/puffer.css",
|
36
|
+
"app/assets/stylesheets/puffer/puffer_tree.css",
|
36
37
|
"app/assets/stylesheets/puffer/reset.css",
|
37
|
-
"app/controllers/puffer/
|
38
|
-
"app/controllers/puffer/
|
38
|
+
"app/controllers/puffer/base.rb",
|
39
|
+
"app/controllers/puffer/dashboard_base.rb",
|
40
|
+
"app/controllers/puffer/dashboard_controller.rb",
|
41
|
+
"app/controllers/puffer/sessions_base.rb",
|
42
|
+
"app/controllers/puffer/sessions_controller.rb",
|
43
|
+
"app/controllers/puffer/tree_base.rb",
|
39
44
|
"app/helpers/puffer_helper.rb",
|
45
|
+
"app/helpers/puffer_tree_helper.rb",
|
40
46
|
"app/views/layouts/puffer.html.erb",
|
47
|
+
"app/views/layouts/puffer_base.html.erb",
|
41
48
|
"app/views/layouts/puffer_dashboard.html.erb",
|
42
49
|
"app/views/layouts/puffer_sessions.html.erb",
|
43
50
|
"app/views/puffer/base/_form.html.erb",
|
@@ -49,25 +56,22 @@ Gem::Specification.new do |s|
|
|
49
56
|
"app/views/puffer/base/index.html.erb",
|
50
57
|
"app/views/puffer/base/new.html.erb",
|
51
58
|
"app/views/puffer/base/show.html.erb",
|
52
|
-
"app/views/puffer/
|
53
|
-
"app/views/puffer/
|
59
|
+
"app/views/puffer/dashboard_base/index.html.erb",
|
60
|
+
"app/views/puffer/sessions_base/new.html.erb",
|
61
|
+
"app/views/puffer/tree_base/_record.html.erb",
|
62
|
+
"app/views/puffer/tree_base/toggle.js.erb",
|
63
|
+
"app/views/puffer/tree_base/tree.html.erb",
|
54
64
|
"config/locales/puffer.yml",
|
55
|
-
"config/
|
65
|
+
"config/puffer_routes.rb",
|
56
66
|
"lib/generators/puffer/controller/USAGE",
|
57
67
|
"lib/generators/puffer/controller/controller_generator.rb",
|
58
68
|
"lib/generators/puffer/controller/templates/controller.rb",
|
59
|
-
"lib/generators/puffer/install/USAGE",
|
60
|
-
"lib/generators/puffer/install/install_generator.rb",
|
61
|
-
"lib/generators/puffer/install/templates/dashboard_controller.rb",
|
62
|
-
"lib/generators/puffer/install/templates/sessions_controller.rb",
|
63
69
|
"lib/puffer.rb",
|
64
|
-
"lib/puffer/base.rb",
|
65
70
|
"lib/puffer/controller/actions.rb",
|
66
71
|
"lib/puffer/controller/config.rb",
|
67
72
|
"lib/puffer/controller/dsl.rb",
|
68
73
|
"lib/puffer/controller/generated.rb",
|
69
74
|
"lib/puffer/controller/helpers.rb",
|
70
|
-
"lib/puffer/controller/mapping.rb",
|
71
75
|
"lib/puffer/controller/mutate.rb",
|
72
76
|
"lib/puffer/customs.rb",
|
73
77
|
"lib/puffer/engine.rb",
|
@@ -76,8 +80,8 @@ Gem::Specification.new do |s|
|
|
76
80
|
"lib/puffer/extensions/core.rb",
|
77
81
|
"lib/puffer/extensions/form.rb",
|
78
82
|
"lib/puffer/extensions/mapper.rb",
|
79
|
-
"lib/puffer/
|
80
|
-
"lib/puffer/
|
83
|
+
"lib/puffer/field.rb",
|
84
|
+
"lib/puffer/field_set.rb",
|
81
85
|
"lib/puffer/inputs/association.rb",
|
82
86
|
"lib/puffer/inputs/base.rb",
|
83
87
|
"lib/puffer/inputs/boolean.rb",
|
@@ -104,7 +108,6 @@ Gem::Specification.new do |s|
|
|
104
108
|
"spec/dummy/app/controllers/admin/tags_controller.rb",
|
105
109
|
"spec/dummy/app/controllers/admin/users_controller.rb",
|
106
110
|
"spec/dummy/app/controllers/application_controller.rb",
|
107
|
-
"spec/dummy/app/controllers/puffer/dashboard_controller.rb",
|
108
111
|
"spec/dummy/app/controllers/puffer/sessions_controller.rb",
|
109
112
|
"spec/dummy/app/helpers/application_helper.rb",
|
110
113
|
"spec/dummy/app/models/category.rb",
|
@@ -133,15 +136,16 @@ Gem::Specification.new do |s|
|
|
133
136
|
"spec/dummy/config/initializers/wrap_parameters.rb",
|
134
137
|
"spec/dummy/config/locales/en.yml",
|
135
138
|
"spec/dummy/config/routes.rb",
|
136
|
-
"spec/dummy/db/migrate/
|
137
|
-
"spec/dummy/db/migrate/
|
138
|
-
"spec/dummy/db/migrate/
|
139
|
+
"spec/dummy/db/migrate/20100930132559_create_users.rb",
|
140
|
+
"spec/dummy/db/migrate/20100930132656_create_posts.rb",
|
141
|
+
"spec/dummy/db/migrate/20100930132726_create_categories.rb",
|
139
142
|
"spec/dummy/db/migrate/20100930132837_create_post_categories.rb",
|
140
143
|
"spec/dummy/db/migrate/20100930133425_create_admin_profiles.rb",
|
141
144
|
"spec/dummy/db/migrate/20101011155830_create_tags.rb",
|
142
145
|
"spec/dummy/db/migrate/20101011160326_create_taggings.rb",
|
143
146
|
"spec/dummy/db/migrate/20110107082706_create_friendships.rb",
|
144
147
|
"spec/dummy/db/migrate/20110301072545_create_news.rb",
|
148
|
+
"spec/dummy/db/schema.rb",
|
145
149
|
"spec/dummy/db/seeds.rb",
|
146
150
|
"spec/dummy/public/404.html",
|
147
151
|
"spec/dummy/public/422.html",
|
@@ -173,7 +177,7 @@ Gem::Specification.new do |s|
|
|
173
177
|
s.specification_version = 3
|
174
178
|
|
175
179
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
176
|
-
s.add_runtime_dependency(%q<rails>, [">= 3.1.0.
|
180
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.1.0.rc5"])
|
177
181
|
s.add_runtime_dependency(%q<kaminari>, [">= 0"])
|
178
182
|
s.add_runtime_dependency(%q<apotomo>, [">= 0"])
|
179
183
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
@@ -186,8 +190,9 @@ Gem::Specification.new do |s|
|
|
186
190
|
s.add_development_dependency(%q<forgery>, [">= 0"])
|
187
191
|
s.add_development_dependency(%q<fabrication>, [">= 0"])
|
188
192
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
193
|
+
s.add_development_dependency(%q<nested_set>, [">= 0"])
|
189
194
|
else
|
190
|
-
s.add_dependency(%q<rails>, [">= 3.1.0.
|
195
|
+
s.add_dependency(%q<rails>, [">= 3.1.0.rc5"])
|
191
196
|
s.add_dependency(%q<kaminari>, [">= 0"])
|
192
197
|
s.add_dependency(%q<apotomo>, [">= 0"])
|
193
198
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
@@ -200,9 +205,10 @@ Gem::Specification.new do |s|
|
|
200
205
|
s.add_dependency(%q<forgery>, [">= 0"])
|
201
206
|
s.add_dependency(%q<fabrication>, [">= 0"])
|
202
207
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
208
|
+
s.add_dependency(%q<nested_set>, [">= 0"])
|
203
209
|
end
|
204
210
|
else
|
205
|
-
s.add_dependency(%q<rails>, [">= 3.1.0.
|
211
|
+
s.add_dependency(%q<rails>, [">= 3.1.0.rc5"])
|
206
212
|
s.add_dependency(%q<kaminari>, [">= 0"])
|
207
213
|
s.add_dependency(%q<apotomo>, [">= 0"])
|
208
214
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
@@ -215,6 +221,7 @@ Gem::Specification.new do |s|
|
|
215
221
|
s.add_dependency(%q<forgery>, [">= 0"])
|
216
222
|
s.add_dependency(%q<fabrication>, [">= 0"])
|
217
223
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
224
|
+
s.add_dependency(%q<nested_set>, [">= 0"])
|
218
225
|
end
|
219
226
|
end
|
220
227
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Admin::CategoriesController < Puffer::
|
1
|
+
class Admin::CategoriesController < Puffer::TreeBase
|
2
2
|
|
3
3
|
setup do
|
4
4
|
group :posting
|
@@ -12,6 +12,9 @@ class Admin::CategoriesController < Puffer::Base
|
|
12
12
|
form do
|
13
13
|
field :id
|
14
14
|
field :title
|
15
|
+
field :parent do
|
16
|
+
field :title
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
20
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
class
|
1
|
+
class CreateCategories < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :categories do |t|
|
4
4
|
t.string :title
|
5
5
|
|
6
|
+
t.integer :parent_id
|
7
|
+
t.integer :lft
|
8
|
+
t.integer :rgt
|
9
|
+
t.integer :depth, :default => 0
|
10
|
+
|
6
11
|
t.timestamps
|
7
12
|
end
|
8
13
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended to check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(:version => 20110301072545) do
|
14
|
+
|
15
|
+
create_table "categories", :force => true do |t|
|
16
|
+
t.string "title"
|
17
|
+
t.integer "parent_id"
|
18
|
+
t.integer "lft"
|
19
|
+
t.integer "rgt"
|
20
|
+
t.integer "depth", :default => 0
|
21
|
+
t.datetime "created_at"
|
22
|
+
t.datetime "updated_at"
|
23
|
+
end
|
24
|
+
|
25
|
+
create_table "friendships", :force => true do |t|
|
26
|
+
t.integer "user_id"
|
27
|
+
t.integer "friend_id"
|
28
|
+
t.string "state"
|
29
|
+
t.datetime "created_at"
|
30
|
+
t.datetime "updated_at"
|
31
|
+
end
|
32
|
+
|
33
|
+
create_table "news", :force => true do |t|
|
34
|
+
t.string "title"
|
35
|
+
t.text "body"
|
36
|
+
t.datetime "created_at"
|
37
|
+
t.datetime "updated_at"
|
38
|
+
end
|
39
|
+
|
40
|
+
create_table "post_categories", :force => true do |t|
|
41
|
+
t.integer "post_id"
|
42
|
+
t.integer "category_id"
|
43
|
+
t.datetime "created_at"
|
44
|
+
t.datetime "updated_at"
|
45
|
+
end
|
46
|
+
|
47
|
+
create_table "posts", :force => true do |t|
|
48
|
+
t.integer "user_id"
|
49
|
+
t.string "title"
|
50
|
+
t.text "body"
|
51
|
+
t.datetime "created_at"
|
52
|
+
t.datetime "updated_at"
|
53
|
+
end
|
54
|
+
|
55
|
+
create_table "profiles", :force => true do |t|
|
56
|
+
t.integer "user_id"
|
57
|
+
t.string "name"
|
58
|
+
t.string "surname"
|
59
|
+
t.date "birth_date"
|
60
|
+
t.datetime "created_at"
|
61
|
+
t.datetime "updated_at"
|
62
|
+
end
|
63
|
+
|
64
|
+
create_table "taggings", :force => true do |t|
|
65
|
+
t.string "name"
|
66
|
+
t.integer "tag_id"
|
67
|
+
t.integer "taggable_id"
|
68
|
+
t.string "taggable_type"
|
69
|
+
end
|
70
|
+
|
71
|
+
add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
|
72
|
+
add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type"
|
73
|
+
|
74
|
+
create_table "tags", :force => true do |t|
|
75
|
+
t.string "name"
|
76
|
+
t.datetime "created_at"
|
77
|
+
t.datetime "updated_at"
|
78
|
+
end
|
79
|
+
|
80
|
+
create_table "users", :force => true do |t|
|
81
|
+
t.string "email"
|
82
|
+
t.string "password"
|
83
|
+
t.datetime "created_at"
|
84
|
+
t.datetime "updated_at"
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/spec/dummy/db/seeds.rb
CHANGED
@@ -5,3 +5,30 @@
|
|
5
5
|
#
|
6
6
|
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
|
7
7
|
# Mayor.create(name: 'Emanuel', city: cities.first)
|
8
|
+
|
9
|
+
categories = {
|
10
|
+
'Category #1' => {
|
11
|
+
'Category #11' => {},
|
12
|
+
'Category #12' => {
|
13
|
+
'Category #121' => {
|
14
|
+
'Category #1211' => {}
|
15
|
+
},
|
16
|
+
'Category #122' =>{}
|
17
|
+
},
|
18
|
+
'Category #13' => {
|
19
|
+
'Category #131' => {}
|
20
|
+
}
|
21
|
+
},
|
22
|
+
'Category #2' => {
|
23
|
+
'Category #21' => {}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
def create_category hash, parent = nil
|
28
|
+
hash.each do |(title, children)|
|
29
|
+
c = Category.create :title => title, :parent => parent
|
30
|
+
create_category children, c
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
create_category categories
|
data/spec/lib/fields_spec.rb
CHANGED
@@ -7,49 +7,49 @@ end
|
|
7
7
|
describe "Field" do
|
8
8
|
|
9
9
|
it "#model" do
|
10
|
-
field = Puffer::
|
10
|
+
field = Puffer::Field.new 'user.profile.name', Post
|
11
11
|
field.model.should == Profile
|
12
|
-
field = Puffer::
|
12
|
+
field = Puffer::Field.new 'user.email', Post
|
13
13
|
field.model.should == User
|
14
|
-
field = Puffer::
|
14
|
+
field = Puffer::Field.new 'user', Post
|
15
15
|
field.model.should == Post
|
16
|
-
field = Puffer::
|
16
|
+
field = Puffer::Field.new 'title', Post
|
17
17
|
field.model.should == Post
|
18
18
|
end
|
19
19
|
|
20
20
|
it "#name" do
|
21
|
-
field = Puffer::
|
21
|
+
field = Puffer::Field.new 'user.profile.name', Post
|
22
22
|
field.name.should == 'name'
|
23
23
|
end
|
24
24
|
|
25
25
|
it "#query_column" do
|
26
|
-
field = Puffer::
|
26
|
+
field = Puffer::Field.new 'user.profile.name', Post
|
27
27
|
field.query_column.should == 'profiles.name'
|
28
|
-
field = Puffer::
|
28
|
+
field = Puffer::Field.new 'user.email', Post
|
29
29
|
field.query_column.should == 'users.email'
|
30
|
-
field = Puffer::
|
30
|
+
field = Puffer::Field.new 'user.full_name', Post
|
31
31
|
field.query_column.should == nil
|
32
32
|
end
|
33
33
|
|
34
34
|
it "#column" do
|
35
|
-
field = Puffer::
|
35
|
+
field = Puffer::Field.new 'user.profile.name', Post
|
36
36
|
field.column.name.should == 'name'
|
37
|
-
field = Puffer::
|
37
|
+
field = Puffer::Field.new 'user.full_name', Post
|
38
38
|
field.column.should == nil
|
39
39
|
end
|
40
40
|
|
41
41
|
it '#type' do
|
42
|
-
field = Puffer::
|
42
|
+
field = Puffer::Field.new 'user.created_at', Post
|
43
43
|
field.type.should == :datetime
|
44
44
|
end
|
45
45
|
|
46
46
|
it '#type with virtual field' do
|
47
|
-
field = Puffer::
|
47
|
+
field = Puffer::Field.new 'user.full_name', Post
|
48
48
|
field.type.should == :string
|
49
49
|
end
|
50
50
|
|
51
51
|
it '#type was specified' do
|
52
|
-
field = Puffer::
|
52
|
+
field = Puffer::Field.new 'user.full_name', Post, :type => :text
|
53
53
|
field.type.should == :text
|
54
54
|
end
|
55
55
|
|