Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

いろんな修正が1コミットで反省している

  • Loading branch information...
commit fc21fc6ee46b6ca06439a5276ca9abd04a7ac2dc 1 parent 88ab294
@suginoy authored
Showing with 773 additions and 80 deletions.
  1. +3 −0  app/assets/javascripts/courses.js.coffee
  2. +3 −0  app/assets/javascripts/dashboard.js.coffee
  3. +3 −0  app/assets/stylesheets/courses.css.scss
  4. +3 −0  app/assets/stylesheets/dashboard.css.scss
  5. +85 −0 app/controllers/courses_controller.rb
  6. +7 −0 app/controllers/dashboard_controller.rb
  7. +24 −48 app/controllers/questions_controller.rb
  8. +10 −0 app/helpers/courses_helper.rb
  9. +2 −0  app/helpers/dashboard_helper.rb
  10. +10 −0 app/models/course.rb
  11. +30 −5 app/models/question.rb
  12. +0 −1  app/models/summary.rb
  13. +2 −1  app/models/user.rb
  14. +29 −0 app/views/courses/_form.html.erb
  15. +6 −0 app/views/courses/edit.html.erb
  16. +23 −0 app/views/courses/index.html.erb
  17. +5 −0 app/views/courses/new.html.erb
  18. +44 −0 app/views/courses/show.html.erb
  19. +22 −0 app/views/dashboard/show.html.erb
  20. +1 −0  app/views/layouts/application.html.erb
  21. +2 −4 app/views/questions/_form.html.erb
  22. +2 −2 app/views/questions/edit.html.erb
  23. +1 −1  app/views/questions/new.html.erb
  24. +10 −6 app/views/questions/show.html.erb
  25. +1 −0  app/views/shared/_header.html.erb
  26. +9 −6 config/routes.rb
  27. +12 −0 db/migrate/20111224011150_create_courses.rb
  28. +5 −0 db/migrate/20111224012654_add_course_id_to_questions.rb
  29. +5 −0 db/migrate/20111226132234_add_counter_cache_to_courses.rb
  30. +5 −0 db/migrate/20111226135810_add_sharing_to_courses.rb
  31. +14 −1 db/schema.rb
  32. +47 −5 db/seeds.rb
  33. +157 −0 spec/controllers/cources_controller_spec.rb
  34. +12 −0 spec/controllers/dashboard_controller_spec.rb
  35. +15 −0 spec/helpers/cources_helper_spec.rb
  36. +15 −0 spec/helpers/dashboard_helper_spec.rb
  37. +5 −0 spec/models/cource_spec.rb
  38. +11 −0 spec/requests/cources_spec.rb
  39. +35 −0 spec/routing/cources_routing_spec.rb
  40. +22 −0 spec/views/cources/edit.html.erb_spec.rb
  41. +28 −0 spec/views/cources/index.html.erb_spec.rb
  42. +22 −0 spec/views/cources/new.html.erb_spec.rb
  43. +21 −0 spec/views/cources/show.html.erb_spec.rb
  44. +5 −0 spec/views/dashboard/index.html.erb_spec.rb
View
3  app/assets/javascripts/courses.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/
View
3  app/assets/javascripts/dashboard.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/
View
3  app/assets/stylesheets/courses.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the courses controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  app/assets/stylesheets/dashboard.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the dashboard controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
85 app/controllers/courses_controller.rb
@@ -0,0 +1,85 @@
+class CoursesController < ApplicationController
+ # GET /courses
+ # GET /courses.json
+ def index
+ @courses = Course.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @courses }
+ end
+ end
+
+ # GET /courses/1
+ # GET /courses/1.json
+ def show
+ @course = Course.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @course }
+ end
+ end
+
+ # GET /courses/new
+ # GET /courses/new.json
+ def new
+ @course = Course.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @course }
+ end
+ end
+
+ # GET /courses/1/edit
+ def edit
+ @course = Course.find(params[:id])
+ end
+
+ # POST /courses
+ # POST /courses.json
+ def create
+ @course = Course.new(params[:course])
+ @course.owner_id = current_user.id
+
+ respond_to do |format|
+ if @course.save
+ format.html { redirect_to @course, notice: 'Course was successfully created.' }
+ format.json { render json: @course, status: :created, location: @course }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @course.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /courses/1
+ # PUT /courses/1.json
+ def update
+ @course = Course.find(params[:id])
+ @course.owner_id = current_user.id
+
+ respond_to do |format|
+ if @course.update_attributes(params[:course])
+ format.html { redirect_to @course, notice: 'Course was successfully updated.' }
+ format.json { head :ok }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @course.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /courses/1
+ # DELETE /courses/1.json
+ def destroy
+ @course = Course.find(params[:id])
+ @course.destroy
+
+ respond_to do |format|
+ format.html { redirect_to courses_url }
+ format.json { head :ok }
+ end
+ end
+end
View
7 app/controllers/dashboard_controller.rb
@@ -0,0 +1,7 @@
+class DashboardController < ApplicationController
+ def index
+ @user = current_user
+ @shared_courses = Course.shared_courses_for(@user)
+ end
+
+end
View
72 app/controllers/questions_controller.rb
@@ -1,21 +1,12 @@
class QuestionsController < ApplicationController
- # GET /questions
- # GET /questions.json
- def index
- # @questions = Question.all
-
- respond_to do |format|
- format.html # index.html.erb
- format.json { render json: @questions }
- end
- end
-
- # GET /questions/1
- # GET /questions/1.json
+ # GET /courses/:course_id/questions/1
+ # GET /courses/:course_id/questions/1.json
def show
@user = current_user
@question = Question.find(params[:id])
- @next_question = Question.other_question(params[:id])
+ #@next_question = Question.other_question(params[:id])
+ @next_question = @question.next
+ @user.prepare_summary(@question[:id])
@summary = Summary.find_by_user_id_and_question_id(@user[:id], @question[:id])
respond_to do |format|
@@ -24,31 +15,28 @@ def show
end
end
- # GET /questions/new
- # GET /questions/new.json
+ # GET /courses/:course_id/questions/new
+ # GET /courses/:course_id/questions/new.json
def new
- @question = Question.new
-
- respond_to do |format|
- format.html # new.html.erb
- format.json { render json: @question }
- end
+ @question = Question.new(:course_id => params[:course_id])
end
- # GET /questions/1/edit
+ # GET /courses/:course_id/questions/1/edit
def edit
@question = Question.find(params[:id])
end
- # POST /questions
- # POST /questions.json
+ # POST /courses/:course_id/questions
+ # POST /courses/:course_id/questions.json
def create
- @question = Question.new(params[:question])
+ @course = Course.find(params[:course_id])
+ @question = @course.questions.build(params[:question])
+ @question.save
respond_to do |format|
if @question.save
- format.html { redirect_to @question, notice: 'Question was successfully created.' }
- format.json { render json: @question, status: :created, location: @question }
+ format.html { redirect_to @course, notice: 'Question was successfully created.' }
+ format.json { render json: @course, status: :created, location: @question }
else
format.html { render action: "new" }
format.json { render json: @question.errors, status: :unprocessable_entity }
@@ -56,14 +44,14 @@ def create
end
end
- # PUT /questions/1
- # PUT /questions/1.json
+ # PUT /courses/:course_id/questions/1
+ # PUT /courses/:course_id/questions/1.json
def update
@question = Question.find(params[:id])
respond_to do |format|
if @question.update_attributes(params[:question])
- format.html { redirect_to @question, notice: 'Question was successfully updated.' }
+ format.html { redirect_to @question.course, notice: 'Question was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
@@ -72,8 +60,8 @@ def update
end
end
- # DELETE /questions/1
- # DELETE /questions/1.json
+ # DELETE /courses/:course_id/questions/1
+ # DELETE /courses/:course_id/questions/1.json
def destroy
@question = Question.find(params[:id])
@question.destroy
@@ -84,9 +72,10 @@ def destroy
end
end
- # POST /questions/1/answer
- # POST /questions/1/answer.json
+ # POST /courses/:course_id/questions/1/answer
+ # POST /courses/:course_id/questions/1/answer.json
def answer
+ # TODO: サマリ更新ロジックをモデルに移動
@question = Question.find(params[:id])
@user = current_user
@summary = Summary.find_by_user_id_and_question_id(@user[:id], @question[:id])
@@ -104,17 +93,4 @@ def answer
@summary.save!
@score.save!
end
-
- # GET /questions/1
- # GET /questions/1.json
- def first
- @user = current_user
-
- # サマリ全コピー TODO 1.バルクINSERTに変更(できるの?) / 2.初回ログイン時に変更する
- Question.all.each do |q|
- @user.prepare_summary(q[:id])
- end
-
- redirect_to :action => "show", :id => Summary.least_answered(@user[:id])[:question_id]
- end
end
View
10 app/helpers/courses_helper.rb
@@ -0,0 +1,10 @@
+# encoding: utf-8
+module CoursesHelper
+ def sharing_display(sharing)
+ if sharing
+ "共有"
+ else
+ "専有"
+ end
+ end
+end
View
2  app/helpers/dashboard_helper.rb
@@ -0,0 +1,2 @@
+module DashboardHelper
+end
View
10 app/models/course.rb
@@ -0,0 +1,10 @@
+class Course < ActiveRecord::Base
+ belongs_to :owner, :class_name => 'User', :dependent => :delete
+ has_many :questions
+
+ validates :name, :presence => true
+ validates :description, :presence => true
+
+ scope :shared, where(:sharing => true)
+ scope :shared_courses_for, lambda { |user| shared.where 'owner_id != ?', user[:id] }
+end
View
35 app/models/question.rb
@@ -1,9 +1,34 @@
class Question < ActiveRecord::Base
+ before_save :set_next_number
+ after_destroy :compact
+ belongs_to :course, :counter_cache => true
has_many :scores
has_many :users, :through => :scores
- default_scope order("id")
- scope :other_questions, lambda { |previous_id| where("id != ?", previous_id) }
- def self.other_question(id)
- self.other_questions(id).sample
- end
+
+ #validates :number, :title, :description, :choice1, :choice2, :choice3, :choice4, :explanation,
+ validates :title, :description, :choice1, :choice2, :choice3, :choice4, :explanation,
+ :presence => true
+ validates :answer, :inclusion => { :in => [1, 2, 3, 4] }
+
+ default_scope order("number")
+
+ def next
+ unless self.number == self.course.questions.length
+ Question.find_by_course_id_and_number(self.course_id, self.number + 1)
+ end
+ end
+
+ def compact
+ Question.where(:course_id => self.course_id).each do |question|
+ if question.number > self.number
+ question.update_atribute(:number, self.number - 1)
+ end
+ end
+ end
+
+ private
+ def set_next_number # TODO メソッド名変更
+ self.number ||= self.course.questions_count + 1
+ #self.number ||= Course.find(self.course_id).questions_count + 1
+ end
end
View
1  app/models/summary.rb
@@ -1,6 +1,5 @@
class Summary < ActiveRecord::Base
has_many :scores
- #has_many :users, :through => :scores
belongs_to :users
has_many :questions, :through => :scores
View
3  app/models/user.rb
@@ -1,7 +1,7 @@
class User < ActiveRecord::Base
+ has_many :courses, :foreign_key => 'owner_id'
has_many :scores
has_many :questions, :through => :scores
- #has_many :summaries, :through => :scores # user_id をSummaryに追加して直接参照する
has_many :summaries
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
@@ -18,4 +18,5 @@ def prepare_summary(question_id)
Summary.find_by_user_id_and_question_id(self.id, question_id)
end
end
+
end
View
29 app/views/courses/_form.html.erb
@@ -0,0 +1,29 @@
+<%= form_for(@course) do |f| %>
+ <% if @course.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@course.errors.count, "error") %> prohibited this course from being saved:</h2>
+
+ <ul>
+ <% @course.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :description %><br />
+ <%= f.text_area :description %>
+ </div>
+ <div class="field">
+ <%= f.label :sharing %><br />
+ <%= f.check_box :sharing %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
View
6 app/views/courses/edit.html.erb
@@ -0,0 +1,6 @@
+<h1>Editing course</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @course %> |
+<%= link_to 'Back', courses_path %>
View
23 app/views/courses/index.html.erb
@@ -0,0 +1,23 @@
+<h1>Listing courses</h1>
+
+<table>
+ <tr>
+ <th>コース名</th>
+ <th>作成者</th>
+ <th>問題数</th>
+ <th>共有/専有</th>
+ </tr>
+
+<% @courses.each do |course| %>
+ <tr>
+ <td><%= link_to course.name, course %></td>
+ <td><%= course.owner.email %></td>
+ <td><%= course.questions_count %></td>
+ <td><%= course.sharing %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Cource', new_course_path %>
View
5 app/views/courses/new.html.erb
@@ -0,0 +1,5 @@
+<h1>New course</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', courses_path %>
View
44 app/views/courses/show.html.erb
@@ -0,0 +1,44 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>コース:</b>
+ <%= @course.name %>
+</p>
+
+<p>
+ <b>コース内容:</b>
+ <%= @course.description %>
+</p>
+
+<p>
+ <b>作成者:</b>
+ <%= @course.owner.email %>
+</p>
+
+<p>
+ <b>問題数:</b>
+ <%= @course.questions_count %>
+</p>
+
+<p>
+ <b>共有/専有:</b>
+ <%= sharing_display @course.sharing %>
+</p>
+
+<% unless @course.questions.empty? %>
+<p>
+ <%= link_to 'スタート', course_question_path(@course, @course.questions.first) %>
+</p>
+<ul>
+ <% @course.questions.each do |question| %>
+ <li><%= question.number %>|<%= truncate(question.description, :length => 20) %>|<%= link_to "Edit", edit_course_question_path(@course, question) %></li>
+ <% end %>
+</ul>
+<% end %>
+
+<p>
+ <%= link_to '問題を追加する', new_course_question_path(@course) %>
+</p>
+
+<%= link_to 'Edit Cource', edit_course_path(@course) %> |
+<%= link_to 'Back', courses_path %>
View
22 app/views/dashboard/show.html.erb
@@ -0,0 +1,22 @@
+<h1>Dashboard</h1>
+
+<p>
+ <%= @user.email %>さんのコース
+</p>
+
+<ul>
+<% @user.courses.each do |course| %>
+ <li><%= link_to course.name, url_for(course) %>|問題数 <%= course.questions_count %></li>
+<% end %>
+</ul>
+
+<p>
+ 共有されているコース
+</p>
+
+<ul>
+<% @shared_courses.each do |course| %>
+ <li><%= link_to course.name, url_for(course) %>|作成者 <%= course.owner.email %>|問題数 <%= course.questions_count %></li>
+<% end %>
+</ul>
+<%= link_to '新しいコースを作成する', new_course_path %>
View
1  app/views/layouts/application.html.erb
@@ -8,6 +8,7 @@
<%= csrf_meta_tags %>
</head>
<body>
+ <%= render :partial => 'shared/header' %>
<%= yield %>
View
6 app/views/questions/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_for(@question) do |f| %>
+<%= form_for([ @question.course, @question]) do |f| %>
<% if @question.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@question.errors.count, "error") %> prohibited this question from being saved:</h2>
@@ -11,9 +11,7 @@
</div>
<% end %>
- <div class="field">
- <%= f.label :number %><br />
- <%= f.number_field :number %>
+ <%= hidden_field_tag "course_id", @question.course_id %>
</div>
<div class="field">
<%= f.label :title %><br />
View
4 app/views/questions/edit.html.erb
@@ -2,5 +2,5 @@
<%= render 'form' %>
-<%= link_to 'Show', @question %> |
-<%= link_to 'Back', questions_path %>
+<%= link_to 'Show', course_question_path(@question.course, @question) %> |
+<%= link_to 'Back', course_path(@question.course) %>
View
2  app/views/questions/new.html.erb
@@ -2,4 +2,4 @@
<%= render 'form' %>
-<%= link_to 'Back', questions_path %>
+<%= link_to 'Back', course_path(@question.course) %>
View
16 app/views/questions/show.html.erb
@@ -9,7 +9,7 @@
</li>
</ul>
<div id="postQ">
- <%= link_to image_tag("/assets/post.gif"), new_question_path %>
+ <%= link_to image_tag("/assets/post.gif"), new_course_path %>
</div>
</div>
<div id="question">
@@ -18,12 +18,12 @@
Q<%= @question.number %>
</li>
<li class="qtitle">
- <%= @question.title %>
+ <%= @question.title %>(<%= @summary.percentage %> % of <%= pluralize(@summary.total, "time") %>)
</li>
</ul>
<br />
<br />
- <%= @question.description %>(<%= @summary.percentage %> %)
+ <%= @question.description %>
<div id="answers">
<div class="answer box">
<p>A. <%= link_to @question.choice1, { :controller => "questions", :action => "answer", :id => @question[:id], :answer => 1 }, :method => :post, :remote => true, :name => "answer" %></p>
@@ -51,8 +51,12 @@
<%= @question.explanation %>
</div>
<div id="nextq">
- <%= link_to image_tag("/assets/next.gif", :alt => "次の問題へ"), question_path(@next_question) %>
+ <% if @next_question.nil? %>
+ <%= link_to "コースへ戻る", course_path(@question.course) %>
+ <% else %>
+ <%= link_to image_tag("/assets/next.gif", :alt => "次の問題へ"), course_question_path(@question.course, @next_question) %>
+ <% end %>
</div>
-</div>
-</div>
+ </div>
+ </div>
</div>
View
1  app/views/shared/_header.html.erb
@@ -0,0 +1 @@
+<%= link_to 'ログアウト', { :action=>"destroy", :controller=>"devise/sessions" }, :method => :delete %>
View
15 config/routes.rb
@@ -1,12 +1,15 @@
Yontaku::Application.routes.draw do
- devise_for :users
+ get "dashboard" => "dashboard#show"
- resources :questions do
- member do
- post "answer" => "questions#answer"
- end
+ resources :courses do
+ resources :questions, :except => [:index]
+ member do
+ post "answer" => "questions#answer"
+ end
end
+ devise_for :users
+
# The priority is based upon order of creation:
# first created -> highest priority.
@@ -57,7 +60,7 @@
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => 'welcome#index'
- root :to => 'questions#first'
+ root :to => 'dashboard#index'
# See how all your routes lay out with "rake routes"
View
12 db/migrate/20111224011150_create_courses.rb
@@ -0,0 +1,12 @@
+class CreateCourses < ActiveRecord::Migration
+ def change
+ create_table :courses do |t|
+ t.string :name
+ t.text :description
+ t.integer :owner_id
+
+ t.timestamps
+ end
+ add_index :courses, :owner_id
+ end
+end
View
5 db/migrate/20111224012654_add_course_id_to_questions.rb
@@ -0,0 +1,5 @@
+class AddCourseIdToQuestions < ActiveRecord::Migration
+ def change
+ add_column :questions, :course_id, :integer
+ end
+end
View
5 db/migrate/20111226132234_add_counter_cache_to_courses.rb
@@ -0,0 +1,5 @@
+class AddCounterCacheToCourses < ActiveRecord::Migration
+ def change
+ add_column :courses, :questions_count, :integer, :null => false, :default => 0
+ end
+end
View
5 db/migrate/20111226135810_add_sharing_to_courses.rb
@@ -0,0 +1,5 @@
+class AddSharingToCourses < ActiveRecord::Migration
+ def change
+ add_column :courses, :sharing, :boolean
+ end
+end
View
15 db/schema.rb
@@ -11,7 +11,19 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20111208080740) do
+ActiveRecord::Schema.define(:version => 20111226135810) do
+
+ create_table "courses", :force => true do |t|
+ t.string "name"
+ t.text "description"
+ t.integer "owner_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ t.integer "questions_count", :default => 0, :null => false
+ t.boolean "sharing"
+ end
+
+ add_index "courses", ["owner_id"], :name => "index_courses_on_owner_id"
create_table "questions", :force => true do |t|
t.integer "number"
@@ -25,6 +37,7 @@
t.text "explanation"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "course_id"
end
create_table "scores", :force => true do |t|
View
52 db/seeds.rb
@@ -7,8 +7,50 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
-Question.create!(:number => 1, :title => "Choose one word or phrase that best completes the sentence.", :description => "Your prompt _______ to our proposal would be highly appreciated.", :choice1 => "respond", :choice2 => "response", :choice3 => "to respond", :choice4 => "responded", :answer => 2, :explanation => "ビジネス・レターでよく使用される文です。Your の後ろには名詞があることが予想されますが、prompt の品詞を見極めることがまず大切です。これが「迅速な」の意味の形容詞であることが分かれば、その後ろに名詞がこなければいけないことが明らかになります。")
-Question.create!(:number => 2, :title => "Choose one word or phrase that best completes the sentence.", :description => "Let them _______ as they like. They'll never listen to us.", :choice1 => "do", :choice2 => "to do", :choice3 => "to be doing", :choice4 => "to have done", :answer => 1, :explanation => "「…させてあげる」の意味の使役動詞 let は、let +目的語+原形動詞の形をとります。")
-Question.create!(:number => 3, :title => "Choose one word or phrase that best completes the sentence.", :description => "I was just about to leave home, _______ the phone rang.", :choice1 => "that", :choice2 => "why", :choice3 => "when", :choice4 => "at that time", :answer => 3, :explanation => "【着眼点】選択肢のうちで、接続詞機能を有し、かつコンマを介して2つの節を連結できるのは非制限用法をもつ関係副詞のwhenのみである。なお、この場合のwhenは前の節全体を先行詞とする。be about to ~ は「まさに[今にも]~しようとしている」の意。「ちょうど家を出ようとしていたそのときに、電話が鳴った。」")
-Question.create!(:number => 4, :title => "Choose one word or phrase that best completes the sentence.", :description => "Your children have passed the age _______ they need to worry about such illnesses. ", :choice1 => "why", :choice2 => "how", :choice3 => "when", :choice4 => "which", :answer => 3, :explanation => "【着眼点】選択肢はすべて関係詞だが、先行詞がthe ageという「時」を表す名詞句であるから (A) と (B) は消える。次に、このthe ageを受けてthey need to worry about such illnessesの節にどう結びつけていくかだが、the ageという名詞句のままではどこにも差し込む適当な場所はない。したがって、名詞句だけの代用となる関係代名詞 (which) は不可。whenであれば「その年齢において[その年齢のときに]they need to以下である」が成立するのでうまくつながることになる。")
-Question.create!(:number => 5, :title => "Choose one word or phrase that best completes the sentence.", :description => "The real estate agent has three apartments to show you _______ is very near your workplace.", :choice1 => ", one of them", :choice2 => ", one of which", :choice3 => "none of whom", :choice4 => "some of which", :answer => 2, :explanation => "【着眼点】whichやwhomがofを介して数[量]詞と結びつく‘one [some, any, none, all, both, several, enough, many, few, etc.] of which [whom]’の形は非制限用法なので、コンマのない (C) , (D) は不可。加えて (C) は先行詞 (three apartments) が人でない点、(D) は関係詞節内の動詞が単数 (is) である点でも不可。コンマだけで節を結ぶ (A) も不可。")
+course = Course.create!(
+ :name => "お試し問題",
+ :description => "お試し問題です",
+ :owner_id => 1, # TODO deviseのユーザを作成する
+ :sharing => true
+)
+
+course.questions.create!(
+ :number => 1,
+ :title => "Choose one word or phrase that best completes the sentence.",
+ :description => "Your prompt _______ to our proposal would be highly appreciated.",
+ :choice1 => "respond", :choice2 => "response",:choice3 => "to respond", :choice4 => "responded",
+ :answer => 2,
+ :explanation => "ビジネス・レターでよく使用される文です。Your の後ろには名詞があることが予想されますが、prompt の品詞を見極めることがまず大切です。これが「迅速な」の意味の形容詞であることが分かれば、その後ろに名詞がこなければいけないことが明らかになります。"
+)
+course.questions.create!(
+ :number => 2,
+ :title => "Choose one word or phrase that best completes the sentence.",
+ :description => "Let them _______ as they like. They'll never listen to us.",
+ :choice1 => "do", :choice2 => "to do", :choice3 => "to be doing", :choice4 => "to have done",
+ :answer => 1,
+ :explanation => "「…させてあげる」の意味の使役動詞 let は、let +目的語+原形動詞の形をとります。"
+)
+course.questions.create!(
+ :number => 3,
+ :title => "Choose one word or phrase that best completes the sentence.",
+ :description => "I was just about to leave home, _______ the phone rang.",
+ :choice1 => "that", :choice2 => "why", :choice3 => "when", :choice4 => "at that time",
+ :answer => 3,
+ :explanation => "【着眼点】選択肢のうちで、接続詞機能を有し、かつコンマを介して2つの節を連結できるのは非制限用法をもつ関係副詞のwhenのみである。なお、この場合のwhenは前の節全体を先行詞とする。be about to ~ は「まさに[今にも]~しようとしている」の意。「ちょうど家を出ようとしていたそのときに、電話が鳴った。」"
+)
+course.questions.create!(
+ :number => 4,
+ :title => "Choose one word or phrase that best completes the sentence.",
+ :description => "Your children have passed the age _______ they need to worry about such illnesses. ",
+ :choice1 => "why", :choice2 => "how", :choice3 => "when", :choice4 => "which",
+ :answer => 3,
+ :explanation => "【着眼点】選択肢はすべて関係詞だが、先行詞がthe ageという「時」を表す名詞句であるから (A) と (B) は消える。次に、このthe ageを受けてthey need to worry about such illnessesの節にどう結びつけていくかだが、the ageという名詞句のままではどこにも差し込む適当な場所はない。したがって、名詞句だけの代用となる関係代名詞 (which) は不可。whenであれば「その年齢において[その年齢のときに]they need to以下である」が成立するのでうまくつながることになる。"
+)
+course.questions.create!(
+ :number => 5,
+ :title => "Choose one word or phrase that best completes the sentence.",
+ :description => "The real estate agent has three apartments to show you _______ is very near your workplace.",
+ :choice1 => ", one of them", :choice2 => ", one of which", :choice3 => "none of whom", :choice4 => "some of which",
+ :answer => 2,
+ :explanation => "【着眼点】whichやwhomがofを介して数[量]詞と結びつく‘one [some, any, none, all, both, several, enough, many, few, etc.] of which [whom]’の形は非制限用法なので、コンマのない (C) , (D) は不可。加えて (C) は先行詞 (three apartments) が人でない点、(D) は関係詞節内の動詞が単数 (is) である点でも不可。コンマだけで節を結ぶ (A) も不可。"
+)
View
157 spec/controllers/cources_controller_spec.rb
@@ -0,0 +1,157 @@
+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 CourcesController do
+
+ # This should return the minimal set of attributes required to create a valid
+ # Cource. As you add validations to Cource, be sure to
+ # update the return value of this method accordingly.
+ def valid_attributes
+ {}
+ end
+
+ describe "GET index" do
+ it "assigns all cources as @cources" do
+ cource = Cource.create! valid_attributes
+ get :index
+ assigns(:cources).should eq([cource])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested cource as @cource" do
+ cource = Cource.create! valid_attributes
+ get :show, :id => cource.id.to_s
+ assigns(:cource).should eq(cource)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new cource as @cource" do
+ get :new
+ assigns(:cource).should be_a_new(Cource)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested cource as @cource" do
+ cource = Cource.create! valid_attributes
+ get :edit, :id => cource.id.to_s
+ assigns(:cource).should eq(cource)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new Cource" do
+ expect {
+ post :create, :cource => valid_attributes
+ }.to change(Cource, :count).by(1)
+ end
+
+ it "assigns a newly created cource as @cource" do
+ post :create, :cource => valid_attributes
+ assigns(:cource).should be_a(Cource)
+ assigns(:cource).should be_persisted
+ end
+
+ it "redirects to the created cource" do
+ post :create, :cource => valid_attributes
+ response.should redirect_to(Cource.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved cource as @cource" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cource.any_instance.stub(:save).and_return(false)
+ post :create, :cource => {}
+ assigns(:cource).should be_a_new(Cource)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cource.any_instance.stub(:save).and_return(false)
+ post :create, :cource => {}
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested cource" do
+ cource = Cource.create! valid_attributes
+ # Assuming there are no other cources in the database, this
+ # specifies that the Cource created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ Cource.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, :id => cource.id, :cource => {'these' => 'params'}
+ end
+
+ it "assigns the requested cource as @cource" do
+ cource = Cource.create! valid_attributes
+ put :update, :id => cource.id, :cource => valid_attributes
+ assigns(:cource).should eq(cource)
+ end
+
+ it "redirects to the cource" do
+ cource = Cource.create! valid_attributes
+ put :update, :id => cource.id, :cource => valid_attributes
+ response.should redirect_to(cource)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the cource as @cource" do
+ cource = Cource.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cource.any_instance.stub(:save).and_return(false)
+ put :update, :id => cource.id.to_s, :cource => {}
+ assigns(:cource).should eq(cource)
+ end
+
+ it "re-renders the 'edit' template" do
+ cource = Cource.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Cource.any_instance.stub(:save).and_return(false)
+ put :update, :id => cource.id.to_s, :cource => {}
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested cource" do
+ cource = Cource.create! valid_attributes
+ expect {
+ delete :destroy, :id => cource.id.to_s
+ }.to change(Cource, :count).by(-1)
+ end
+
+ it "redirects to the cources list" do
+ cource = Cource.create! valid_attributes
+ delete :destroy, :id => cource.id.to_s
+ response.should redirect_to(cources_url)
+ end
+ end
+
+end
View
12 spec/controllers/dashboard_controller_spec.rb
@@ -0,0 +1,12 @@
+require 'spec_helper'
+
+describe DashboardController do
+
+ describe "GET 'index'" do
+ it "should be successful" do
+ get 'index'
+ response.should be_success
+ end
+ end
+
+end
View
15 spec/helpers/cources_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the CourcesHelper. For example:
+#
+# describe CourcesHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe CourcesHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
15 spec/helpers/dashboard_helper_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the DashboardHelper. For example:
+#
+# describe DashboardHelper do
+# describe "string concat" do
+# it "concats two strings with spaces" do
+# helper.concat_strings("this","that").should == "this that"
+# end
+# end
+# end
+describe DashboardHelper do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/cource_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Cource do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
11 spec/requests/cources_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "Cources" do
+ describe "GET /cources" 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 cources_path
+ response.status.should be(200)
+ end
+ end
+end
View
35 spec/routing/cources_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe CourcesController do
+ describe "routing" do
+
+ it "routes to #index" do
+ get("/cources").should route_to("cources#index")
+ end
+
+ it "routes to #new" do
+ get("/cources/new").should route_to("cources#new")
+ end
+
+ it "routes to #show" do
+ get("/cources/1").should route_to("cources#show", :id => "1")
+ end
+
+ it "routes to #edit" do
+ get("/cources/1/edit").should route_to("cources#edit", :id => "1")
+ end
+
+ it "routes to #create" do
+ post("/cources").should route_to("cources#create")
+ end
+
+ it "routes to #update" do
+ put("/cources/1").should route_to("cources#update", :id => "1")
+ end
+
+ it "routes to #destroy" do
+ delete("/cources/1").should route_to("cources#destroy", :id => "1")
+ end
+
+ end
+end
View
22 spec/views/cources/edit.html.erb_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe "cources/edit.html.erb" do
+ before(:each) do
+ @cource = assign(:cource, stub_model(Cource,
+ :name => "MyString",
+ :question => nil,
+ :created_by => 1
+ ))
+ end
+
+ it "renders the edit cource form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => cources_path(@cource), :method => "post" do
+ assert_select "input#cource_name", :name => "cource[name]"
+ assert_select "input#cource_question", :name => "cource[question]"
+ assert_select "input#cource_created_by", :name => "cource[created_by]"
+ end
+ end
+end
View
28 spec/views/cources/index.html.erb_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe "cources/index.html.erb" do
+ before(:each) do
+ assign(:cources, [
+ stub_model(Cource,
+ :name => "Name",
+ :question => nil,
+ :created_by => 1
+ ),
+ stub_model(Cource,
+ :name => "Name",
+ :question => nil,
+ :created_by => 1
+ )
+ ])
+ end
+
+ it "renders a list of cources" 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
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "tr>td", :text => nil.to_s, :count => 2
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "tr>td", :text => 1.to_s, :count => 2
+ end
+end
View
22 spec/views/cources/new.html.erb_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe "cources/new.html.erb" do
+ before(:each) do
+ assign(:cource, stub_model(Cource,
+ :name => "MyString",
+ :question => nil,
+ :created_by => 1
+ ).as_new_record)
+ end
+
+ it "renders new cource form" do
+ render
+
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ assert_select "form", :action => cources_path, :method => "post" do
+ assert_select "input#cource_name", :name => "cource[name]"
+ assert_select "input#cource_question", :name => "cource[question]"
+ assert_select "input#cource_created_by", :name => "cource[created_by]"
+ end
+ end
+end
View
21 spec/views/cources/show.html.erb_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper'
+
+describe "cources/show.html.erb" do
+ before(:each) do
+ @cource = assign(:cource, stub_model(Cource,
+ :name => "Name",
+ :question => nil,
+ :created_by => 1
+ ))
+ end
+
+ it "renders attributes in <p>" do
+ render
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ rendered.should match(/Name/)
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ rendered.should match(//)
+ # Run the generator again with the --webrat flag if you want to use webrat matchers
+ rendered.should match(/1/)
+ end
+end
View
5 spec/views/dashboard/index.html.erb_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe "dashboard/index.html.erb" do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.