jtable-rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +10 -0
  5. data/Gemfile.lock +94 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +2 -0
  8. data/Rakefile +42 -0
  9. data/VERSION +1 -0
  10. data/jtable-rails.gemspec +136 -0
  11. data/lib/jtable-rails.rb +5 -0
  12. data/lib/jtable-rails/action_controller.rb +8 -0
  13. data/lib/jtable-rails/active_record.rb +83 -0
  14. data/spec/controller_specs/people_controller_spec.rb +30 -0
  15. data/spec/fabricators/person.rb +9 -0
  16. data/spec/model_specs/person_spec.rb +73 -0
  17. data/spec/spec_helper.rb +16 -0
  18. data/spec/support/rails_app/.gitignore +4 -0
  19. data/spec/support/rails_app/Gemfile +5 -0
  20. data/spec/support/rails_app/Gemfile.lock +82 -0
  21. data/spec/support/rails_app/Rakefile +7 -0
  22. data/spec/support/rails_app/app/controllers/application_controller.rb +3 -0
  23. data/spec/support/rails_app/app/controllers/people_controller.rb +83 -0
  24. data/spec/support/rails_app/app/helpers/application_helper.rb +2 -0
  25. data/spec/support/rails_app/app/helpers/people_helper.rb +2 -0
  26. data/spec/support/rails_app/app/models/person.rb +3 -0
  27. data/spec/support/rails_app/app/views/layouts/application.html.erb +14 -0
  28. data/spec/support/rails_app/app/views/people/_form.html.erb +41 -0
  29. data/spec/support/rails_app/app/views/people/edit.html.erb +6 -0
  30. data/spec/support/rails_app/app/views/people/index.html.erb +33 -0
  31. data/spec/support/rails_app/app/views/people/new.html.erb +5 -0
  32. data/spec/support/rails_app/app/views/people/show.html.erb +35 -0
  33. data/spec/support/rails_app/config.ru +4 -0
  34. data/spec/support/rails_app/config/application.rb +42 -0
  35. data/spec/support/rails_app/config/boot.rb +13 -0
  36. data/spec/support/rails_app/config/database.yml +22 -0
  37. data/spec/support/rails_app/config/environment.rb +5 -0
  38. data/spec/support/rails_app/config/environments/development.rb +26 -0
  39. data/spec/support/rails_app/config/environments/production.rb +49 -0
  40. data/spec/support/rails_app/config/environments/test.rb +35 -0
  41. data/spec/support/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  42. data/spec/support/rails_app/config/initializers/inflections.rb +10 -0
  43. data/spec/support/rails_app/config/initializers/mime_types.rb +5 -0
  44. data/spec/support/rails_app/config/initializers/secret_token.rb +7 -0
  45. data/spec/support/rails_app/config/initializers/session_store.rb +8 -0
  46. data/spec/support/rails_app/config/locales/en.yml +5 -0
  47. data/spec/support/rails_app/config/routes.rb +60 -0
  48. data/spec/support/rails_app/db/migrate/20110207142623_create_people.rb +18 -0
  49. data/spec/support/rails_app/db/schema.rb +26 -0
  50. data/spec/support/rails_app/db/seeds.rb +7 -0
  51. data/spec/support/rails_app/public/stylesheets/scaffold.css +56 -0
  52. data/spec/support/rails_app/script/rails +6 -0
  53. metadata +236 -0
@@ -0,0 +1,9 @@
1
+ Fabricator(:person) do
2
+ [:first_name, :last_name, :age, :date_of_birth, :gender, :alive]
3
+ first_name {Fabricate.sequence(:person_first_name) {|i| "FirstName #{i}"}}
4
+ last_name {Fabricate.sequence(:person_last_name) {|i| "LastName #{i}"}}
5
+ age {Fabricate.sequence(:person_age)}
6
+ date_of_birth {Fabricate.sequence(:person_date_of_birth).years.ago}
7
+ gender {Fabricate.sequence(:person_gender) {|i| i%2==0 ? "Male" : "Female"}}
8
+ alive {rand(10).even?}
9
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Person" do
4
+ before(:each) do
5
+ 10.times do |i|
6
+ Fabricate(:person)
7
+ end
8
+
9
+ @params = {
10
+ :searchable_columns => ["first_name", "last_name", "age", "date_of_birth", "gender"],
11
+ :column_search => {},
12
+ :limit => "5",
13
+ :offset => "0",
14
+ :search => "",
15
+ :sort_column => "",
16
+ :sort_direction => ""
17
+ }
18
+ end
19
+
20
+ it "should have the jtable scopes and methods" do
21
+ Person.respond_to?(:jtable).should be_true
22
+ Person.respond_to?(:jtable_search).should be_true
23
+ Person.respond_to?(:jtable_single_search).should be_true
24
+ Person.respond_to?(:jtable_order).should be_true
25
+ Person.respond_to?(:jtable_paginate).should be_true
26
+ Person.respond_to?(:jtable_default).should be_true
27
+ Person.respond_to?(:jtable_query).should be_true
28
+ [:first_name, :last_name, :age, :date_of_birth, :gender, :alive].each do |attribute|
29
+ Person.respond_to?("jtable_search_#{attribute}").should be_true
30
+ Person.respond_to?("jtable_order_#{attribute}").should be_true
31
+ end
32
+ end
33
+
34
+ it "should load initial set" do
35
+ Person.jtable_query(@params).to_json.should eql(Person.all.to_json)
36
+ end
37
+
38
+ it "should paginate" do
39
+ Person.jtable_query(@params).jtable_paginate(@params[:limit], @params[:offset]).to_json.should eql(Person.limit(5).offset(0).to_json)
40
+ @params[:offset] = 5
41
+ Person.jtable_query(@params).jtable_paginate(@params[:limit], @params[:offset]).to_json.should eql(Person.limit(5).offset(5).to_json)
42
+ end
43
+
44
+ it "should search" do
45
+ person_1 = Person.first
46
+ person_2 = Person.last
47
+ person_1.first_name = "John"
48
+ person_1.last_name = "Smith"
49
+ person_1.save
50
+ person_2.first_name = "Johnathan"
51
+ person_2.last_name = "Smith"
52
+ person_2.save
53
+ @params[:search] = "john smith"
54
+ Person.jtable_query(@params).to_json.should eql(Person.where(['(first_name LIKE ? OR last_name LIKE ?) AND (first_name LIKE ? OR last_name LIKE ?)', "%john%", "%john%", "%smith%", "%smith%"]).to_json)
55
+ end
56
+
57
+ it "should single column search" do
58
+ person_1 = Person.first
59
+ person_2 = Person.last
60
+ person_1.first_name = "John"
61
+ person_1.save
62
+ person_2.first_name = "Johnathan"
63
+ person_2.save
64
+ @params[:column_search][:first_name] = "john"
65
+ Person.jtable_query(@params).to_json.should eql(Person.where(['(first_name LIKE ?)', "%john%"]).to_json)
66
+ end
67
+
68
+ it "should order" do
69
+ @params[:sort_column] = "age"
70
+ @params[:sort_direction] = "ASC"
71
+ Person.jtable_query(@params).to_json.should eql(Person.order('age ASC').to_json)
72
+ end
73
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'jtable-rails'
5
+
6
+ require 'support/rails_app/config/environment.rb'
7
+
8
+ Dir[File.expand_path(File.join(File.dirname(__FILE__), 'fabricators', '**', '*.rb'))].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ config.before(:each) do
12
+ [Person].each do |model|
13
+ model.destroy_all
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'rails', '3.0.3'
4
+ gem 'sqlite3-ruby', :require => 'sqlite3'
5
+ gem 'jtable-rails', :path => File.expand_path(File.dirname(__FILE__) + '/../../../.')
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: /Users/yelvert/projects/jtable/jtable-rails
3
+ specs:
4
+ jtable-rails (0.0.0)
5
+ rails (= 3.0.3)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ abstract (1.0.0)
11
+ actionmailer (3.0.3)
12
+ actionpack (= 3.0.3)
13
+ mail (~> 2.2.9)
14
+ actionpack (3.0.3)
15
+ activemodel (= 3.0.3)
16
+ activesupport (= 3.0.3)
17
+ builder (~> 2.1.2)
18
+ erubis (~> 2.6.6)
19
+ i18n (~> 0.4)
20
+ rack (~> 1.2.1)
21
+ rack-mount (~> 0.6.13)
22
+ rack-test (~> 0.5.6)
23
+ tzinfo (~> 0.3.23)
24
+ activemodel (3.0.3)
25
+ activesupport (= 3.0.3)
26
+ builder (~> 2.1.2)
27
+ i18n (~> 0.4)
28
+ activerecord (3.0.3)
29
+ activemodel (= 3.0.3)
30
+ activesupport (= 3.0.3)
31
+ arel (~> 2.0.2)
32
+ tzinfo (~> 0.3.23)
33
+ activeresource (3.0.3)
34
+ activemodel (= 3.0.3)
35
+ activesupport (= 3.0.3)
36
+ activesupport (3.0.3)
37
+ arel (2.0.7)
38
+ builder (2.1.2)
39
+ erubis (2.6.6)
40
+ abstract (>= 1.0.0)
41
+ i18n (0.5.0)
42
+ mail (2.2.15)
43
+ activesupport (>= 2.3.6)
44
+ i18n (>= 0.4.0)
45
+ mime-types (~> 1.16)
46
+ treetop (~> 1.4.8)
47
+ mime-types (1.16)
48
+ polyglot (0.3.1)
49
+ rack (1.2.1)
50
+ rack-mount (0.6.13)
51
+ rack (>= 1.0.0)
52
+ rack-test (0.5.7)
53
+ rack (>= 1.0)
54
+ rails (3.0.3)
55
+ actionmailer (= 3.0.3)
56
+ actionpack (= 3.0.3)
57
+ activerecord (= 3.0.3)
58
+ activeresource (= 3.0.3)
59
+ activesupport (= 3.0.3)
60
+ bundler (~> 1.0)
61
+ railties (= 3.0.3)
62
+ railties (3.0.3)
63
+ actionpack (= 3.0.3)
64
+ activesupport (= 3.0.3)
65
+ rake (>= 0.8.7)
66
+ thor (~> 0.14.4)
67
+ rake (0.8.7)
68
+ sqlite3 (1.3.3)
69
+ sqlite3-ruby (1.3.3)
70
+ sqlite3 (>= 1.3.3)
71
+ thor (0.14.6)
72
+ treetop (1.4.9)
73
+ polyglot (>= 0.3.1)
74
+ tzinfo (0.3.24)
75
+
76
+ PLATFORMS
77
+ ruby
78
+
79
+ DEPENDENCIES
80
+ jtable-rails!
81
+ rails (= 3.0.3)
82
+ sqlite3-ruby
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ RailsApp::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,83 @@
1
+ class PeopleController < ApplicationController
2
+ # GET /people
3
+ # GET /people.xml
4
+ def index
5
+ @people = Person.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @people }
10
+ end
11
+ end
12
+
13
+ # GET /people/1
14
+ # GET /people/1.xml
15
+ def show
16
+ @person = Person.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @person }
21
+ end
22
+ end
23
+
24
+ # GET /people/new
25
+ # GET /people/new.xml
26
+ def new
27
+ @person = Person.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.xml { render :xml => @person }
32
+ end
33
+ end
34
+
35
+ # GET /people/1/edit
36
+ def edit
37
+ @person = Person.find(params[:id])
38
+ end
39
+
40
+ # POST /people
41
+ # POST /people.xml
42
+ def create
43
+ @person = Person.new(params[:person])
44
+
45
+ respond_to do |format|
46
+ if @person.save
47
+ format.html { redirect_to(@person, :notice => 'Person was successfully created.') }
48
+ format.xml { render :xml => @person, :status => :created, :location => @person }
49
+ else
50
+ format.html { render :action => "new" }
51
+ format.xml { render :xml => @person.errors, :status => :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ # PUT /people/1
57
+ # PUT /people/1.xml
58
+ def update
59
+ @person = Person.find(params[:id])
60
+
61
+ respond_to do |format|
62
+ if @person.update_attributes(params[:person])
63
+ format.html { redirect_to(@person, :notice => 'Person was successfully updated.') }
64
+ format.xml { head :ok }
65
+ else
66
+ format.html { render :action => "edit" }
67
+ format.xml { render :xml => @person.errors, :status => :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE /people/1
73
+ # DELETE /people/1.xml
74
+ def destroy
75
+ @person = Person.find(params[:id])
76
+ @person.destroy
77
+
78
+ respond_to do |format|
79
+ format.html { redirect_to(people_url) }
80
+ format.xml { head :ok }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PeopleHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class Person < ActiveRecord::Base
2
+ jtable :first_name, :last_name, :age, :date_of_birth, :gender, :alive
3
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>RailsApp</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,41 @@
1
+ <%= form_for(@person) do |f| %>
2
+ <% if @person.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@person.errors.count, "error") %> prohibited this person from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @person.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :first_name %><br />
16
+ <%= f.text_field :first_name %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :last_name %><br />
20
+ <%= f.text_field :last_name %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :age %><br />
24
+ <%= f.text_field :age %>
25
+ </div>
26
+ <div class="field">
27
+ <%= f.label :date_of_birth %><br />
28
+ <%= f.date_select :date_of_birth %>
29
+ </div>
30
+ <div class="field">
31
+ <%= f.label :gender %><br />
32
+ <%= f.text_field :gender %>
33
+ </div>
34
+ <div class="field">
35
+ <%= f.label :alive %><br />
36
+ <%= f.check_box :alive %>
37
+ </div>
38
+ <div class="actions">
39
+ <%= f.submit %>
40
+ </div>
41
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing person</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @person %> |
6
+ <%= link_to 'Back', people_path %>
@@ -0,0 +1,33 @@
1
+ <h1>Listing people</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>First name</th>
6
+ <th>Last name</th>
7
+ <th>Age</th>
8
+ <th>Date of birth</th>
9
+ <th>Gender</th>
10
+ <th>Alive</th>
11
+ <th></th>
12
+ <th></th>
13
+ <th></th>
14
+ </tr>
15
+
16
+ <% @people.each do |person| %>
17
+ <tr>
18
+ <td><%= person.first_name %></td>
19
+ <td><%= person.last_name %></td>
20
+ <td><%= person.age %></td>
21
+ <td><%= person.date_of_birth %></td>
22
+ <td><%= person.gender %></td>
23
+ <td><%= person.alive %></td>
24
+ <td><%= link_to 'Show', person %></td>
25
+ <td><%= link_to 'Edit', edit_person_path(person) %></td>
26
+ <td><%= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete %></td>
27
+ </tr>
28
+ <% end %>
29
+ </table>
30
+
31
+ <br />
32
+
33
+ <%= link_to 'New Person', new_person_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New person</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', people_path %>
@@ -0,0 +1,35 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>First name:</b>
5
+ <%= @person.first_name %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Last name:</b>
10
+ <%= @person.last_name %>
11
+ </p>
12
+
13
+ <p>
14
+ <b>Age:</b>
15
+ <%= @person.age %>
16
+ </p>
17
+
18
+ <p>
19
+ <b>Date of birth:</b>
20
+ <%= @person.date_of_birth %>
21
+ </p>
22
+
23
+ <p>
24
+ <b>Gender:</b>
25
+ <%= @person.gender %>
26
+ </p>
27
+
28
+ <p>
29
+ <b>Alive:</b>
30
+ <%= @person.alive %>
31
+ </p>
32
+
33
+
34
+ <%= link_to 'Edit', edit_person_path(@person) %> |
35
+ <%= link_to 'Back', people_path %>