scidea-schools 1.0.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.
- data/MIT-LICENSE +7 -0
- data/README.md +1 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/backbone_apps/models/school.js +13 -0
- data/app/assets/javascripts/backbone_apps/school_selector.js +396 -0
- data/app/assets/stylesheets/scidea/admin/pages/schools/edit_user.css +57 -0
- data/app/assets/stylesheets/scidea/admin/pages/schools/user_migrate.css +3 -0
- data/app/assets/stylesheets/scidea/pages/schools/user_profile.css +53 -0
- data/app/controllers/admin/schools_controller.rb +125 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/schools_controller.rb +58 -0
- data/app/controllers/test/scidea_schools_qunit_tests_controller.rb +51 -0
- data/app/helpers/schools_helper.rb +22 -0
- data/app/models/school.rb +93 -0
- data/app/themes/global_sass/_mixins.scss +5 -0
- data/app/themes/scidea/sass/_config.scss +7 -0
- data/app/themes/scidea/sass/admin/pages/schools/edit_user.scss +14 -0
- data/app/themes/scidea/sass/admin/pages/schools/user_migrate.scss +21 -0
- data/app/themes/scidea/sass/components/_schools.scss +170 -0
- data/app/themes/scidea/sass/pages/schools/user_profile.scss +6 -0
- data/app/views/admin/schools/_form.html.erb +20 -0
- data/app/views/admin/schools/_school.html.erb +10 -0
- data/app/views/admin/schools/_search.html.erb +14 -0
- data/app/views/admin/schools/confirm_migration.html.erb +17 -0
- data/app/views/admin/schools/edit.html.erb +7 -0
- data/app/views/admin/schools/index.html.erb +60 -0
- data/app/views/admin/schools/new.html.erb +5 -0
- data/app/views/admin/schools/new_migration.html.erb +76 -0
- data/app/views/admin/schools/show.html.erb +46 -0
- data/app/views/admin/users/_profile_show_school.html.erb +4 -0
- data/app/views/admin/users/_school_edit.html.erb +5 -0
- data/app/views/layouts/application.html.erb +14 -0
- data/app/views/schools/_form.html.erb +19 -0
- data/app/views/schools/_profile_form.html.erb +43 -0
- data/app/views/schools/_script_form.html.erb +3 -0
- data/app/views/schools/_search.html.erb +6 -0
- data/app/views/users/_school_edit.html.erb +5 -0
- data/config/compass.rb +28 -0
- data/config/cucumber.yml +8 -0
- data/config/environment.rb +18 -0
- data/config/initializers/schools_assets.rb +6 -0
- data/config/locales/en.yml +8 -0
- data/config/requirejs.yml +2 -0
- data/config/routes.rb +25 -0
- data/db/seeds.rb +14 -0
- data/features/applying_for_seminars.feature +0 -0
- data/features/edit_seminar_application.feature +42 -0
- data/features/manage_users.feature +23 -0
- data/features/qunit/qunit.feature +7 -0
- data/features/schools/manage_schools.feature +87 -0
- data/features/schools/schools.feature +208 -0
- data/features/step_definitions/audience_steps.rb +10 -0
- data/features/step_definitions/authentication_steps.rb +34 -0
- data/features/step_definitions/custom_form_steps.rb +33 -0
- data/features/step_definitions/email_steps.rb +206 -0
- data/features/step_definitions/menu_steps.rb +4 -0
- data/features/step_definitions/misc_steps.rb +52 -0
- data/features/step_definitions/qunit_steps.rb +20 -0
- data/features/step_definitions/registration_steps.rb +17 -0
- data/features/step_definitions/school_steps.rb +35 -0
- data/features/step_definitions/seminar_application_steps.rb +16 -0
- data/features/step_definitions/seminar_steps.rb +5 -0
- data/features/step_definitions/steps.rb +0 -0
- data/features/step_definitions/user_steps.rb +16 -0
- data/features/step_definitions/web_steps.rb +211 -0
- data/features/support/env.rb +21 -0
- data/features/support/hooks.rb +16 -0
- data/features/support/paths.rb +39 -0
- data/features/support/seed_user_roles.rb +16 -0
- data/features/support/selectors.rb +66 -0
- data/lib/generators/scidea/schools/migrations_generator.rb +14 -0
- data/lib/generators/scidea/schools/removal_migrations_generator.rb +14 -0
- data/lib/generators/scidea/schools/templates/removal/scidea_schools_99_remove.rb +35 -0
- data/lib/generators/scidea/schools/templates/scidea_schools_01_install.rb +35 -0
- data/lib/scidea/schools/engine.rb +31 -0
- data/lib/scidea/schools/models/ability.rb +28 -0
- data/lib/scidea/schools/models/profile.rb +25 -0
- data/lib/scidea/schools/version.rb +5 -0
- data/lib/scidea/schools.rb +5 -0
- data/lib/scidea-schools.rb +1 -0
- data/lib/tasks/db/seed.rake +5 -0
- data/qunit/helpers/qunit.js +1598 -0
- data/qunit/html_fixtures/backbone_apps/_school_selector.html.erb +16 -0
- data/qunit/test_runner.html.erb +25 -0
- data/qunit/tests/backbone_apps/school_selector.js +50 -0
- data/spec/factories/schools.rb +10 -0
- data/spec/models/ability_spec.rb +27 -0
- data/spec/models/profile_spec.rb +38 -0
- data/spec/models/school_spec.rb +304 -0
- data/spec/routing/admin/admin_schools_routing_spec.rb +47 -0
- data/spec/routing/schools_routing_spec.rb +35 -0
- data/spec/spec_helper.rb +48 -0
- metadata +249 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<%= test_fixture do %>
|
|
2
|
+
<% @user = User.new %>
|
|
3
|
+
<% @profile = Profile.new %>
|
|
4
|
+
<% Audience.find_or_create_by_name("Educator") %>
|
|
5
|
+
<script type="text/template" id="new-school-form-tpl">
|
|
6
|
+
<%= render :partial => 'schools/form' %>
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<%= render :partial => 'shared/form_errors', :locals => { :object => @user } %>
|
|
10
|
+
|
|
11
|
+
<%= semantic_form_for(@profile, :url => "#", :method => :get, :html => {:novalidate => nil, :autocomplete => "off"}) do |form| %>
|
|
12
|
+
<%= render :partial => "schools/profile_form", :locals => {:form => form} %>
|
|
13
|
+
<%= form.input :audience, :as => :select, :collection => Audience.all, :label => 'Profession', :required => true, :input_html => { :required => 'required', 'data-message' => Profile.error_message(:audience) } %>
|
|
14
|
+
<%= form.submit %>
|
|
15
|
+
<% end %>
|
|
16
|
+
<% end %>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<% @html_fixtures.each do |fixture| %>
|
|
2
|
+
<%= render fixture %>
|
|
3
|
+
<% end %>
|
|
4
|
+
|
|
5
|
+
<% head_js { javascript_include_tag 'qunit.js' } %>
|
|
6
|
+
|
|
7
|
+
<% css { stylesheet_link_tag 'qunit.css' } %>
|
|
8
|
+
|
|
9
|
+
<% page_title("QUnit Javascript Test Suite") %>
|
|
10
|
+
|
|
11
|
+
<div id="qunit-test-results">
|
|
12
|
+
<h1 id="qunit-header">Scitent QUnit Test Suite</h1>
|
|
13
|
+
<h2 id="qunit-banner"></h2>
|
|
14
|
+
<div id="qunit-testrunner-toolbar"></div>
|
|
15
|
+
<h2 id="qunit-userAgent"></h2>
|
|
16
|
+
<ol id="qunit-tests"></ol>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div id="qunit-fixture">
|
|
20
|
+
<%= yield :test_fixture %>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<%= page_js do %>
|
|
24
|
+
<%= raw @test_js %>
|
|
25
|
+
<% end %>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
require(['backbone_apps/school_selector'], function(plugin) {
|
|
2
|
+
var SchoolSelectorView = plugin($);
|
|
3
|
+
|
|
4
|
+
module("School Selector Tests");
|
|
5
|
+
|
|
6
|
+
test("SchoolSelectorView loaded", function() {
|
|
7
|
+
ok(SchoolSelectorView, "SchoolSelectorView defined");
|
|
8
|
+
|
|
9
|
+
var ssv = new SchoolSelectorView({
|
|
10
|
+
el : $('#profile-school').get(),
|
|
11
|
+
audienceField : $('#profile_audience_id')
|
|
12
|
+
});
|
|
13
|
+
ok(ssv, "SchoolSelectorView instantiable");
|
|
14
|
+
ok(ssv.newSchoolForm, "SchoolSelectorView#newSchoolForm accessible");
|
|
15
|
+
ok(ssv.stateDefs, "SchoolSelectorView#stateDefs accessible");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("zipcode validation", function() {
|
|
19
|
+
var audienceField = $('#profile_audience_id');
|
|
20
|
+
var ssv = new SchoolSelectorView({
|
|
21
|
+
el : $('#profile-school').get(),
|
|
22
|
+
audienceField : audienceField
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// School field only shows up when audience is set to Educator
|
|
26
|
+
var educatorOption = $('#profile_audience_id option:contains(Educator)');
|
|
27
|
+
audienceField.val(educatorOption.val()).trigger('refreshCustomValidityRules');
|
|
28
|
+
audienceField.change();
|
|
29
|
+
|
|
30
|
+
var zipcode = $("#school-select-zipcode");
|
|
31
|
+
ok(zipcode, "Found zipcode DOM element");
|
|
32
|
+
ok(zipcode.prop("required"), "zipcode should be required");
|
|
33
|
+
|
|
34
|
+
zipcode.val("").trigger('refreshCustomValidityRules');
|
|
35
|
+
ok(!zipcode.prop('validity').valid, "empty zipcode should not be valid");
|
|
36
|
+
|
|
37
|
+
zipcode.val("123").trigger('refreshCustomValidityRules');
|
|
38
|
+
ok(!zipcode.prop('validity').valid, "too short");
|
|
39
|
+
|
|
40
|
+
zipcode.val("12345").trigger('refreshCustomValidityRules');
|
|
41
|
+
ok(zipcode.checkValidity(), "good format, correct length (checkValidity)");
|
|
42
|
+
ok(zipcode.prop('validity').valid, "good format, correct length");
|
|
43
|
+
|
|
44
|
+
zipcode.val("abcde").trigger('refreshCustomValidityRules');
|
|
45
|
+
ok(!zipcode.checkValidity(), "bad format (checkValidity)");
|
|
46
|
+
ok(!zipcode.prop('validity').valid, "bad format");
|
|
47
|
+
equals(zipcode.prop('validationMessage'), "Invalid zipcode", "custom error message shows");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Factory.define :school do |f|
|
|
2
|
+
f.sequence(:name) { |n| "School #{n}" } #n will increment each time a school factory is created
|
|
3
|
+
f.address_1 'School Address 1'
|
|
4
|
+
f.address_2 'School Address 2'
|
|
5
|
+
f.city 'School City'
|
|
6
|
+
f.state 'VA'
|
|
7
|
+
f.zipcode '12345'
|
|
8
|
+
f.phone '9876543210'
|
|
9
|
+
f.approved true
|
|
10
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Ability do
|
|
4
|
+
describe "as a course admin user" do
|
|
5
|
+
subject { Ability.new(Factory.build(:user_course_admin), 'Admin') }
|
|
6
|
+
|
|
7
|
+
it { should be_able_to(:manage, School) }
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
describe "as a learner user" do
|
|
11
|
+
subject { Ability.new(Factory.build(:user_learner)) }
|
|
12
|
+
|
|
13
|
+
it { should be_able_to(:create, School) }
|
|
14
|
+
it { should be_able_to(:update, School) }
|
|
15
|
+
it { should be_able_to(:index, School) }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "as an unregistered user" do
|
|
19
|
+
subject { Ability.new(User.new) }
|
|
20
|
+
|
|
21
|
+
it { should be_able_to(:create, School) }
|
|
22
|
+
it { should be_able_to(:update, School) }
|
|
23
|
+
it { should be_able_to(:index, School) }
|
|
24
|
+
it { should be_able_to(:create, User) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Profile do
|
|
4
|
+
subject { Factory(:profile) }
|
|
5
|
+
|
|
6
|
+
it { should belong_to(:school) }
|
|
7
|
+
|
|
8
|
+
describe "school validation" do
|
|
9
|
+
context "there exists a few audiences, including educator" do
|
|
10
|
+
before do
|
|
11
|
+
@doctor_audience = Factory :audience, :name => "Doctor"
|
|
12
|
+
@educator_audience = Factory :audience, :name => "Educator"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context "A profile is created with a non-educators audience and without a school;" do
|
|
16
|
+
it "should be a valid profile" do
|
|
17
|
+
@profile = Factory :profile, :audience => @doctor_audience
|
|
18
|
+
@profile.valid?.should be_true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "A profile is created with a educators audience;" do
|
|
23
|
+
context "the profile does not have a school associated with it;" do
|
|
24
|
+
it "should not be a valid profile" do
|
|
25
|
+
lambda{ Factory :profile, :audience => @educator_audience, :school => nil }.should raise_error
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "the profile does have a school associated with it;" do
|
|
30
|
+
it "should be a valid profile" do
|
|
31
|
+
@profile = Factory :profile, :audience => @educator_audience, :school => Factory(:school)
|
|
32
|
+
@profile.valid?.should be_true
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end #describe
|
|
38
|
+
end
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe School do
|
|
4
|
+
|
|
5
|
+
subject { Factory(:school) }
|
|
6
|
+
|
|
7
|
+
it { should validate_presence_of(:address_1) }
|
|
8
|
+
it { should validate_presence_of(:city) }
|
|
9
|
+
it { should validate_presence_of(:name) }
|
|
10
|
+
it { should validate_presence_of(:state) }
|
|
11
|
+
it { should validate_presence_of(:zipcode) }
|
|
12
|
+
|
|
13
|
+
it { should have_many(:profiles) }
|
|
14
|
+
|
|
15
|
+
describe "zipcode formatting" do
|
|
16
|
+
it "should only persist the first five digits" do
|
|
17
|
+
lambda{ Factory(:school, :zipcode => '123456') }.should raise_error
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "should only accept numerical values" do
|
|
21
|
+
lambda{ Factory(:school, :zipcode => 'a2345') }.should raise_error
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "should require full five digits" do
|
|
25
|
+
lambda{ Factory(:school, :zipcode => '1234') }.should raise_error
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe "search" do
|
|
30
|
+
context "there are no schools" do
|
|
31
|
+
it "it should return no results" do
|
|
32
|
+
School.search('whatever').should be_empty
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "there exist two schools with different names but the same zipcodes" do
|
|
37
|
+
before do
|
|
38
|
+
@shared_zipcode = '12345'
|
|
39
|
+
@temple = Factory :school, :name => 'Temple University', :zipcode => @shared_zipcode
|
|
40
|
+
@drexel = Factory :school, :name => 'Drexel University', :zipcode => @shared_zipcode
|
|
41
|
+
@unc = Factory :school, :name => 'University of North Carolina', :zipcode => '00000'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should return no schools if no search terms match" do
|
|
45
|
+
School.search('whatever').should be_empty
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should only return schools that contain the search term in their name" do
|
|
49
|
+
(School.search(@temple.name) - [@temple]).should be_empty
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should return all schools that match the search terms by zipcode" do
|
|
53
|
+
(School.search(@shared_zipcode) - [@temple, @drexel]).should be_empty
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe "user_count" do
|
|
60
|
+
context "there are two schools, each with different amounts of users" do
|
|
61
|
+
before do
|
|
62
|
+
@school_a = Factory :school
|
|
63
|
+
@school_b = Factory :school
|
|
64
|
+
@school_a_users = 1
|
|
65
|
+
@school_b_users = 3
|
|
66
|
+
@school_a_users.times { Factory :profile, :school => @school_a }
|
|
67
|
+
@school_b_users.times { Factory :profile, :school => @school_b }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it "should return the number of profiles associated with the school" do
|
|
71
|
+
@school_a.user_count.should == @school_a_users
|
|
72
|
+
@school_b.user_count.should == @school_b_users
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
describe "migrate_users_to" do
|
|
78
|
+
before do
|
|
79
|
+
@school = Factory :school
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should throw an error if target school is nil" do
|
|
83
|
+
lambda { @school.migrate_users_to(nil) }.should raise_error
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context "there is a valid target school" do
|
|
87
|
+
before do
|
|
88
|
+
@target_school = Factory :school
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it "should migrate and return 0 users" do
|
|
92
|
+
@school.migrate_users_to(@target_school).should be_empty
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context "there are multiple useres in a school" do
|
|
96
|
+
before do
|
|
97
|
+
2.times { Factory :profile, :school => @school }
|
|
98
|
+
@users = @school.profiles.map{ |p| p.user }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should return all users that were in the school" do
|
|
102
|
+
(@school.migrate_users_to(@target_school) - @users).should be_empty
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should remove all users from that school" do
|
|
106
|
+
@school.migrate_users_to(@target_school)
|
|
107
|
+
@school.user_count.should == 0
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "should add all users to the target school" do
|
|
111
|
+
migrated_users = @school.migrate_users_to(@target_school)
|
|
112
|
+
(@users - migrated_users).should be_empty
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
end # describe migrate_users_to
|
|
118
|
+
|
|
119
|
+
describe "learner_form_search" do
|
|
120
|
+
before do
|
|
121
|
+
@zipcode = '99999'
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context "when searching by a bad zipcode" do
|
|
125
|
+
it "will return an empty result set" do
|
|
126
|
+
School.learner_form_search('abcde').should be_empty
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
context "there are no schools" do
|
|
131
|
+
it "will return an empty result set" do
|
|
132
|
+
School.learner_form_search(@zipcode).should be_empty
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context "and a user-created school is passed as a paramter" do
|
|
136
|
+
before do
|
|
137
|
+
@user_created_school = Factory :school, :approved => false, :zipcode => '31415'
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
it "will return only the user created school" do
|
|
141
|
+
School.learner_form_search(@user_created_school.zipcode, @user_created_school).should == [@user_created_school]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
context "and the user-created school is from a zipcode different from the search parameter" do
|
|
145
|
+
it "should return an empty result set" do
|
|
146
|
+
School.learner_form_search(@zipcode, @user_created_school).should be_empty
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
context "there are several schools in different zipcodes" do
|
|
153
|
+
before do
|
|
154
|
+
@c_school = Factory :school, :name => 'C School', :zipcode => @zipcode
|
|
155
|
+
@b_school = Factory :school, :name => 'B School'
|
|
156
|
+
@a_school = Factory :school, :name => 'A School', :zipcode => @zipcode
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
context "when searching by a zipcode with two schools in it;" do
|
|
160
|
+
it "should return the two schools, sorted ascending by name" do
|
|
161
|
+
School.learner_form_search(@zipcode).should == [@a_school, @c_school]
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
context "and a user-created school (with the same zipcode) is passed as a paramter" do
|
|
165
|
+
before { @user_created_school = Factory :school, :name => 'Ac School', :approved => false, :zipcode => @zipcode }
|
|
166
|
+
|
|
167
|
+
it "will return the two existing schools and the user-created school" do
|
|
168
|
+
School.learner_form_search(@zipcode, @user_created_school).should == [@a_school, @user_created_school, @c_school]
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
context "and the user-created school is from a zipcode different from the search parameter" do
|
|
172
|
+
before do
|
|
173
|
+
@user_created_school.zipcode = '31415'
|
|
174
|
+
@user_created_school.save
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "should the original result set without the user created school" do
|
|
178
|
+
School.learner_form_search(@zipcode, @user_created_school).should == [@a_school, @c_school]
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
context "the user-created school is nil" do
|
|
182
|
+
before { @user_created_school = nil }
|
|
183
|
+
|
|
184
|
+
it "should the original result set without the user created school" do
|
|
185
|
+
School.learner_form_search(@zipcode, @user_created_school).should == [@a_school, @c_school]
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end # user-created school passed as a parameter
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
context "when searching by a zipcode with two schools, one pending admin approval" do
|
|
193
|
+
before do
|
|
194
|
+
@c_school.approved = false
|
|
195
|
+
@c_school.save
|
|
196
|
+
@results = School.learner_form_search(@zipcode)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
it "should only return the school that is approved" do
|
|
200
|
+
@results.should == [@a_school]
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
context "when searching by a bad zipcode" do
|
|
205
|
+
it "will return an empty result set" do
|
|
206
|
+
School.learner_form_search('abcde').should be_empty
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
end # several schools
|
|
211
|
+
|
|
212
|
+
end # describe learner_form_search
|
|
213
|
+
|
|
214
|
+
describe "render_form?" do
|
|
215
|
+
context "when there do not exist any schools" do
|
|
216
|
+
before { School.stub(:count).and_return(0) }
|
|
217
|
+
|
|
218
|
+
it "will return false" do
|
|
219
|
+
School.render_form?.should be_false
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
context "when there exists a school" do
|
|
224
|
+
before do
|
|
225
|
+
School.stub(:count).and_return(1)
|
|
226
|
+
Audience.stub(:count).and_return(0)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it "will return false" do
|
|
230
|
+
School.render_form?.should be_false
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
context "and an audience" do
|
|
234
|
+
before { Audience.stub(:count).and_return(1) }
|
|
235
|
+
|
|
236
|
+
it "will return true" do
|
|
237
|
+
School.render_form?.should be_true
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end # describe render_form?
|
|
242
|
+
|
|
243
|
+
describe "to_client_model_json" do
|
|
244
|
+
context "the record is new" do
|
|
245
|
+
it "should not contain created_at" do
|
|
246
|
+
School.new.to_client_model_json.include?('created_at').should be_false
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it "should not contain updated_at" do
|
|
250
|
+
School.new.to_client_model_json.include?('updated_at').should be_false
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
context "the record has been persisted" do
|
|
255
|
+
it "should not contain created_at" do
|
|
256
|
+
subject.to_client_model_json.include?('created_at').should be_false
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
it "should not contain updated_at" do
|
|
260
|
+
subject.to_client_model_json.include?('updated_at').should be_false
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
describe "phone validation" do
|
|
266
|
+
before { @school = Factory :school }
|
|
267
|
+
|
|
268
|
+
context "the phone number is valid;" do
|
|
269
|
+
context "it contains extra characters" do
|
|
270
|
+
before { @school.phone = '987-654-2310' }
|
|
271
|
+
|
|
272
|
+
it "should return a value without extra characters" do
|
|
273
|
+
@school.phone.should == '(987) 654-2310'
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
context "the phone number is missing" do
|
|
279
|
+
before { @school.phone = '' }
|
|
280
|
+
|
|
281
|
+
it "should not validate" do
|
|
282
|
+
@school.valid?.should be_false
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
context "the phone number contains only non-numeric values" do
|
|
287
|
+
before { @school.phone = 'abcdefg' }
|
|
288
|
+
|
|
289
|
+
it "should not validate" do
|
|
290
|
+
@school.valid?.should be_false
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
context "the phone number is invalid (too short);" do
|
|
295
|
+
before { @school.phone = '123' }
|
|
296
|
+
|
|
297
|
+
it "should not validate" do
|
|
298
|
+
|
|
299
|
+
@school.valid?.should be_false
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Admin::SchoolsController do
|
|
4
|
+
describe "routing" do
|
|
5
|
+
|
|
6
|
+
it "recognizes and generates #index" do
|
|
7
|
+
{ :get => "/admin/schools" }.should route_to(:controller => "admin/schools", :action => "index")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "recognizes and generates #new" do
|
|
11
|
+
{ :get => "/admin/schools/new" }.should route_to(:controller => "admin/schools", :action => "new")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "recognizes and generates #show" do
|
|
15
|
+
{ :get => "/admin/schools/1" }.should route_to(:controller => "admin/schools", :action => "show", :id => "1")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "recognizes and generates #edit" do
|
|
19
|
+
{ :get => "/admin/schools/1/edit" }.should route_to(:controller => "admin/schools", :action => "edit", :id => "1")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "recognizes and generates #create" do
|
|
23
|
+
{ :post => "/admin/schools" }.should route_to(:controller => "admin/schools", :action => "create")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "recognizes and generates #update" do
|
|
27
|
+
{ :put => "/admin/schools/1" }.should route_to(:controller => "admin/schools", :action => "update", :id => "1")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "recognizes and generates #destroy" do
|
|
31
|
+
{ :delete => "/admin/schools/1" }.should route_to(:controller => "admin/schools", :action => "destroy", :id => "1")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "recognizes and generates #new_migration" do
|
|
35
|
+
{ :get => "/admin/schools/1/migration/new" }.should route_to(:controller => "admin/schools", :action => "new_migration", :id => "1")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "recognizes and generates #confirm_migration" do
|
|
39
|
+
{ :get => "/admin/schools/1/migration/2/confirm" }.should route_to(:controller => "admin/schools", :action => "confirm_migration", :id => "1", :target_school_id => "2")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "recognizes and generates #migration" do
|
|
43
|
+
{ :post => "/admin/schools/1/migration/2" }.should route_to(:controller => "admin/schools", :action => "create_migration", :id => "1", :target_school_id => "2")
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe SchoolsController do
|
|
4
|
+
describe "routing" do
|
|
5
|
+
|
|
6
|
+
it "recognizes and generates #index" do
|
|
7
|
+
{ :get => "schools" }.should route_to(:controller => "schools", :action => "index" )
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "should not recognize #new" do
|
|
11
|
+
{ :get => "schools/new" }.should_not be_routable
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should not recognize #show" do
|
|
15
|
+
{ :get => "schools/1" }.should_not be_routable
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "should recognize #edit" do
|
|
19
|
+
{ :get => "schools/1/edit" }.should route_to(:controller => "schools", :action => "edit", :id => "1")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "recognizes and generates #create" do
|
|
23
|
+
{ :post => "schools" }.should route_to(:controller => "schools", :action => "create")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "recognizes and generates #update" do
|
|
27
|
+
{ :put => "schools/1" }.should route_to(:controller => "schools", :action => "update", :id => "1")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should not recognize #destroy" do
|
|
31
|
+
{ :delete => "schools/1" }.should_not be_routable
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] ||= 'test'
|
|
2
|
+
|
|
3
|
+
require File.expand_path("../../config/environment", __FILE__)
|
|
4
|
+
|
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
7
|
+
require 'rspec'
|
|
8
|
+
require 'scidea-schools'
|
|
9
|
+
|
|
10
|
+
require 'rspec/rails'
|
|
11
|
+
require 'rspec_tag_matchers'
|
|
12
|
+
require 'cancan/matchers'
|
|
13
|
+
require 'paperclip/matchers'
|
|
14
|
+
|
|
15
|
+
require File.expand_path("../../features/support/seed_user_roles.rb", __FILE__)
|
|
16
|
+
|
|
17
|
+
# Requires supporting files with custom matchers and macros, etc,
|
|
18
|
+
# in ./support/ and its subdirectories.
|
|
19
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
20
|
+
|
|
21
|
+
RSpec.configure do |config|
|
|
22
|
+
config.mock_with :rspec
|
|
23
|
+
config.use_transactional_fixtures = true
|
|
24
|
+
|
|
25
|
+
config.before(:suite) do
|
|
26
|
+
DatabaseCleaner.strategy = :transaction
|
|
27
|
+
DatabaseCleaner.clean_with(:truncation)
|
|
28
|
+
::SeedUserRoles.seed
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
config.before(:each) do
|
|
32
|
+
DatabaseCleaner.start
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
config.after(:each) do
|
|
36
|
+
DatabaseCleaner.clean
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
config.after(:suite) do
|
|
40
|
+
::SeedUserRoles.clean
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# load local factories which will be added to the factories from scidea.
|
|
45
|
+
Rails.configuration.after_initialize do
|
|
46
|
+
FactoryGirl.definition_file_paths = [File.expand_path('../factories', __FILE__)]
|
|
47
|
+
FactoryGirl.find_definitions
|
|
48
|
+
end
|