selections 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +18 -0
  2. data/CHANGELOG.md +3 -0
  3. data/Gemfile +4 -0
  4. data/{MIT-LICENSE → LICENSE.txt} +4 -2
  5. data/README.md +237 -0
  6. data/Rakefile +3 -29
  7. data/lib/selections.rb +22 -6
  8. data/lib/selections/belongs_to_selection.rb +20 -0
  9. data/lib/selections/form_builder_extensions.rb +86 -0
  10. data/lib/selections/selectable.rb +125 -0
  11. data/lib/selections/version.rb +1 -1
  12. data/selections.gemspec +38 -0
  13. data/spec/selections/selectable_spec.rb +220 -0
  14. data/spec/selections/selections_tag_spec.rb +203 -0
  15. data/spec/spec_helper.rb +30 -21
  16. metadata +99 -177
  17. data/README.rdoc +0 -3
  18. data/app/assets/javascripts/selections/application.js +0 -9
  19. data/app/assets/javascripts/selections/selections.js +0 -2
  20. data/app/assets/stylesheets/scaffold.css +0 -56
  21. data/app/assets/stylesheets/selections/application.css +0 -7
  22. data/app/assets/stylesheets/selections/selections.css +0 -4
  23. data/app/controllers/selections/application_controller.rb +0 -4
  24. data/app/controllers/selections/selections_controller.rb +0 -45
  25. data/app/helpers/selections/application_helper.rb +0 -4
  26. data/app/helpers/selections/selectors_helper.rb +0 -4
  27. data/app/models/selections/selection.rb +0 -83
  28. data/app/views/layouts/selections/application.html.erb +0 -1
  29. data/app/views/selections/selections/_form.html.erb +0 -41
  30. data/app/views/selections/selections/edit.html.erb +0 -6
  31. data/app/views/selections/selections/index.html.erb +0 -33
  32. data/app/views/selections/selections/new.html.erb +0 -5
  33. data/app/views/selections/selections/show.html.erb +0 -35
  34. data/config/initializers/selections.rb +0 -1
  35. data/config/routes.rb +0 -5
  36. data/db/migrate/20120114024459_create_selections_selections.rb +0 -15
  37. data/lib/selections/engine.rb +0 -5
  38. data/lib/selections/selection_select.rb +0 -24
  39. data/lib/tasks/selections_tasks.rake +0 -4
  40. data/spec/controllers/companies_controller_spec.rb +0 -10
  41. data/spec/controllers/selections/selections_controller_spec.rb +0 -165
  42. data/spec/dummy/Rakefile +0 -7
  43. data/spec/dummy/app/assets/javascripts/application.js +0 -9
  44. data/spec/dummy/app/assets/javascripts/companies.js +0 -2
  45. data/spec/dummy/app/assets/stylesheets/application.css +0 -7
  46. data/spec/dummy/app/assets/stylesheets/companies.css +0 -4
  47. data/spec/dummy/app/assets/stylesheets/scaffold.css +0 -56
  48. data/spec/dummy/app/controllers/application_controller.rb +0 -2
  49. data/spec/dummy/app/controllers/companies_controller.rb +0 -83
  50. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  51. data/spec/dummy/app/helpers/companies_helper.rb +0 -2
  52. data/spec/dummy/app/models/company.rb +0 -7
  53. data/spec/dummy/app/views/companies/_form.html.erb +0 -3
  54. data/spec/dummy/app/views/companies/edit.html.erb +0 -4
  55. data/spec/dummy/app/views/companies/index.html.erb +0 -27
  56. data/spec/dummy/app/views/companies/new.html.erb +0 -5
  57. data/spec/dummy/app/views/companies/show.html.erb +0 -20
  58. data/spec/dummy/app/views/layouts/application.html.erb +0 -11
  59. data/spec/dummy/config.ru +0 -4
  60. data/spec/dummy/config/application.rb +0 -45
  61. data/spec/dummy/config/boot.rb +0 -10
  62. data/spec/dummy/config/database.yml +0 -25
  63. data/spec/dummy/config/environment.rb +0 -5
  64. data/spec/dummy/config/environments/development.rb +0 -30
  65. data/spec/dummy/config/environments/production.rb +0 -60
  66. data/spec/dummy/config/environments/test.rb +0 -42
  67. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  68. data/spec/dummy/config/initializers/inflections.rb +0 -10
  69. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  70. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  71. data/spec/dummy/config/initializers/session_store.rb +0 -8
  72. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  73. data/spec/dummy/config/locales/en.yml +0 -5
  74. data/spec/dummy/config/routes.rb +0 -6
  75. data/spec/dummy/db/development.sqlite3 +0 -0
  76. data/spec/dummy/db/migrate/20120114125226_create_selections_selections.rb +0 -15
  77. data/spec/dummy/db/migrate/20120115055119_create_companies.rb +0 -12
  78. data/spec/dummy/db/schema.rb +0 -38
  79. data/spec/dummy/db/test.sqlite3 +0 -0
  80. data/spec/dummy/log/development.log +0 -94
  81. data/spec/dummy/log/test.log +0 -26360
  82. data/spec/dummy/public/404.html +0 -26
  83. data/spec/dummy/public/422.html +0 -26
  84. data/spec/dummy/public/500.html +0 -26
  85. data/spec/dummy/public/favicon.ico +0 -0
  86. data/spec/dummy/script/rails +0 -6
  87. data/spec/helpers/selections/selections_helper_spec.rb +0 -15
  88. data/spec/models/company_spec.rb +0 -7
  89. data/spec/models/selections/selection_spec.rb +0 -219
  90. data/spec/routing/selections/selections_routing_spec.rb +0 -35
  91. data/spec/support/controller_route_fix.rb +0 -33
  92. data/spec/support/factories/company_factory.rb +0 -5
  93. data/spec/support/factories/selection_factory.rb +0 -5
  94. data/spec/views/companies/edit.html.erb_spec.rb +0 -76
  95. data/spec/views/companies/new.html.erb_spec.rb +0 -78
  96. data/spec/views/selections/selections/edit.html.erb_spec.rb +0 -28
  97. data/spec/views/selections/selections/index.html.erb_spec.rb +0 -40
  98. data/spec/views/selections/selections/new.html.erb_spec.rb +0 -28
  99. data/spec/views/selections/selections/show.html.erb_spec.rb +0 -30
@@ -1,78 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "companies/new" do
4
- context "default selection list" do
5
- before do
6
- @company = Factory.build(:company)
7
- assign(:company, @company)
8
- @parent_10 = Factory(:selection, :system_code => "state")
9
- @child_11 = Factory(:selection, :parent => @parent_10)
10
- @child_12 = Factory(:selection, :parent => @parent_10, :is_default => true)
11
- @child_13 = Factory(:selection, :parent => @parent_10)
12
- @child_14 = Factory(:selection, :parent => @parent_10)
13
- @parent_20 = Factory(:selection, :system_code => "priority")
14
- @child_21 = Factory(:selection, :parent => @parent_20, :is_default => true)
15
- @child_22 = Factory(:selection, :parent => @parent_21)
16
- end
17
-
18
- it "should display error when field does not match system_code" do
19
- assign(:field, :not_match)
20
- render
21
- assert_select "form", "Invalid system_code"
22
- end
23
-
24
- context "standard" do
25
- before(:each) do
26
- assign(:field, :state)
27
- assign(:options, nil)
28
- assign(:html_options, nil)
29
- end
30
-
31
- it "selection with default item" do
32
- render
33
- assert_select "form", :action => companies_path, :method => "post" do
34
- assert_select "select#company_state_id[name='company[state_id]']" do
35
- selected_options(@parent_10.children, @child_12, false)
36
- end
37
- end
38
- end
39
- it "selection with no default set" do
40
- @child_12.update_attribute(:is_default, false)
41
- render
42
- selected_options(@parent_10.children, nil, true)
43
- end
44
- it "selection with archived item" do
45
- @child_13.update_attribute(:archived, true)
46
- render
47
- selected_options(@parent_10.children-[@child_13], @child_12, false)
48
- end
49
- it "selection with archived default item" do
50
- @child_12.update_attribute(:archived, true)
51
- render
52
- selected_options(@parent_10.children-[@child_12], nil, true)
53
- end
54
- it "should have blank selection when :include_blank is true" do
55
- assign(:options, {:include_blank => true})
56
- render
57
- selected_options(@parent_10.children, @child_12, true)
58
- end
59
- it "should not have blank when no default and :include_blank is false" do
60
- assign(:options, {:include_blank => false})
61
- @child_12.update_attribute(:is_default, false)
62
- render
63
- selected_options(@parent_10.children, nil, false)
64
- end
65
- it "it should use fieldname which does not match a system_code" do
66
- assign(:options, {:system_code => "state"})
67
- assign(:field, :genre)
68
- render
69
- selected_options(@parent_10.children, @child_12, false)
70
- end
71
- it "should use the value in state if set (and ignore default) - when page not saved and reloads" do
72
- @company.state = @child_14
73
- render
74
- selected_options(@parent_10.children, @child_14, false)
75
- end
76
- end
77
- end
78
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "selections/edit" do
4
- before(:each) do
5
- @selection = assign(:selection, stub_model(Selection,
6
- :name => "MyString",
7
- :parent_id => 1,
8
- :system_code => "MyString",
9
- :position => 1,
10
- :is_default => false,
11
- :is_system => false
12
- ))
13
- end
14
-
15
- it "renders the edit selection form" do
16
- render
17
-
18
- # Run the generator again with the --webrat flag if you want to use webrat matchers
19
- assert_select "form", :action => selections_path(@selection), :method => "post" do
20
- assert_select "input#selection_name", :name => "selection[name]"
21
- assert_select "input#selection_parent_id", :name => "selection[parent_id]"
22
- assert_select "input#selection_system_code", :name => "selection[system_code]"
23
- assert_select "input#selection_position", :name => "selection[position]"
24
- assert_select "input#selection_is_default", :name => "selection[is_default]"
25
- assert_select "input#selection_is_system", :name => "selection[is_system]"
26
- end
27
- end
28
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "selections/index" do
4
- before(:each) do
5
- assign(:selections, [
6
- stub_model(Selection,
7
- :name => "Name",
8
- :parent_id => 1,
9
- :system_code => "System Code",
10
- :position => 1,
11
- :is_default => false,
12
- :is_system => false
13
- ),
14
- stub_model(Selection,
15
- :name => "Name",
16
- :parent_id => 1,
17
- :system_code => "System Code",
18
- :position => 1,
19
- :is_default => false,
20
- :is_system => false
21
- )
22
- ])
23
- end
24
-
25
- it "renders a list of selections" do
26
- render
27
- # Run the generator again with the --webrat flag if you want to use webrat matchers
28
- assert_select "tr>td", :text => "Name".to_s, :count => 2
29
- # Run the generator again with the --webrat flag if you want to use webrat matchers
30
- assert_select "tr>td", :text => 1.to_s, :count => 2
31
- # Run the generator again with the --webrat flag if you want to use webrat matchers
32
- assert_select "tr>td", :text => "System Code".to_s, :count => 2
33
- # Run the generator again with the --webrat flag if you want to use webrat matchers
34
- assert_select "tr>td", :text => 1.to_s, :count => 2
35
- # Run the generator again with the --webrat flag if you want to use webrat matchers
36
- assert_select "tr>td", :text => false.to_s, :count => 2
37
- # Run the generator again with the --webrat flag if you want to use webrat matchers
38
- assert_select "tr>td", :text => false.to_s, :count => 2
39
- end
40
- end
@@ -1,28 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "selections/new" do
4
- before(:each) do
5
- assign(:selection, stub_model(Selection,
6
- :name => "MyString",
7
- :parent_id => 1,
8
- :system_code => "MyString",
9
- :position => 1,
10
- :is_default => false,
11
- :is_system => false
12
- ).as_new_record)
13
- end
14
-
15
- it "renders new selection form" do
16
- render
17
-
18
- # Run the generator again with the --webrat flag if you want to use webrat matchers
19
- assert_select "form", :action => selections_path, :method => "post" do
20
- assert_select "input#selection_name", :name => "selection[name]"
21
- assert_select "input#selection_parent_id", :name => "selection[parent_id]"
22
- assert_select "input#selection_system_code", :name => "selection[system_code]"
23
- assert_select "input#selection_position", :name => "selection[position]"
24
- assert_select "input#selection_is_default", :name => "selection[is_default]"
25
- assert_select "input#selection_is_system", :name => "selection[is_system]"
26
- end
27
- end
28
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "selections/show" do
4
- before(:each) do
5
- @selection = assign(:selection, stub_model(Selection,
6
- :name => "Name",
7
- :parent_id => 1,
8
- :system_code => "System Code",
9
- :position => 1,
10
- :is_default => false,
11
- :is_system => false
12
- ))
13
- end
14
-
15
- it "renders attributes in <p>" do
16
- render
17
- # Run the generator again with the --webrat flag if you want to use webrat matchers
18
- rendered.should match(/Name/)
19
- # Run the generator again with the --webrat flag if you want to use webrat matchers
20
- rendered.should match(/1/)
21
- # Run the generator again with the --webrat flag if you want to use webrat matchers
22
- rendered.should match(/System Code/)
23
- # Run the generator again with the --webrat flag if you want to use webrat matchers
24
- rendered.should match(/1/)
25
- # Run the generator again with the --webrat flag if you want to use webrat matchers
26
- rendered.should match(/false/)
27
- # Run the generator again with the --webrat flag if you want to use webrat matchers
28
- rendered.should match(/false/)
29
- end
30
- end