puffer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +98 -80
- data/README.md +6 -0
- data/Rakefile +1 -1
- data/app/assets/javascripts/puffer/puffer.js +15 -3
- data/app/assets/javascripts/puffer/right-sortable-src.js +28 -306
- data/app/assets/stylesheets/puffer/application.css +2 -0
- data/app/assets/stylesheets/puffer/file_input.css +59 -0
- data/app/assets/stylesheets/puffer/puffer.css +1 -0
- data/app/assets/stylesheets/puffer/puffer_grid.css +23 -0
- data/app/components/boolean/filter.html.erb +9 -0
- data/app/components/boolean_component.rb +4 -0
- data/app/components/carrierwave/form.html.erb +34 -0
- data/app/components/carrierwave/index.html.erb +6 -0
- data/app/components/carrierwave_component.rb +16 -0
- data/app/components/references_one/form.html.erb +2 -3
- data/app/controllers/admin/dashboard_controller.rb +0 -1
- data/app/controllers/admin/puffer_users_controller.rb +3 -7
- data/app/controllers/admin/sessions_controller.rb +1 -1
- data/app/models/puffer_user.rb +3 -18
- data/app/views/layouts/puffer.html.erb +2 -0
- data/app/views/puffer/base/_edit.html.erb +1 -1
- data/app/views/puffer/base/new.html.erb +1 -1
- data/app/views/puffer/grid_base/_grid.html.erb +9 -0
- data/app/views/puffer/grid_base/_index.html.erb +26 -0
- data/config/routes.rb +1 -1
- data/gemfiles/Gemfile-rails-3.1 +5 -0
- data/gemfiles/Gemfile-rails-3.1.lock +201 -0
- data/gemfiles/Gemfile-rails-3.2 +5 -0
- data/gemfiles/Gemfile-rails-3.2.lock +199 -0
- data/lib/puffer.rb +38 -12
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/base.rb +1 -2
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/dashboard_base.rb +0 -1
- data/lib/puffer/backends/controllers/grid_base.rb +12 -0
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/puffer_users_base.rb +0 -0
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/base.rb +0 -1
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/clearance.rb +13 -5
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/devise.rb +1 -1
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/simple.rb +1 -1
- data/{app/controllers/puffer → lib/puffer/backends/controllers}/tree_base.rb +0 -1
- data/lib/puffer/backends/models/user/active_record.rb +9 -0
- data/lib/puffer/backends/models/user/base.rb +30 -0
- data/lib/puffer/backends/models/user/mongoid.rb +15 -0
- data/lib/puffer/component.rb +2 -2
- data/lib/puffer/controller/auth.rb +48 -47
- data/lib/puffer/controller/config.rb +4 -6
- data/lib/puffer/controller/dsl.rb +2 -4
- data/lib/puffer/controller/mutate.rb +23 -26
- data/lib/puffer/extensions/directive_processor.rb +11 -16
- data/lib/puffer/extensions/engine.rb +7 -9
- data/lib/puffer/extensions/{mapper.rb → mapper31.rb} +10 -12
- data/lib/puffer/extensions/mapper32.rb +108 -0
- data/lib/puffer/filters.rb +15 -3
- data/lib/puffer/orm_adapter/active_record.rb +15 -2
- data/lib/puffer/orm_adapter/base.rb +4 -0
- data/lib/puffer/orm_adapter/mongoid.rb +15 -2
- data/lib/puffer/resource.rb +1 -1
- data/lib/puffer/version.rb +1 -1
- data/puffer.gemspec +10 -4
- data/spec/{app/components → components}/base_component_spec.rb +0 -0
- data/spec/{app/components → components}/boolean_component_spec.rb +0 -0
- data/spec/{app/components → components}/date_time_component_spec.rb +0 -0
- data/spec/{app/components → components}/file_component_spec.rb +0 -0
- data/spec/{app/components → components}/hidden_component_spec.rb +0 -0
- data/spec/{app/components → components}/password_component_spec.rb +0 -0
- data/spec/{app/components → components}/references_many_component_spec.rb +0 -0
- data/spec/{app/components → components}/references_one_component_spec.rb +0 -0
- data/spec/{app/components → components}/select_component_spec.rb +0 -0
- data/spec/{app/components → components}/string_component_spec.rb +0 -0
- data/spec/{app/components → components}/text_component_spec.rb +0 -0
- data/spec/controllers/sessions/base_shared.rb +66 -0
- data/spec/controllers/sessions/clearance_spec.rb +21 -0
- data/spec/controllers/sessions/simple_spec.rb +14 -0
- data/spec/dummy/app/controllers/admin/news_controller.rb +1 -1
- data/spec/dummy/app/controllers/admin/profiles_controller.rb +3 -1
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/orms/mongoid_orm_primals_controller.rb +16 -0
- data/spec/dummy/app/helpers/news_helper.rb +1 -1
- data/spec/dummy/app/models/clearance_user.rb +3 -0
- data/spec/dummy/app/models/mongoid_orm/embeds_many_reference.rb +9 -0
- data/spec/dummy/app/models/mongoid_orm/embeds_one_reference.rb +9 -0
- data/spec/dummy/app/models/mongoid_orm/has_many_reference.rb +9 -0
- data/spec/dummy/app/models/mongoid_orm/has_one_reference.rb +9 -0
- data/spec/dummy/app/models/mongoid_orm/primal.rb +8 -0
- data/spec/dummy/app/models/profile.rb +2 -0
- data/spec/dummy/app/uploaders/avatar_uploader.rb +8 -0
- data/spec/dummy/config/application.rb +5 -3
- data/spec/dummy/config/initializers/clearance.rb +3 -0
- data/spec/dummy/config/initializers/devise.rb +34 -22
- data/spec/dummy/config/locales/devise.en.yml +6 -7
- data/spec/dummy/config/routes.rb +0 -1
- data/spec/dummy/db/migrate/{20100930133425_create_admin_profiles.rb → 20100930133425_create_profiles.rb} +2 -1
- data/spec/dummy/db/migrate/20111208222355_create_clearance_users.rb +13 -0
- data/spec/dummy/db/migrate/20120129091339_upgrade_clearance_to_diesel.rb +19 -0
- data/spec/dummy/db/schema.rb +12 -1
- data/spec/fabricators/clearance_user_fabricator.rb +4 -0
- data/spec/fabricators/puffer_user_fabricator.rb +5 -0
- data/spec/lib/filters_spec.rb +1 -1
- data/spec/lib/orm_adapter/active_record_spec.rb +0 -1
- data/spec/lib/orm_adapter/base_shared.rb +80 -76
- data/spec/lib/orm_adapter/mongoid_spec.rb +0 -2
- data/spec/lib/resource/tree_spec.rb +0 -1
- data/spec/spec_helper.rb +5 -3
- metadata +150 -75
- data/VERSION +0 -1
- data/app/models/puffer/puffer_user.rb +0 -25
@@ -16,6 +16,14 @@ class MongoidOrm::Primal
|
|
16
16
|
field :set_field, :type => ::Set
|
17
17
|
field :range_field, :type => Range
|
18
18
|
|
19
|
+
has_one :has_one_reference, :validate => true, :class_name => 'MongoidOrm::HasOneReference'
|
20
|
+
has_many :has_many_references, :validate => true, :class_name => 'MongoidOrm::HasManyReference'
|
21
|
+
|
22
|
+
embeds_one :embeds_one_reference, :validate => true, :class_name => 'MongoidOrm::EmbedsOneReference'
|
23
|
+
embeds_many :embeds_many_references, :validate => true, :class_name => 'MongoidOrm::EmbedsManyReference'
|
24
|
+
|
25
|
+
accepts_nested_attributes_for :has_one_reference, :has_many_references, :allow_destroy => true
|
26
|
+
|
19
27
|
def array_field_before_type_cast
|
20
28
|
array_field.join(', ') if array_field.present?
|
21
29
|
end
|
@@ -2,10 +2,10 @@ require File.expand_path('../boot', __FILE__)
|
|
2
2
|
|
3
3
|
require 'rails/all'
|
4
4
|
|
5
|
-
Bundler.require
|
5
|
+
Bundler.require :development
|
6
|
+
|
7
|
+
require 'carrierwave/orm/activerecord'
|
6
8
|
require 'puffer'
|
7
|
-
require 'nested_set'
|
8
|
-
require 'devise'
|
9
9
|
|
10
10
|
module Dummy
|
11
11
|
class Application < Rails::Application
|
@@ -41,3 +41,5 @@ module Dummy
|
|
41
41
|
config.assets.enabled = true
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
require Rails.root.join('config/initializers/clearance.rb')
|
@@ -1,5 +1,5 @@
|
|
1
|
-
# Use this hook to configure devise mailer, warden hooks and so forth.
|
2
|
-
#
|
1
|
+
# Use this hook to configure devise mailer, warden hooks and so forth.
|
2
|
+
# Many of these configuration options can be set straight in your model.
|
3
3
|
Devise.setup do |config|
|
4
4
|
# ==> Mailer Configuration
|
5
5
|
# Configure the e-mail address which will be shown in Devise::Mailer,
|
@@ -9,6 +9,9 @@ Devise.setup do |config|
|
|
9
9
|
# Configure the class responsible to send e-mails.
|
10
10
|
# config.mailer = "Devise::Mailer"
|
11
11
|
|
12
|
+
# Automatically apply schema changes in tableless databases
|
13
|
+
config.apply_schema = false
|
14
|
+
|
12
15
|
# ==> ORM configuration
|
13
16
|
# Load and configure the ORM. Supports :active_record (default) and
|
14
17
|
# :mongoid (bson_ext recommended) by default. Other ORMs may be
|
@@ -43,9 +46,15 @@ Devise.setup do |config|
|
|
43
46
|
config.strip_whitespace_keys = [ :email ]
|
44
47
|
|
45
48
|
# Tell if authentication through request.params is enabled. True by default.
|
49
|
+
# It can be set to an array that will enable params authentication only for the
|
50
|
+
# given strategies, for example, `config.params_authenticatable = [:database]` will
|
51
|
+
# enable it only for database (email + password) authentication.
|
46
52
|
# config.params_authenticatable = true
|
47
53
|
|
48
54
|
# Tell if authentication through HTTP Basic Auth is enabled. False by default.
|
55
|
+
# It can be set to an array that will enable http authentication only for the
|
56
|
+
# given strategies, for example, `config.http_authenticatable = [:token]` will
|
57
|
+
# enable it only for token authentication.
|
49
58
|
# config.http_authenticatable = false
|
50
59
|
|
51
60
|
# If http headers should be returned for AJAX requests. True by default.
|
@@ -59,6 +68,13 @@ Devise.setup do |config|
|
|
59
68
|
# Does not affect registerable.
|
60
69
|
# config.paranoid = true
|
61
70
|
|
71
|
+
# By default Devise will store the user in session. You can skip storage for
|
72
|
+
# :http_auth and :token_auth by adding those symbols to the array below.
|
73
|
+
# Notice that if you are skipping storage for all authentication paths, you
|
74
|
+
# may want to disable generating routes to Devise's sessions controller by
|
75
|
+
# passing :skip => :sessions to `devise_for` in your config/routes.rb
|
76
|
+
config.skip_session_storage = [:http_auth]
|
77
|
+
|
62
78
|
# ==> Configuration for :database_authenticatable
|
63
79
|
# For bcrypt, this is the cost for hashing the password and defaults to 10. If
|
64
80
|
# using other encryptors, it sets how many times you want the password re-encrypted.
|
@@ -69,16 +85,21 @@ Devise.setup do |config|
|
|
69
85
|
config.stretches = Rails.env.test? ? 1 : 10
|
70
86
|
|
71
87
|
# Setup a pepper to generate the encrypted password.
|
72
|
-
# config.pepper = "
|
88
|
+
# config.pepper = "de02046bab0967b9d9b0204aa70d755f7b52b9cd274ed3c1e0791bf971a28758c41b93e44577f812993607f429937ec0a8848054a5854cd3f4409a53add88ce1"
|
73
89
|
|
74
90
|
# ==> Configuration for :confirmable
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
|
91
|
+
# A period that the user is allowed to access the website even without
|
92
|
+
# confirming his account. For instance, if set to 2.days, the user will be
|
93
|
+
# able to access the website for two days without confirming his account,
|
94
|
+
# access will be blocked just in the third day. Default is 0.days, meaning
|
95
|
+
# the user cannot access the website without confirming his account.
|
96
|
+
# config.allow_unconfirmed_access_for = 2.days
|
97
|
+
|
98
|
+
# If true, requires any email changes to be confirmed (exctly the same way as
|
99
|
+
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
100
|
+
# db field (see migrations). Until confirmed new email is stored in
|
101
|
+
# unconfirmed email column, and copied to email column on successful confirmation.
|
102
|
+
config.reconfirmable = true
|
82
103
|
|
83
104
|
# Defines which key will be used when confirming an account
|
84
105
|
# config.confirmation_keys = [ :email ]
|
@@ -87,9 +108,6 @@ Devise.setup do |config|
|
|
87
108
|
# The time the user will be remembered without asking for credentials again.
|
88
109
|
# config.remember_for = 2.weeks
|
89
110
|
|
90
|
-
# If true, a valid remember token can be re-used between multiple browsers.
|
91
|
-
# config.remember_across_browsers = true
|
92
|
-
|
93
111
|
# If true, extends the user's remember period when remembered via cookie.
|
94
112
|
# config.extend_remember_period = false
|
95
113
|
|
@@ -146,7 +164,7 @@ Devise.setup do |config|
|
|
146
164
|
# Time interval you can reset your password with a reset password key.
|
147
165
|
# Don't put a too small interval or your users won't have the time to
|
148
166
|
# change their passwords.
|
149
|
-
config.reset_password_within =
|
167
|
+
config.reset_password_within = 6.hours
|
150
168
|
|
151
169
|
# ==> Configuration for :encryptable
|
152
170
|
# Allow you to use another encryption algorithm besides bcrypt (default). You can use
|
@@ -160,10 +178,6 @@ Devise.setup do |config|
|
|
160
178
|
# Defines name of the authentication token params key
|
161
179
|
# config.token_authentication_key = :auth_token
|
162
180
|
|
163
|
-
# If true, authentication through token does not store user in session and needs
|
164
|
-
# to be supplied on each request. Useful if you are using the token as API token.
|
165
|
-
# config.stateless_token = false
|
166
|
-
|
167
181
|
# ==> Scopes configuration
|
168
182
|
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
169
183
|
# "users/sessions/new". It's turned off by default because it's slower if you
|
@@ -187,9 +201,8 @@ Devise.setup do |config|
|
|
187
201
|
# If you have any extra navigational formats, like :iphone or :mobile, you
|
188
202
|
# should add them to the navigational formats lists.
|
189
203
|
#
|
190
|
-
# The
|
191
|
-
#
|
192
|
-
# config.navigational_formats = [:"*/*", "*/*", :html]
|
204
|
+
# The "*/*" below is required to match Internet Explorer requests.
|
205
|
+
# config.navigational_formats = ["*/*", :html]
|
193
206
|
|
194
207
|
# The default HTTP method used to sign out a resource. Default is :delete.
|
195
208
|
config.sign_out_via = :delete
|
@@ -204,7 +217,6 @@ Devise.setup do |config|
|
|
204
217
|
# change the failure app, you can configure them inside the config.warden block.
|
205
218
|
#
|
206
219
|
# config.warden do |manager|
|
207
|
-
# manager.failure_app = AnotherApp
|
208
220
|
# manager.intercept_401 = false
|
209
221
|
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
210
222
|
# end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Additional translations at
|
1
|
+
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n
|
2
2
|
|
3
3
|
en:
|
4
4
|
errors:
|
@@ -35,16 +35,15 @@ en:
|
|
35
35
|
confirmed: 'Your account was successfully confirmed. You are now signed in.'
|
36
36
|
registrations:
|
37
37
|
signed_up: 'Welcome! You have signed up successfully.'
|
38
|
-
|
38
|
+
signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
|
39
|
+
signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
|
40
|
+
signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
|
39
41
|
updated: 'You updated your account successfully.'
|
42
|
+
update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
|
40
43
|
destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
|
41
|
-
reasons:
|
42
|
-
inactive: 'inactive'
|
43
|
-
unconfirmed: 'unconfirmed'
|
44
|
-
locked: 'locked'
|
45
44
|
unlocks:
|
46
45
|
send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
|
47
|
-
unlocked: 'Your account
|
46
|
+
unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
|
48
47
|
send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
|
49
48
|
omniauth_callbacks:
|
50
49
|
success: 'Successfully authorized from %{kind} account.'
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
class
|
1
|
+
class CreateProfiles < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :profiles do |t|
|
4
4
|
t.integer :user_id
|
5
5
|
t.string :name
|
6
6
|
t.string :surname
|
7
7
|
t.date :birth_date
|
8
|
+
t.string :avatar
|
8
9
|
|
9
10
|
t.timestamps
|
10
11
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateClearanceUsers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :clearance_users do |t|
|
4
|
+
t.string :email
|
5
|
+
t.string :encrypted_password, :limit => 128
|
6
|
+
t.string :salt, :limit => 128
|
7
|
+
t.string :confirmation_token, :limit => 128
|
8
|
+
t.string :remember_token, :limit => 128
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class UpgradeClearanceToDiesel < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table(:users) do |t|
|
4
|
+
t.string :encrypted_password, :limit => 128
|
5
|
+
t.string :salt, :limit => 128
|
6
|
+
t.string :confirmation_token, :limit => 128
|
7
|
+
t.string :remember_token, :limit => 128
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :users, :email
|
11
|
+
add_index :users, :remember_token
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
change_table(:users) do |t|
|
16
|
+
t.remove :encrypted_password,:salt,:confirmation_token,:remember_token
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20111208222355) do
|
15
15
|
|
16
16
|
create_table "active_record_orm_has_many_references", :force => true do |t|
|
17
17
|
t.string "name"
|
@@ -52,6 +52,16 @@ ActiveRecord::Schema.define(:version => 20111122203304) do
|
|
52
52
|
t.datetime "updated_at"
|
53
53
|
end
|
54
54
|
|
55
|
+
create_table "clearance_users", :force => true do |t|
|
56
|
+
t.string "email"
|
57
|
+
t.string "encrypted_password", :limit => 128
|
58
|
+
t.string "salt", :limit => 128
|
59
|
+
t.string "confirmation_token", :limit => 128
|
60
|
+
t.string "remember_token", :limit => 128
|
61
|
+
t.datetime "created_at"
|
62
|
+
t.datetime "updated_at"
|
63
|
+
end
|
64
|
+
|
55
65
|
create_table "friendships", :force => true do |t|
|
56
66
|
t.integer "user_id"
|
57
67
|
t.integer "friend_id"
|
@@ -90,6 +100,7 @@ ActiveRecord::Schema.define(:version => 20111122203304) do
|
|
90
100
|
t.string "name"
|
91
101
|
t.string "surname"
|
92
102
|
t.date "birth_date"
|
103
|
+
t.string "avatar"
|
93
104
|
t.datetime "created_at"
|
94
105
|
t.datetime "updated_at"
|
95
106
|
end
|
data/spec/lib/filters_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Puffer::Filters do
|
|
5
5
|
describe 'controller filters class generation' do
|
6
6
|
|
7
7
|
it 'should set proper attributes' do
|
8
|
-
Puffer::Filters.new(Admin::PostsController.filter_fields).attributes.keys.should == %w(user.email status title body puffer_search puffer_order)
|
8
|
+
Puffer::Filters.new(Admin::PostsController.filter_fields).attributes.keys.should == %w(user.email status title body puffer_search puffer_order puffer_per_page)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should set proper query' do
|
@@ -2,118 +2,122 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples "an adapter" do
|
4
4
|
|
5
|
-
|
6
|
-
model.to_adapter.filter(model, controller.index_fields, options).all.to_a
|
7
|
-
end
|
8
|
-
|
9
|
-
|
10
|
-
def nth *indexes
|
11
|
-
model.all.to_a.values_at *indexes
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'without params' do
|
5
|
+
describe 'filtering' do
|
15
6
|
|
16
|
-
|
17
|
-
|
7
|
+
def filter options = {}
|
8
|
+
model.to_adapter.filter(model, controller.index_fields, options).all.to_a
|
18
9
|
end
|
19
10
|
|
20
|
-
it 'should return all records' do
|
21
|
-
filter.should == model.all.to_a
|
22
|
-
end
|
23
11
|
|
24
|
-
|
25
|
-
|
26
|
-
context 'search' do
|
27
|
-
|
28
|
-
before do
|
29
|
-
string_fields = %w(hello hello world hello world)
|
30
|
-
select_fields = %w(hello world helloworld hello world)
|
31
|
-
5.times { |i|
|
32
|
-
Fabricate fabric, :string_field => string_fields[i], :select_field => select_fields[i]
|
33
|
-
}
|
12
|
+
def nth *indexes
|
13
|
+
model.all.to_a.values_at *indexes
|
34
14
|
end
|
35
15
|
|
36
|
-
|
37
|
-
filter(:search => 'hel').should == nth(0, 1, 2, 3)
|
38
|
-
end
|
16
|
+
context 'without params' do
|
39
17
|
|
40
|
-
|
41
|
-
|
42
|
-
|
18
|
+
before do
|
19
|
+
5.times { Fabricate fabric }
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return all records' do
|
23
|
+
filter.should == model.all.to_a
|
24
|
+
end
|
43
25
|
|
44
|
-
it 'should return searched records without conditioned' do
|
45
|
-
filter(:search => 'hel', :conditions => {'select_field' => 'world'}).should == nth(1)
|
46
26
|
end
|
47
27
|
|
48
|
-
|
28
|
+
context 'search' do
|
49
29
|
|
50
|
-
|
30
|
+
before do
|
31
|
+
string_fields = %w(hello hello world hello world)
|
32
|
+
select_fields = %w(hello world helloworld hello world)
|
33
|
+
5.times { |i|
|
34
|
+
Fabricate fabric, :string_field => string_fields[i], :select_field => select_fields[i]
|
35
|
+
}
|
36
|
+
end
|
51
37
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
5.times { |i|
|
56
|
-
Fabricate fabric, :select_field => select_fields[i], :boolean_field => boolean_fields[i]
|
57
|
-
}
|
58
|
-
end
|
38
|
+
it 'should return all searched records' do
|
39
|
+
filter(:search => 'hel').should =~ nth(0, 1, 2, 3)
|
40
|
+
end
|
59
41
|
|
60
|
-
|
61
|
-
|
62
|
-
|
42
|
+
it 'should return searched records without conditioned' do
|
43
|
+
filter(:search => 'hel', :conditions => {'select_field' => 'hello'}).should =~ nth(0, 3)
|
44
|
+
end
|
63
45
|
|
64
|
-
|
65
|
-
|
66
|
-
|
46
|
+
it 'should return searched records without conditioned' do
|
47
|
+
filter(:search => 'hel', :conditions => {'select_field' => 'world'}).should =~ nth(1)
|
48
|
+
end
|
67
49
|
|
68
|
-
it 'should stack conditions with end' do
|
69
|
-
filter(:conditions => {'select_field' => 'hello', 'boolean_field' => true}).should == nth(0, 3)
|
70
50
|
end
|
71
51
|
|
72
|
-
|
52
|
+
context 'select' do
|
73
53
|
|
74
|
-
|
54
|
+
before do
|
55
|
+
select_fields = %w(hello world hello hello world)
|
56
|
+
boolean_fields = %w(true false false true false)
|
57
|
+
5.times { |i|
|
58
|
+
Fabricate fabric, :select_field => select_fields[i], :boolean_field => boolean_fields[i]
|
59
|
+
}
|
60
|
+
end
|
75
61
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
Fabricate fabric, :integer_field => integer_fields[i]
|
80
|
-
}
|
81
|
-
end
|
62
|
+
it 'should return all conditioned records' do
|
63
|
+
filter(:conditions => {'select_field' => 'hello'}).should =~ nth(0, 2, 3)
|
64
|
+
end
|
82
65
|
|
83
|
-
|
84
|
-
|
85
|
-
|
66
|
+
it 'should return all conditioned records' do
|
67
|
+
filter(:conditions => {'boolean_field' => false}).should =~ nth(1, 2, 4)
|
68
|
+
end
|
86
69
|
|
87
|
-
|
88
|
-
|
89
|
-
|
70
|
+
it 'should stack conditions with end' do
|
71
|
+
filter(:conditions => {'select_field' => 'hello', 'boolean_field' => true}).should =~ nth(0, 3)
|
72
|
+
end
|
90
73
|
|
91
|
-
it 'should order records desc' do
|
92
|
-
filter(:order => ['integer_field', :desc]).should == nth(2, 3, 1, 0, 4)
|
93
74
|
end
|
94
75
|
|
95
|
-
|
76
|
+
context 'order' do
|
96
77
|
|
97
|
-
context 'diapazones' do
|
98
|
-
Timecop.freeze Time.now do
|
99
78
|
before do
|
79
|
+
integer_fields = %w(2, 3, 5, 4, 1)
|
100
80
|
5.times { |i|
|
101
|
-
Fabricate fabric, :
|
81
|
+
Fabricate fabric, :integer_field => integer_fields[i]
|
102
82
|
}
|
103
83
|
end
|
104
84
|
|
105
|
-
it 'should
|
106
|
-
filter(:
|
85
|
+
it 'should order records asc' do
|
86
|
+
filter(:order => 'integer_field').should =~ nth(4, 0, 1, 3, 2)
|
107
87
|
end
|
108
88
|
|
109
|
-
it 'should
|
110
|
-
filter(:
|
89
|
+
it 'should order records asc' do
|
90
|
+
filter(:order => ['integer_field', :asc]).should =~ nth(4, 0, 1, 3, 2)
|
111
91
|
end
|
112
92
|
|
113
|
-
it 'should
|
114
|
-
filter(:
|
93
|
+
it 'should order records desc' do
|
94
|
+
filter(:order => ['integer_field', :desc]).should =~ nth(2, 3, 1, 0, 4)
|
115
95
|
end
|
96
|
+
|
116
97
|
end
|
98
|
+
|
99
|
+
context 'diapazones' do
|
100
|
+
Timecop.freeze Time.now do
|
101
|
+
before do
|
102
|
+
5.times { |i|
|
103
|
+
Fabricate fabric, :datetime_field => Time.now + i.hours
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should return from till' do
|
108
|
+
filter(:conditions => {'datetime_field' => Puffer::Filters::Diapason.new(Time.now + 0.9.hour, Time.now + 3.1.hours)}).should =~ nth(1, 2, 3)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should return from' do
|
112
|
+
filter(:conditions => {'datetime_field' => Puffer::Filters::Diapason.new(Time.now + 0.9.hour)}).should =~ nth(1, 2, 3, 4)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should return till' do
|
116
|
+
filter(:conditions => {'datetime_field' => Puffer::Filters::Diapason.new(nil, Time.now + 3.1.hours)}).should =~ nth(0, 1, 2, 3)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
117
121
|
end
|
118
122
|
|
119
123
|
end
|