puffer 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +6 -0
  3. data/CHANGELOG.md +14 -0
  4. data/Gemfile.lock +98 -80
  5. data/README.md +6 -0
  6. data/Rakefile +1 -1
  7. data/app/assets/javascripts/puffer/puffer.js +15 -3
  8. data/app/assets/javascripts/puffer/right-sortable-src.js +28 -306
  9. data/app/assets/stylesheets/puffer/application.css +2 -0
  10. data/app/assets/stylesheets/puffer/file_input.css +59 -0
  11. data/app/assets/stylesheets/puffer/puffer.css +1 -0
  12. data/app/assets/stylesheets/puffer/puffer_grid.css +23 -0
  13. data/app/components/boolean/filter.html.erb +9 -0
  14. data/app/components/boolean_component.rb +4 -0
  15. data/app/components/carrierwave/form.html.erb +34 -0
  16. data/app/components/carrierwave/index.html.erb +6 -0
  17. data/app/components/carrierwave_component.rb +16 -0
  18. data/app/components/references_one/form.html.erb +2 -3
  19. data/app/controllers/admin/dashboard_controller.rb +0 -1
  20. data/app/controllers/admin/puffer_users_controller.rb +3 -7
  21. data/app/controllers/admin/sessions_controller.rb +1 -1
  22. data/app/models/puffer_user.rb +3 -18
  23. data/app/views/layouts/puffer.html.erb +2 -0
  24. data/app/views/puffer/base/_edit.html.erb +1 -1
  25. data/app/views/puffer/base/new.html.erb +1 -1
  26. data/app/views/puffer/grid_base/_grid.html.erb +9 -0
  27. data/app/views/puffer/grid_base/_index.html.erb +26 -0
  28. data/config/routes.rb +1 -1
  29. data/gemfiles/Gemfile-rails-3.1 +5 -0
  30. data/gemfiles/Gemfile-rails-3.1.lock +201 -0
  31. data/gemfiles/Gemfile-rails-3.2 +5 -0
  32. data/gemfiles/Gemfile-rails-3.2.lock +199 -0
  33. data/lib/puffer.rb +38 -12
  34. data/{app/controllers/puffer → lib/puffer/backends/controllers}/base.rb +1 -2
  35. data/{app/controllers/puffer → lib/puffer/backends/controllers}/dashboard_base.rb +0 -1
  36. data/lib/puffer/backends/controllers/grid_base.rb +12 -0
  37. data/{app/controllers/puffer → lib/puffer/backends/controllers}/puffer_users_base.rb +0 -0
  38. data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/base.rb +0 -1
  39. data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/clearance.rb +13 -5
  40. data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/devise.rb +1 -1
  41. data/{app/controllers/puffer → lib/puffer/backends/controllers}/sessions/simple.rb +1 -1
  42. data/{app/controllers/puffer → lib/puffer/backends/controllers}/tree_base.rb +0 -1
  43. data/lib/puffer/backends/models/user/active_record.rb +9 -0
  44. data/lib/puffer/backends/models/user/base.rb +30 -0
  45. data/lib/puffer/backends/models/user/mongoid.rb +15 -0
  46. data/lib/puffer/component.rb +2 -2
  47. data/lib/puffer/controller/auth.rb +48 -47
  48. data/lib/puffer/controller/config.rb +4 -6
  49. data/lib/puffer/controller/dsl.rb +2 -4
  50. data/lib/puffer/controller/mutate.rb +23 -26
  51. data/lib/puffer/extensions/directive_processor.rb +11 -16
  52. data/lib/puffer/extensions/engine.rb +7 -9
  53. data/lib/puffer/extensions/{mapper.rb → mapper31.rb} +10 -12
  54. data/lib/puffer/extensions/mapper32.rb +108 -0
  55. data/lib/puffer/filters.rb +15 -3
  56. data/lib/puffer/orm_adapter/active_record.rb +15 -2
  57. data/lib/puffer/orm_adapter/base.rb +4 -0
  58. data/lib/puffer/orm_adapter/mongoid.rb +15 -2
  59. data/lib/puffer/resource.rb +1 -1
  60. data/lib/puffer/version.rb +1 -1
  61. data/puffer.gemspec +10 -4
  62. data/spec/{app/components → components}/base_component_spec.rb +0 -0
  63. data/spec/{app/components → components}/boolean_component_spec.rb +0 -0
  64. data/spec/{app/components → components}/date_time_component_spec.rb +0 -0
  65. data/spec/{app/components → components}/file_component_spec.rb +0 -0
  66. data/spec/{app/components → components}/hidden_component_spec.rb +0 -0
  67. data/spec/{app/components → components}/password_component_spec.rb +0 -0
  68. data/spec/{app/components → components}/references_many_component_spec.rb +0 -0
  69. data/spec/{app/components → components}/references_one_component_spec.rb +0 -0
  70. data/spec/{app/components → components}/select_component_spec.rb +0 -0
  71. data/spec/{app/components → components}/string_component_spec.rb +0 -0
  72. data/spec/{app/components → components}/text_component_spec.rb +0 -0
  73. data/spec/controllers/sessions/base_shared.rb +66 -0
  74. data/spec/controllers/sessions/clearance_spec.rb +21 -0
  75. data/spec/controllers/sessions/simple_spec.rb +14 -0
  76. data/spec/dummy/app/controllers/admin/news_controller.rb +1 -1
  77. data/spec/dummy/app/controllers/admin/profiles_controller.rb +3 -1
  78. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  79. data/spec/dummy/app/controllers/orms/mongoid_orm_primals_controller.rb +16 -0
  80. data/spec/dummy/app/helpers/news_helper.rb +1 -1
  81. data/spec/dummy/app/models/clearance_user.rb +3 -0
  82. data/spec/dummy/app/models/mongoid_orm/embeds_many_reference.rb +9 -0
  83. data/spec/dummy/app/models/mongoid_orm/embeds_one_reference.rb +9 -0
  84. data/spec/dummy/app/models/mongoid_orm/has_many_reference.rb +9 -0
  85. data/spec/dummy/app/models/mongoid_orm/has_one_reference.rb +9 -0
  86. data/spec/dummy/app/models/mongoid_orm/primal.rb +8 -0
  87. data/spec/dummy/app/models/profile.rb +2 -0
  88. data/spec/dummy/app/uploaders/avatar_uploader.rb +8 -0
  89. data/spec/dummy/config/application.rb +5 -3
  90. data/spec/dummy/config/initializers/clearance.rb +3 -0
  91. data/spec/dummy/config/initializers/devise.rb +34 -22
  92. data/spec/dummy/config/locales/devise.en.yml +6 -7
  93. data/spec/dummy/config/routes.rb +0 -1
  94. data/spec/dummy/db/migrate/{20100930133425_create_admin_profiles.rb → 20100930133425_create_profiles.rb} +2 -1
  95. data/spec/dummy/db/migrate/20111208222355_create_clearance_users.rb +13 -0
  96. data/spec/dummy/db/migrate/20120129091339_upgrade_clearance_to_diesel.rb +19 -0
  97. data/spec/dummy/db/schema.rb +12 -1
  98. data/spec/fabricators/clearance_user_fabricator.rb +4 -0
  99. data/spec/fabricators/puffer_user_fabricator.rb +5 -0
  100. data/spec/lib/filters_spec.rb +1 -1
  101. data/spec/lib/orm_adapter/active_record_spec.rb +0 -1
  102. data/spec/lib/orm_adapter/base_shared.rb +80 -76
  103. data/spec/lib/orm_adapter/mongoid_spec.rb +0 -2
  104. data/spec/lib/resource/tree_spec.rb +0 -1
  105. data/spec/spec_helper.rb +5 -3
  106. metadata +150 -75
  107. data/VERSION +0 -1
  108. 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
@@ -4,4 +4,6 @@ class Profile < ActiveRecord::Base
4
4
  has_many :tags, :through => :taggings
5
5
 
6
6
  validates_presence_of :name, :surname
7
+
8
+ mount_uploader :avatar, AvatarUploader
7
9
  end
@@ -0,0 +1,8 @@
1
+ class AvatarUploader < CarrierWave::Uploader::Base
2
+ include CarrierWave::MiniMagick
3
+ storage :file
4
+
5
+ version :puffer do
6
+ process :resize_to_fill => [100, 100]
7
+ end
8
+ 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')
@@ -0,0 +1,3 @@
1
+ Clearance.configure do |config|
2
+ config.mailer_sender = 'donotreply@example.com'
3
+ end
@@ -1,5 +1,5 @@
1
- # Use this hook to configure devise mailer, warden hooks and so forth. The first
2
- # four configuration values can also be set straight in your models.
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 = "80976e8142b5962f4ac9198f4b805704bec95eee4fad0a209d6996c92e2e5552b134d9c67ba7e53af6b0f3b8a97f929d2aa3195bc3842faeb3b6435703855e8d"
88
+ # config.pepper = "de02046bab0967b9d9b0204aa70d755f7b52b9cd274ed3c1e0791bf971a28758c41b93e44577f812993607f429937ec0a8848054a5854cd3f4409a53add88ce1"
73
89
 
74
90
  # ==> Configuration for :confirmable
75
- # The time you want to give your user to confirm his account. During this time
76
- # he will be able to access your application without confirming. Default is 0.days
77
- # When confirm_within is zero, the user won't be able to sign in without confirming.
78
- # You can use this to let your user access some features of your application
79
- # without confirming the account, but blocking it after a certain period
80
- # (ie 2 days).
81
- # config.confirm_within = 2.days
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 = 2.hours
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 :"*/*" and "*/*" formats below is required to match Internet
191
- # Explorer requests.
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 http://github.com/plataformatec/devise/wiki/I18n
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
- inactive_signed_up: 'You have signed up successfully. However, we could not sign you in because your account is %{reason}.'
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 was successfully unlocked. You are now signed in.'
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.'
@@ -26,7 +26,6 @@ Dummy::Application.routes.draw do
26
26
  resources :posts
27
27
  end
28
28
  resources :news
29
- resources :puffer_users
30
29
  end
31
30
 
32
31
  namespace :orms do
@@ -1,10 +1,11 @@
1
- class CreateAdminProfiles < ActiveRecord::Migration
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
@@ -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 => 20111122203304) do
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
@@ -0,0 +1,4 @@
1
+ Fabricator :clearance_user do
2
+ email {Forgery::Internet.email_address}
3
+ password '123456'
4
+ end
@@ -0,0 +1,5 @@
1
+ Fabricator :puffer_user do
2
+ email {Forgery::Internet.email_address}
3
+ password '123456'
4
+ password_confirmation '123456'
5
+ end
@@ -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
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
  require 'lib/orm_adapter/base_shared'
3
2
 
4
3
  describe "ActiveRecordOrm" do
@@ -2,118 +2,122 @@ require 'spec_helper'
2
2
 
3
3
  shared_examples "an adapter" do
4
4
 
5
- def filter options = {}
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
- before do
17
- 5.times { Fabricate fabric }
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
- end
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
- it 'should return all searched records' do
37
- filter(:search => 'hel').should == nth(0, 1, 2, 3)
38
- end
16
+ context 'without params' do
39
17
 
40
- it 'should return searched records without conditioned' do
41
- filter(:search => 'hel', :conditions => {'select_field' => 'hello'}).should == nth(0, 3)
42
- end
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
- end
28
+ context 'search' do
49
29
 
50
- context 'select' do
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
- before do
53
- select_fields = %w(hello world hello hello world)
54
- boolean_fields = %w(true false false true false)
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
- it 'should return all conditioned records' do
61
- filter(:conditions => {'select_field' => 'hello'}).should == nth(0, 2, 3)
62
- end
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
- it 'should return all conditioned records' do
65
- filter(:conditions => {'boolean_field' => false}).should == nth(1, 2, 4)
66
- end
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
- end
52
+ context 'select' do
73
53
 
74
- context 'order' do
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
- before do
77
- integer_fields = %w(2, 3, 5, 4, 1)
78
- 5.times { |i|
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
- it 'should order records asc' do
84
- filter(:order => 'integer_field').should == nth(4, 0, 1, 3, 2)
85
- end
66
+ it 'should return all conditioned records' do
67
+ filter(:conditions => {'boolean_field' => false}).should =~ nth(1, 2, 4)
68
+ end
86
69
 
87
- it 'should order records asc' do
88
- filter(:order => ['integer_field', :asc]).should == nth(4, 0, 1, 3, 2)
89
- end
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
- end
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, :datetime_field => Time.now + i.hours
81
+ Fabricate fabric, :integer_field => integer_fields[i]
102
82
  }
103
83
  end
104
84
 
105
- it 'should return from till' do
106
- filter(:conditions => {'datetime_field' => Puffer::Filters::Diapason.new(Time.now + 0.9.hour, Time.now + 3.1.hours)}).should == nth(1, 2, 3)
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 return from' do
110
- filter(:conditions => {'datetime_field' => Puffer::Filters::Diapason.new(Time.now + 0.9.hour)}).should == nth(1, 2, 3, 4)
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 return till' do
114
- filter(:conditions => {'datetime_field' => Puffer::Filters::Diapason.new(nil, Time.now + 3.1.hours)}).should == nth(0, 1, 2, 3)
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