selections 0.0.1

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 (89) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +31 -0
  4. data/app/assets/javascripts/selections/application.js +9 -0
  5. data/app/assets/javascripts/selections/selections.js +2 -0
  6. data/app/assets/stylesheets/scaffold.css +56 -0
  7. data/app/assets/stylesheets/selections/application.css +7 -0
  8. data/app/assets/stylesheets/selections/selections.css +4 -0
  9. data/app/controllers/selections/application_controller.rb +4 -0
  10. data/app/controllers/selections/selections_controller.rb +45 -0
  11. data/app/helpers/selections/application_helper.rb +4 -0
  12. data/app/helpers/selections/selectors_helper.rb +4 -0
  13. data/app/models/selections/selection.rb +83 -0
  14. data/app/views/layouts/selections/application.html.erb +1 -0
  15. data/app/views/selections/selections/_form.html.erb +41 -0
  16. data/app/views/selections/selections/edit.html.erb +6 -0
  17. data/app/views/selections/selections/index.html.erb +33 -0
  18. data/app/views/selections/selections/new.html.erb +5 -0
  19. data/app/views/selections/selections/show.html.erb +35 -0
  20. data/config/initializers/selections.rb +1 -0
  21. data/config/routes.rb +5 -0
  22. data/db/migrate/20120114024459_create_selections_selections.rb +15 -0
  23. data/lib/selections.rb +7 -0
  24. data/lib/selections/engine.rb +5 -0
  25. data/lib/selections/selection_select.rb +24 -0
  26. data/lib/selections/version.rb +3 -0
  27. data/lib/tasks/selections_tasks.rake +4 -0
  28. data/spec/controllers/companies_controller_spec.rb +10 -0
  29. data/spec/controllers/selections/selections_controller_spec.rb +165 -0
  30. data/spec/dummy/Rakefile +7 -0
  31. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  32. data/spec/dummy/app/assets/javascripts/companies.js +2 -0
  33. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  34. data/spec/dummy/app/assets/stylesheets/companies.css +4 -0
  35. data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
  36. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  37. data/spec/dummy/app/controllers/companies_controller.rb +83 -0
  38. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  39. data/spec/dummy/app/helpers/companies_helper.rb +2 -0
  40. data/spec/dummy/app/models/company.rb +7 -0
  41. data/spec/dummy/app/views/companies/_form.html.erb +3 -0
  42. data/spec/dummy/app/views/companies/edit.html.erb +4 -0
  43. data/spec/dummy/app/views/companies/index.html.erb +27 -0
  44. data/spec/dummy/app/views/companies/new.html.erb +5 -0
  45. data/spec/dummy/app/views/companies/show.html.erb +20 -0
  46. data/spec/dummy/app/views/layouts/application.html.erb +11 -0
  47. data/spec/dummy/config.ru +4 -0
  48. data/spec/dummy/config/application.rb +45 -0
  49. data/spec/dummy/config/boot.rb +10 -0
  50. data/spec/dummy/config/database.yml +25 -0
  51. data/spec/dummy/config/environment.rb +5 -0
  52. data/spec/dummy/config/environments/development.rb +30 -0
  53. data/spec/dummy/config/environments/production.rb +60 -0
  54. data/spec/dummy/config/environments/test.rb +42 -0
  55. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  56. data/spec/dummy/config/initializers/inflections.rb +10 -0
  57. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  58. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  59. data/spec/dummy/config/initializers/session_store.rb +8 -0
  60. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  61. data/spec/dummy/config/locales/en.yml +5 -0
  62. data/spec/dummy/config/routes.rb +6 -0
  63. data/spec/dummy/db/development.sqlite3 +0 -0
  64. data/spec/dummy/db/migrate/20120114125226_create_selections_selections.rb +15 -0
  65. data/spec/dummy/db/migrate/20120115055119_create_companies.rb +12 -0
  66. data/spec/dummy/db/schema.rb +38 -0
  67. data/spec/dummy/db/test.sqlite3 +0 -0
  68. data/spec/dummy/log/development.log +94 -0
  69. data/spec/dummy/log/test.log +26360 -0
  70. data/spec/dummy/public/404.html +26 -0
  71. data/spec/dummy/public/422.html +26 -0
  72. data/spec/dummy/public/500.html +26 -0
  73. data/spec/dummy/public/favicon.ico +0 -0
  74. data/spec/dummy/script/rails +6 -0
  75. data/spec/helpers/selections/selections_helper_spec.rb +15 -0
  76. data/spec/models/company_spec.rb +7 -0
  77. data/spec/models/selections/selection_spec.rb +219 -0
  78. data/spec/routing/selections/selections_routing_spec.rb +35 -0
  79. data/spec/spec_helper.rb +30 -0
  80. data/spec/support/controller_route_fix.rb +33 -0
  81. data/spec/support/factories/company_factory.rb +5 -0
  82. data/spec/support/factories/selection_factory.rb +5 -0
  83. data/spec/views/companies/edit.html.erb_spec.rb +76 -0
  84. data/spec/views/companies/new.html.erb_spec.rb +78 -0
  85. data/spec/views/selections/selections/edit.html.erb_spec.rb +28 -0
  86. data/spec/views/selections/selections/index.html.erb_spec.rb +40 -0
  87. data/spec/views/selections/selections/new.html.erb_spec.rb +28 -0
  88. data/spec/views/selections/selections/show.html.erb_spec.rb +30 -0
  89. metadata +260 -0
@@ -0,0 +1,7 @@
1
+ require "rails"
2
+ require "selections/engine"
3
+ require "acts_as_tree"
4
+ require "selections/selection_select"
5
+
6
+ #module Selections
7
+ #end
@@ -0,0 +1,5 @@
1
+ module Selections
2
+ class Engine < Rails::Engine
3
+ isolate_namespace Selections
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ module SelectionSelect
2
+ def selections field, options = {}, html_options = {}
3
+ options ||= {}
4
+ html_options ||= {}
5
+ system_code = options[:system_code] || field
6
+ system_code = Selections::Selection.find_by_system_code(system_code.to_s)
7
+ if system_code
8
+ items = system_code.children
9
+ field_id = (field.to_s + "_id").to_sym
10
+ if object.new_record? && object.send(field_id).nil?
11
+ default = items.find_by_is_default(true)
12
+ object.send(field_id.to_s+"=", default.id) if default && !default.archived
13
+ end
14
+ options[:include_blank] = true if object.send(field_id).blank? && options[:include_blank].nil?
15
+ #TODO add default style
16
+ #html_options[:style] ||=
17
+ select field_id, items.filter_archived_except_selected(object.send(field_id)).map {|item| [item.name, item.id]}, options, html_options
18
+ else
19
+ "Invalid system_code"
20
+ end
21
+ end
22
+ end
23
+
24
+ ActionView::Helpers::FormBuilder.send :include, SelectionSelect
@@ -0,0 +1,3 @@
1
+ module Selections
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :selections do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ describe CompaniesController do
3
+
4
+ describe "GET new" do
5
+ it "assigns a new selection as @selection" do
6
+ get :new
7
+ assigns(:company).should be_a_new(Company)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,165 @@
1
+ require 'spec_helper'
2
+
3
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
4
+ # It demonstrates how one might use RSpec to specify the controller code that
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+ #
15
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
20
+ module Selections
21
+ describe SelectionsController do
22
+
23
+ # This should return the minimal set of attributes required to create a valid
24
+ # Selection. As you add validations to Selection, be sure to
25
+ # update the return value of this method accordingly.
26
+ def valid_attributes
27
+ Factory.build(:selection).attributes
28
+ end
29
+
30
+ # This should return the minimal set of values that should be in the session
31
+ # in order to pass any filters (e.g. authentication) defined in
32
+ # SelectionsController. Be sure to keep this updated too.
33
+ def valid_session
34
+ {}
35
+ end
36
+
37
+ describe "GET index" do
38
+ it "assigns all selections as @selections" do
39
+ selection = Selection.create! valid_attributes
40
+ get :index, {}, valid_session
41
+ assigns(:selections).should eq([selection])
42
+ end
43
+ end
44
+
45
+ describe "GET show" do
46
+ it "assigns the requested selection as @selection" do
47
+ selection = Selection.create! valid_attributes
48
+ get :show, {:id => selection.to_param}, valid_session
49
+ assigns(:selection).should eq(selection)
50
+ end
51
+ end
52
+
53
+ describe "GET new" do
54
+ it "assigns a new selection as @selection" do
55
+ get :new, {}, valid_session
56
+ assigns(:selection).should be_a_new(Selection)
57
+ end
58
+ end
59
+
60
+ describe "GET edit" do
61
+ it "assigns the requested selection as @selection" do
62
+ selection = Selection.create! valid_attributes
63
+ get :edit, {:id => selection.to_param}, valid_session
64
+ assigns(:selection).should eq(selection)
65
+ end
66
+ end
67
+
68
+ describe "POST create" do
69
+ describe "with valid params" do
70
+ it "creates a new Selection" do
71
+ expect {
72
+ post :create, {:selection => valid_attributes}, valid_session
73
+ }.to change(Selection, :count).by(1)
74
+ end
75
+
76
+ it "assigns a newly created selection as @selection" do
77
+ post :create, {:selection => valid_attributes}, valid_session
78
+ assigns(:selection).should be_a(Selection)
79
+ assigns(:selection).should be_persisted
80
+ end
81
+
82
+ it "redirects to the created selection" do
83
+ post :create, {:selection => valid_attributes}, valid_session
84
+ response.should redirect_to(Selection.last)
85
+ end
86
+ end
87
+
88
+ describe "with invalid params" do
89
+ it "assigns a newly created but unsaved selection as @selection" do
90
+ # Trigger the behavior that occurs when invalid params are submitted
91
+ Selection.any_instance.stub(:save).and_return(false)
92
+ post :create, {:selection => {}}, valid_session
93
+ assigns(:selection).should be_a_new(Selection)
94
+ end
95
+
96
+ it "re-renders the 'new' template" do
97
+ # Trigger the behavior that occurs when invalid params are submitted
98
+ Selection.any_instance.stub(:save).and_return(false)
99
+ post :create, {:selection => {}}, valid_session
100
+ response.should render_template("new")
101
+ end
102
+ end
103
+ end
104
+
105
+ describe "PUT update" do
106
+ describe "with valid params" do
107
+ it "updates the requested selection" do
108
+ selection = Selection.create! valid_attributes
109
+ # Assuming there are no other selections in the database, this
110
+ # specifies that the Selection created on the previous line
111
+ # receives the :update_attributes message with whatever params are
112
+ # submitted in the request.
113
+ Selection.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
114
+ put :update, {:id => selection.to_param, :selection => {'these' => 'params'}}, valid_session
115
+ end
116
+
117
+ it "assigns the requested selection as @selection" do
118
+ selection = Selection.create! valid_attributes
119
+ put :update, {:id => selection.to_param, :selection => valid_attributes}, valid_session
120
+ assigns(:selection).should eq(selection)
121
+ end
122
+
123
+ it "redirects to the selection" do
124
+ selection = Selection.create! valid_attributes
125
+ put :update, {:id => selection.to_param, :selection => valid_attributes.delete_if{|x| x=="system_code"}}, valid_session
126
+ response.should redirect_to(selection)
127
+ end
128
+ end
129
+
130
+ describe "with invalid params" do
131
+ it "assigns the selection as @selection" do
132
+ selection = Selection.create! valid_attributes
133
+ # Trigger the behavior that occurs when invalid params are submitted
134
+ Selection.any_instance.stub(:save).and_return(false)
135
+ put :update, {:id => selection.to_param, :selection => {}}, valid_session
136
+ assigns(:selection).should eq(selection)
137
+ end
138
+
139
+ it "re-renders the 'edit' template" do
140
+ selection = Selection.create! valid_attributes
141
+ # Trigger the behavior that occurs when invalid params are submitted
142
+ Selection.any_instance.stub(:save).and_return(false)
143
+ put :update, {:id => selection.to_param, :selection => {}}, valid_session
144
+ response.should render_template("edit")
145
+ end
146
+ end
147
+ end
148
+
149
+ describe "DELETE destroy" do
150
+ it "destroys the requested selection" do
151
+ selection = Selection.create! valid_attributes
152
+ expect {
153
+ delete :destroy, {:id => selection.to_param}, valid_session
154
+ }.to change(Selection, :count).by(-1)
155
+ end
156
+
157
+ it "redirects to the selections list" do
158
+ selection = Selection.create! valid_attributes
159
+ delete :destroy, {:id => selection.to_param}, valid_session
160
+ response.should redirect_to(selections_url)
161
+ end
162
+ end
163
+
164
+ end
165
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,9 @@
1
+ // This is a manifest file that'll be compiled into including all the files listed below.
2
+ // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
3
+ // be included in the compiled file accessible from http://example.com/assets/application.js
4
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
5
+ // the compiled file.
6
+ //
7
+ //= require jquery
8
+ //= require jquery_ujs
9
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,83 @@
1
+ class CompaniesController < ApplicationController
2
+ # GET /companies
3
+ # GET /companies.json
4
+ def index
5
+ @companies = Company.all
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.json { render json: @companies }
10
+ end
11
+ end
12
+
13
+ # GET /companies/1
14
+ # GET /companies/1.json
15
+ def show
16
+ @company = Company.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.json { render json: @company }
21
+ end
22
+ end
23
+
24
+ # GET /companies/new
25
+ # GET /companies/new.json
26
+ def new
27
+ @company = Company.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.json { render json: @company }
32
+ end
33
+ end
34
+
35
+ # GET /companies/1/edit
36
+ def edit
37
+ @company = Company.find(params[:id])
38
+ end
39
+
40
+ # POST /companies
41
+ # POST /companies.json
42
+ def create
43
+ @company = Company.new(params[:company])
44
+
45
+ respond_to do |format|
46
+ if @company.save
47
+ format.html { redirect_to @company, notice: 'Company was successfully created.' }
48
+ format.json { render json: @company, status: :created, location: @company }
49
+ else
50
+ format.html { render action: "new" }
51
+ format.json { render json: @company.errors, status: :unprocessable_entity }
52
+ end
53
+ end
54
+ end
55
+
56
+ # PUT /companies/1
57
+ # PUT /companies/1.json
58
+ def update
59
+ @company = Company.find(params[:id])
60
+
61
+ respond_to do |format|
62
+ if @company.update_attributes(params[:company])
63
+ format.html { redirect_to @company, notice: 'Company was successfully updated.' }
64
+ format.json { head :ok }
65
+ else
66
+ format.html { render action: "edit" }
67
+ format.json { render json: @company.errors, status: :unprocessable_entity }
68
+ end
69
+ end
70
+ end
71
+
72
+ # DELETE /companies/1
73
+ # DELETE /companies/1.json
74
+ def destroy
75
+ @company = Company.find(params[:id])
76
+ @company.destroy
77
+
78
+ respond_to do |format|
79
+ format.html { redirect_to companies_url }
80
+ format.json { head :ok }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module CompaniesHelper
2
+ end
@@ -0,0 +1,7 @@
1
+ class Company < ActiveRecord::Base
2
+
3
+ #TODO make this into selection_belongs_to
4
+ belongs_to :genre, :class_name => "Selection"
5
+ belongs_to :state, :class_name => "Selections::Selection"
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ <%= form_for(@company) do |f| %>
2
+ <%= f.selections @field, @options, @html_options %>
3
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <h1>Editing company</h1>
2
+
3
+ <%= render 'form' %>
4
+
@@ -0,0 +1,27 @@
1
+ <h1>Listing companies</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th>State</th>
7
+ <th>Genre</th>
8
+ <th></th>
9
+ <th></th>
10
+ <th></th>
11
+ </tr>
12
+
13
+ <% @companies.each do |company| %>
14
+ <tr>
15
+ <td><%= company.name %></td>
16
+ <td><%= company.state %></td>
17
+ <td><%= company.genre %></td>
18
+ <td><%= link_to 'Show', company %></td>
19
+ <td><%= link_to 'Edit', edit_company_path(company) %></td>
20
+ <td><%= link_to 'Destroy', company, confirm: 'Are you sure?', method: :delete %></td>
21
+ </tr>
22
+ <% end %>
23
+ </table>
24
+
25
+ <br />
26
+
27
+ <%= link_to 'New Company', new_company_path %>