diff --git a/app/assets/javascripts/lecturers.js.coffee b/app/assets/javascripts/lecturers.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/lecturers.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/lecturers.css.scss b/app/assets/stylesheets/lecturers.css.scss new file mode 100644 index 0000000..b330cbb --- /dev/null +++ b/app/assets/stylesheets/lecturers.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the lecturers controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/lecturers_controller.rb b/app/controllers/lecturers_controller.rb new file mode 100644 index 0000000..c861838 --- /dev/null +++ b/app/controllers/lecturers_controller.rb @@ -0,0 +1,83 @@ +class LecturersController < ApplicationController + # GET /lecturers + # GET /lecturers.json + def index + @lecturers = Lecturer.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @lecturers } + end + end + + # GET /lecturers/1 + # GET /lecturers/1.json + def show + @lecturer = Lecturer.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @lecturer } + end + end + + # GET /lecturers/new + # GET /lecturers/new.json + def new + @lecturer = Lecturer.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @lecturer } + end + end + + # GET /lecturers/1/edit + def edit + @lecturer = Lecturer.find(params[:id]) + end + + # POST /lecturers + # POST /lecturers.json + def create + @lecturer = Lecturer.new(params[:lecturer]) + + respond_to do |format| + if @lecturer.save + format.html { redirect_to @lecturer, notice: 'Lecturer was successfully created.' } + format.json { render json: @lecturer, status: :created, location: @lecturer } + else + format.html { render action: "new" } + format.json { render json: @lecturer.errors, status: :unprocessable_entity } + end + end + end + + # PUT /lecturers/1 + # PUT /lecturers/1.json + def update + @lecturer = Lecturer.find(params[:id]) + + respond_to do |format| + if @lecturer.update_attributes(params[:lecturer]) + format.html { redirect_to @lecturer, notice: 'Lecturer was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @lecturer.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /lecturers/1 + # DELETE /lecturers/1.json + def destroy + @lecturer = Lecturer.find(params[:id]) + @lecturer.destroy + + respond_to do |format| + format.html { redirect_to lecturers_url } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/lecturers_helper.rb b/app/helpers/lecturers_helper.rb new file mode 100644 index 0000000..b8dd3ac --- /dev/null +++ b/app/helpers/lecturers_helper.rb @@ -0,0 +1,2 @@ +module LecturersHelper +end diff --git a/app/models/lecturer.rb b/app/models/lecturer.rb new file mode 100644 index 0000000..773e2de --- /dev/null +++ b/app/models/lecturer.rb @@ -0,0 +1,4 @@ +class Lecturer < ActiveRecord::Base + attr_accessible :email, :name, :oid, :picture, :lva_ids + has_and_belongs_to_many :lvas +end diff --git a/app/models/lva.rb b/app/models/lva.rb index 411d913..68cb831 100755 --- a/app/models/lva.rb +++ b/app/models/lva.rb @@ -13,17 +13,17 @@ # updated_at :datetime not null # modul_id :integer # semester_id :integer -# + # class Lva < ActiveRecord::Base ERLAUBTE_TYPEN = ['VO', 'UE', 'VU', 'LU', 'SE', 'andere']; has_paper_trail # Versionsverfolgung - attr_accessible :desc, :ects, :lvanr, :name, :stunden, :modul_ids, :semester_ids, :pruefungsinformation, :lernaufwand, :typ + attr_accessible :desc, :ects, :lvanr, :name, :stunden, :modul_ids, :semester_ids, :pruefungsinformation, :lernaufwand, :typ, :lecturer_ids has_and_belongs_to_many :modul # Gehört zu einem Modul has_and_belongs_to_many :semester #Gehört zu einem Semester( derzeit nicht implementiert) has_many :beispiele , :class_name => "Beispiel" - + has_and_belongs_to_many :lecturers translates :desc, :fallbacks_for_empty_translations => true validates :lvanr,:format=>{ :with => /^[0-9][0-9][0-9]\.[0-9][0-9][0-9]$/}, :presence=>true, :uniqueness=>true # , :uniqueness=>true # LVA-Nummer muss das Format 000.000 besitzen (uniqueness?) oder 000 für nicht diff --git a/app/views/lecturers/_form.html.erb b/app/views/lecturers/_form.html.erb new file mode 100644 index 0000000..baf4f49 --- /dev/null +++ b/app/views/lecturers/_form.html.erb @@ -0,0 +1,13 @@ +<%= semantic_form_for @lecturer do |f| %> + <%= f.inputs do %> + <%= f.input :name %> + <%= f.input :email %> + <%= f.input :oid %> + <%= f.input :picture %> + <%= f.input :lvas %> + <% end %> + + <%= f.actions do %> + <%= f.action :submit, :as => :input %> + <% end %> +<% end %> diff --git a/app/views/lecturers/edit.html.erb b/app/views/lecturers/edit.html.erb new file mode 100644 index 0000000..3802eca --- /dev/null +++ b/app/views/lecturers/edit.html.erb @@ -0,0 +1,6 @@ +

Editing lecturer

+ +<%= render 'form' %> + +<%= link_to 'Show', @lecturer %> | +<%= link_to 'Back', lecturers_path %> diff --git a/app/views/lecturers/index.html.erb b/app/views/lecturers/index.html.erb new file mode 100644 index 0000000..fe977db --- /dev/null +++ b/app/views/lecturers/index.html.erb @@ -0,0 +1,29 @@ +

Listing lecturers

+ + + + + + + + + + + + +<% @lecturers.each do |lecturer| %> + + + + + + + + + +<% end %> +
NameEmailOidPicture
<%= lecturer.name %><%= lecturer.email %><%= lecturer.oid %><%= lecturer.picture %><%= link_to 'Show', lecturer %><%= link_to 'Edit', edit_lecturer_path(lecturer) %><%= link_to 'Destroy', lecturer, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Lecturer', new_lecturer_path %> diff --git a/app/views/lecturers/new.html.erb b/app/views/lecturers/new.html.erb new file mode 100644 index 0000000..396495d --- /dev/null +++ b/app/views/lecturers/new.html.erb @@ -0,0 +1,5 @@ +

New lecturer

+ +<%= render 'form' %> + +<%= link_to 'Back', lecturers_path %> diff --git a/app/views/lecturers/show.html.erb b/app/views/lecturers/show.html.erb new file mode 100644 index 0000000..21e93cb --- /dev/null +++ b/app/views/lecturers/show.html.erb @@ -0,0 +1,25 @@ +

<%= notice %>

+ +

+ Name: + <%= @lecturer.name %> +

+ +

+ Email: + <%= @lecturer.email %> +

+ +

+ Oid: + <%= @lecturer.oid %> +

+ +

+ Picture: + <%= @lecturer.picture %> +

+ + +<%= link_to 'Edit', edit_lecturer_path(@lecturer) %> | +<%= link_to 'Back', lecturers_path %> diff --git a/app/views/lvas/_lva_semester.html.erb b/app/views/lvas/_lva_semester.html.erb index 8e92fd7..e1f8960 100755 --- a/app/views/lvas/_lva_semester.html.erb +++ b/app/views/lvas/_lva_semester.html.erb @@ -1,9 +1,9 @@
- <%= link_to lva.name, lva_path(lva)%>
+ <%=lva.lvanr.to_s %> <%= link_to lva.name, lva_path(lva)%> <%= lva.ects %> ECTS / <%= lva.stunden %> Std
+
diff --git a/config/routes.rb b/config/routes.rb index c6be014..df3ad2f 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Fetsite::Application.routes.draw do + resources :lecturers + + devise_for :users resources :home, :only=>[:index] #get 'home',:controller=>home,:action=>:index,:as=>"home_index" @@ -34,6 +37,7 @@ end get 'verwalten/studien', :controller=>:studien, :action=>:verwalten, :as=>'studien_verwalten' + resources :lecturers resources :semesters resources :moduls resources :lvas diff --git a/db/migrate/20130819132647_create_lecturers.rb b/db/migrate/20130819132647_create_lecturers.rb new file mode 100644 index 0000000..0304290 --- /dev/null +++ b/db/migrate/20130819132647_create_lecturers.rb @@ -0,0 +1,12 @@ +class CreateLecturers < ActiveRecord::Migration + def change + create_table :lecturers do |t| + t.string :name + t.string :email + t.integer :oid + t.string :picture + + t.timestamps + end + end +end diff --git a/db/migrate/20130819133111_create_lecturers_lvas.rb b/db/migrate/20130819133111_create_lecturers_lvas.rb new file mode 100644 index 0000000..ba0e463 --- /dev/null +++ b/db/migrate/20130819133111_create_lecturers_lvas.rb @@ -0,0 +1,13 @@ +class CreateLecturersLvas < ActiveRecord::Migration + def change + create_table :lecturers_lvas, :id=> false do |t| + t.integer :lecturer_id + t.integer :lva_id + end + + + + + + end +end diff --git a/spec/controllers/lecturers_controller_spec.rb b/spec/controllers/lecturers_controller_spec.rb new file mode 100644 index 0000000..d9227d1 --- /dev/null +++ b/spec/controllers/lecturers_controller_spec.rb @@ -0,0 +1,160 @@ +require 'spec_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. + +describe LecturersController do + + # This should return the minimal set of attributes required to create a valid + # Lecturer. As you add validations to Lecturer, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { { "name" => "MyString" } } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # LecturersController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET index" do + it "assigns all lecturers as @lecturers" do + lecturer = Lecturer.create! valid_attributes + get :index, {}, valid_session + assigns(:lecturers).should eq([lecturer]) + end + end + + describe "GET show" do + it "assigns the requested lecturer as @lecturer" do + lecturer = Lecturer.create! valid_attributes + get :show, {:id => lecturer.to_param}, valid_session + assigns(:lecturer).should eq(lecturer) + end + end + + describe "GET new" do + it "assigns a new lecturer as @lecturer" do + get :new, {}, valid_session + assigns(:lecturer).should be_a_new(Lecturer) + end + end + + describe "GET edit" do + it "assigns the requested lecturer as @lecturer" do + lecturer = Lecturer.create! valid_attributes + get :edit, {:id => lecturer.to_param}, valid_session + assigns(:lecturer).should eq(lecturer) + end + end + + describe "POST create" do + describe "with valid params" do + it "creates a new Lecturer" do + expect { + post :create, {:lecturer => valid_attributes}, valid_session + }.to change(Lecturer, :count).by(1) + end + + it "assigns a newly created lecturer as @lecturer" do + post :create, {:lecturer => valid_attributes}, valid_session + assigns(:lecturer).should be_a(Lecturer) + assigns(:lecturer).should be_persisted + end + + it "redirects to the created lecturer" do + post :create, {:lecturer => valid_attributes}, valid_session + response.should redirect_to(Lecturer.last) + end + end + + describe "with invalid params" do + it "assigns a newly created but unsaved lecturer as @lecturer" do + # Trigger the behavior that occurs when invalid params are submitted + Lecturer.any_instance.stub(:save).and_return(false) + post :create, {:lecturer => { "name" => "invalid value" }}, valid_session + assigns(:lecturer).should be_a_new(Lecturer) + end + + it "re-renders the 'new' template" do + # Trigger the behavior that occurs when invalid params are submitted + Lecturer.any_instance.stub(:save).and_return(false) + post :create, {:lecturer => { "name" => "invalid value" }}, valid_session + response.should render_template("new") + end + end + end + + describe "PUT update" do + describe "with valid params" do + it "updates the requested lecturer" do + lecturer = Lecturer.create! valid_attributes + # Assuming there are no other lecturers in the database, this + # specifies that the Lecturer created on the previous line + # receives the :update_attributes message with whatever params are + # submitted in the request. + Lecturer.any_instance.should_receive(:update_attributes).with({ "name" => "MyString" }) + put :update, {:id => lecturer.to_param, :lecturer => { "name" => "MyString" }}, valid_session + end + + it "assigns the requested lecturer as @lecturer" do + lecturer = Lecturer.create! valid_attributes + put :update, {:id => lecturer.to_param, :lecturer => valid_attributes}, valid_session + assigns(:lecturer).should eq(lecturer) + end + + it "redirects to the lecturer" do + lecturer = Lecturer.create! valid_attributes + put :update, {:id => lecturer.to_param, :lecturer => valid_attributes}, valid_session + response.should redirect_to(lecturer) + end + end + + describe "with invalid params" do + it "assigns the lecturer as @lecturer" do + lecturer = Lecturer.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Lecturer.any_instance.stub(:save).and_return(false) + put :update, {:id => lecturer.to_param, :lecturer => { "name" => "invalid value" }}, valid_session + assigns(:lecturer).should eq(lecturer) + end + + it "re-renders the 'edit' template" do + lecturer = Lecturer.create! valid_attributes + # Trigger the behavior that occurs when invalid params are submitted + Lecturer.any_instance.stub(:save).and_return(false) + put :update, {:id => lecturer.to_param, :lecturer => { "name" => "invalid value" }}, valid_session + response.should render_template("edit") + end + end + end + + describe "DELETE destroy" do + it "destroys the requested lecturer" do + lecturer = Lecturer.create! valid_attributes + expect { + delete :destroy, {:id => lecturer.to_param}, valid_session + }.to change(Lecturer, :count).by(-1) + end + + it "redirects to the lecturers list" do + lecturer = Lecturer.create! valid_attributes + delete :destroy, {:id => lecturer.to_param}, valid_session + response.should redirect_to(lecturers_url) + end + end + +end diff --git a/spec/factories/lecturers.rb b/spec/factories/lecturers.rb new file mode 100644 index 0000000..8b261c1 --- /dev/null +++ b/spec/factories/lecturers.rb @@ -0,0 +1,10 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :lecturer do + name "MyString" + email "MyString" + oid 1 + picture "MyString" + end +end diff --git a/spec/helpers/lecturers_helper_spec.rb b/spec/helpers/lecturers_helper_spec.rb new file mode 100644 index 0000000..11ae700 --- /dev/null +++ b/spec/helpers/lecturers_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the LecturersHelper. For example: +# +# describe LecturersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +describe LecturersHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/lecturer_spec.rb b/spec/models/lecturer_spec.rb new file mode 100644 index 0000000..47a9c46 --- /dev/null +++ b/spec/models/lecturer_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Lecturer do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/lecturers_spec.rb b/spec/requests/lecturers_spec.rb new file mode 100644 index 0000000..be73a9f --- /dev/null +++ b/spec/requests/lecturers_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe "Lecturers" do + describe "GET /lecturers" do + it "works! (now write some real specs)" do + # Run the generator again with the --webrat flag if you want to use webrat methods/matchers + get lecturers_path + response.status.should be(200) + end + end +end diff --git a/spec/routing/lecturers_routing_spec.rb b/spec/routing/lecturers_routing_spec.rb new file mode 100644 index 0000000..5edc712 --- /dev/null +++ b/spec/routing/lecturers_routing_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe LecturersController do + describe "routing" do + + it "routes to #index" do + get("/lecturers").should route_to("lecturers#index") + end + + it "routes to #new" do + get("/lecturers/new").should route_to("lecturers#new") + end + + it "routes to #show" do + get("/lecturers/1").should route_to("lecturers#show", :id => "1") + end + + it "routes to #edit" do + get("/lecturers/1/edit").should route_to("lecturers#edit", :id => "1") + end + + it "routes to #create" do + post("/lecturers").should route_to("lecturers#create") + end + + it "routes to #update" do + put("/lecturers/1").should route_to("lecturers#update", :id => "1") + end + + it "routes to #destroy" do + delete("/lecturers/1").should route_to("lecturers#destroy", :id => "1") + end + + end +end diff --git a/spec/views/lecturers/edit.html.erb_spec.rb b/spec/views/lecturers/edit.html.erb_spec.rb new file mode 100644 index 0000000..c41a1e4 --- /dev/null +++ b/spec/views/lecturers/edit.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe "lecturers/edit" do + before(:each) do + @lecturer = assign(:lecturer, stub_model(Lecturer, + :name => "MyString", + :email => "MyString", + :oid => 1, + :picture => "MyString" + )) + end + + it "renders the edit lecturer form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form[action=?][method=?]", lecturer_path(@lecturer), "post" do + assert_select "input#lecturer_name[name=?]", "lecturer[name]" + assert_select "input#lecturer_email[name=?]", "lecturer[email]" + assert_select "input#lecturer_oid[name=?]", "lecturer[oid]" + assert_select "input#lecturer_picture[name=?]", "lecturer[picture]" + end + end +end diff --git a/spec/views/lecturers/index.html.erb_spec.rb b/spec/views/lecturers/index.html.erb_spec.rb new file mode 100644 index 0000000..af635b8 --- /dev/null +++ b/spec/views/lecturers/index.html.erb_spec.rb @@ -0,0 +1,29 @@ +require 'spec_helper' + +describe "lecturers/index" do + before(:each) do + assign(:lecturers, [ + stub_model(Lecturer, + :name => "Name", + :email => "Email", + :oid => 1, + :picture => "Picture" + ), + stub_model(Lecturer, + :name => "Name", + :email => "Email", + :oid => 1, + :picture => "Picture" + ) + ]) + end + + it "renders a list of lecturers" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "tr>td", :text => "Name".to_s, :count => 2 + assert_select "tr>td", :text => "Email".to_s, :count => 2 + assert_select "tr>td", :text => 1.to_s, :count => 2 + assert_select "tr>td", :text => "Picture".to_s, :count => 2 + end +end diff --git a/spec/views/lecturers/new.html.erb_spec.rb b/spec/views/lecturers/new.html.erb_spec.rb new file mode 100644 index 0000000..296a894 --- /dev/null +++ b/spec/views/lecturers/new.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe "lecturers/new" do + before(:each) do + assign(:lecturer, stub_model(Lecturer, + :name => "MyString", + :email => "MyString", + :oid => 1, + :picture => "MyString" + ).as_new_record) + end + + it "renders new lecturer form" do + render + + # Run the generator again with the --webrat flag if you want to use webrat matchers + assert_select "form[action=?][method=?]", lecturers_path, "post" do + assert_select "input#lecturer_name[name=?]", "lecturer[name]" + assert_select "input#lecturer_email[name=?]", "lecturer[email]" + assert_select "input#lecturer_oid[name=?]", "lecturer[oid]" + assert_select "input#lecturer_picture[name=?]", "lecturer[picture]" + end + end +end diff --git a/spec/views/lecturers/show.html.erb_spec.rb b/spec/views/lecturers/show.html.erb_spec.rb new file mode 100644 index 0000000..948ab16 --- /dev/null +++ b/spec/views/lecturers/show.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe "lecturers/show" do + before(:each) do + @lecturer = assign(:lecturer, stub_model(Lecturer, + :name => "Name", + :email => "Email", + :oid => 1, + :picture => "Picture" + )) + end + + it "renders attributes in

" do + render + # Run the generator again with the --webrat flag if you want to use webrat matchers + rendered.should match(/Name/) + rendered.should match(/Email/) + rendered.should match(/1/) + rendered.should match(/Picture/) + end +end