{"action":"created","comment":{"url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments/30017041","id":30017041,"diff_hunk":"@@ -16,5 +16,94 @@\n       it { is_expected.not_to be_published }\n       it { is_expected.not_to be_opened }\n     end\n+\n+    describe 'module preferences' do\n+      let(:course) { create(:course, instance: instance) }\n+      let(:all_modules) { instance.enabled_modules }\n+\n+      describe '#set_default_settings' do\n+        it 'initializes the default values' do\n+          all_modules.each do |m|\n+            expect(course.settings(m.key).enabled).to eq m.enabled_by_default?\n+          end\n+        end\n+      end\n+\n+      describe '#enabled_modules' do\n+        let(:enabled_modules) { course.enabled_modules }\n+\n+        context 'without preference' do\n+          it 'returns the default enabled modules' do\n+            default_enabled_modules = all_modules.select(&:enabled_by_default?)\n+            expect(enabled_modules.count).to eq default_enabled_modules.count\n+            default_enabled_modules.each do |m|\n+              expect(enabled_modules.include?(m)).to eq true\n+            end\n+          end\n+        end\n+\n+        context 'with preference' do\n+          let(:sample_module) { all_modules.first }\n+          context 'disable a module' do\n+            before do\n+              course.settings(sample_module.key).enabled = false\n+              course.save\n+            end\n+\n+            it 'does not include the disabled module' do\n+              expect(enabled_modules.include?(sample_module)).to eq false\n+            end\n+          end\n+\n+          context 'enable a module' do\n+            before do\n+              course.settings(sample_module.key).enabled = true\n+              course.save\n+            end\n+\n+            it 'includes the disabled module' do\n+              expect(enabled_modules.include?(sample_module)).to eq true\n+            end\n+          end\n+        end\n+      end\n+\n+      describe '#disabled_modules' do\n+        let(:disabled_modules) { course.disabled_modules }\n+\n+        context 'without preference' do\n+          it 'returns the default disabled modules' do\n+            default_disabled_modules = all_modules.select { |m| !m.enabled_by_default? }\n+            expect(disabled_modules.count).to eq default_disabled_modules.count\n+            default_disabled_modules.each do |m|\n+              expect(disabled_modules.include?(m)).to eq true\n+            end\n+          end\n+        end\n+\n+        context 'with preference' do\n+          let(:sample_module) { all_modules.first }\n+          context 'disable a module' do\n+            before do\n+              course.settings(sample_module.key).enabled = false\n+            end\n+\n+            it 'includes the disabled module' do\n+              expect(disabled_modules.include?(sample_module)).to eq true\n+            end\n+          end\n+\n+          context 'enable a module' do\n+            before do\n+              course.settings(sample_module.key).enabled = true\n+            end\n+\n+            it 'does not include the enabled module' do\n+              expect(disabled_modules.include?(sample_module)).to eq false\n+            end\n+          end\n+        end\n+      end\n+    end","path":"spec/models/course_spec.rb","position":92,"original_position":92,"commit_id":"369af9d6e4df9febbf7624837ebfb43853bc6efa","original_commit_id":"369af9d6e4df9febbf7624837ebfb43853bc6efa","user":{"login":"lowjoel","id":2505070,"avatar_url":"https://avatars.githubusercontent.com/u/2505070?v=3","gravatar_id":"","url":"https://api.github.com/users/lowjoel","html_url":"https://github.com/lowjoel","followers_url":"https://api.github.com/users/lowjoel/followers","following_url":"https://api.github.com/users/lowjoel/following{/other_user}","gists_url":"https://api.github.com/users/lowjoel/gists{/gist_id}","starred_url":"https://api.github.com/users/lowjoel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lowjoel/subscriptions","organizations_url":"https://api.github.com/users/lowjoel/orgs","repos_url":"https://api.github.com/users/lowjoel/repos","events_url":"https://api.github.com/users/lowjoel/events{/privacy}","received_events_url":"https://api.github.com/users/lowjoel/received_events","type":"User","site_admin":false},"body":"Does this PR handle disabling of course modules if the instance has the module disabled?","created_at":"2015-05-11T07:19:49Z","updated_at":"2015-05-11T07:19:49Z","html_url":"https://github.com/Coursemology/coursemology2/pull/155#discussion_r30017041","pull_request_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/155","_links":{"self":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments/30017041"},"html":{"href":"https://github.com/Coursemology/coursemology2/pull/155#discussion_r30017041"},"pull_request":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/155"}}},"pull_request":{"url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/155","id":32286643,"html_url":"https://github.com/Coursemology/coursemology2/pull/155","diff_url":"https://github.com/Coursemology/coursemology2/pull/155.diff","patch_url":"https://github.com/Coursemology/coursemology2/pull/155.patch","issue_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/155","number":155,"state":"open","locked":false,"title":"Module settings models","user":{"login":"allenwq","id":4983239,"avatar_url":"https://avatars.githubusercontent.com/u/4983239?v=3","gravatar_id":"","url":"https://api.github.com/users/allenwq","html_url":"https://github.com/allenwq","followers_url":"https://api.github.com/users/allenwq/followers","following_url":"https://api.github.com/users/allenwq/following{/other_user}","gists_url":"https://api.github.com/users/allenwq/gists{/gist_id}","starred_url":"https://api.github.com/users/allenwq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/allenwq/subscriptions","organizations_url":"https://api.github.com/users/allenwq/orgs","repos_url":"https://api.github.com/users/allenwq/repos","events_url":"https://api.github.com/users/allenwq/events{/privacy}","received_events_url":"https://api.github.com/users/allenwq/received_events","type":"User","site_admin":false},"body":"Support turn on/off modules in instances/courses.\r\nAdd a ModuleSettingsConcern in this PR, which lets instance and course have following functions:\r\n```ruby\r\n@instance.modules # all the available modules \r\n@instance.enabled_modules\r\n@instance.disabled_modules\r\n\r\n# If a module was disabled in that instance, course will not able to see it\r\n@course.modules\r\n@course.enabled_modules\r\n@course.disabled_modules\r\n```","created_at":"2015-03-31T02:42:20Z","updated_at":"2015-05-11T07:19:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ede1555426d5b0f316667614a8909e61dc574501","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/155/commits","review_comments_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/155/comments","review_comment_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/155/comments","statuses_url":"https://api.github.com/repos/Coursemology/coursemology2/statuses/369af9d6e4df9febbf7624837ebfb43853bc6efa","head":{"label":"coursemology-collab:wangqiang/instance-settings-models","ref":"wangqiang/instance-settings-models","sha":"369af9d6e4df9febbf7624837ebfb43853bc6efa","user":{"login":"coursemology-collab","id":8666458,"avatar_url":"https://avatars.githubusercontent.com/u/8666458?v=3","gravatar_id":"","url":"https://api.github.com/users/coursemology-collab","html_url":"https://github.com/coursemology-collab","followers_url":"https://api.github.com/users/coursemology-collab/followers","following_url":"https://api.github.com/users/coursemology-collab/following{/other_user}","gists_url":"https://api.github.com/users/coursemology-collab/gists{/gist_id}","starred_url":"https://api.github.com/users/coursemology-collab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coursemology-collab/subscriptions","organizations_url":"https://api.github.com/users/coursemology-collab/orgs","repos_url":"https://api.github.com/users/coursemology-collab/repos","events_url":"https://api.github.com/users/coursemology-collab/events{/privacy}","received_events_url":"https://api.github.com/users/coursemology-collab/received_events","type":"Organization","site_admin":false},"repo":{"id":23697674,"name":"coursemology2","full_name":"coursemology-collab/coursemology2","owner":{"login":"coursemology-collab","id":8666458,"avatar_url":"https://avatars.githubusercontent.com/u/8666458?v=3","gravatar_id":"","url":"https://api.github.com/users/coursemology-collab","html_url":"https://github.com/coursemology-collab","followers_url":"https://api.github.com/users/coursemology-collab/followers","following_url":"https://api.github.com/users/coursemology-collab/following{/other_user}","gists_url":"https://api.github.com/users/coursemology-collab/gists{/gist_id}","starred_url":"https://api.github.com/users/coursemology-collab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coursemology-collab/subscriptions","organizations_url":"https://api.github.com/users/coursemology-collab/orgs","repos_url":"https://api.github.com/users/coursemology-collab/repos","events_url":"https://api.github.com/users/coursemology-collab/events{/privacy}","received_events_url":"https://api.github.com/users/coursemology-collab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coursemology-collab/coursemology2","description":"Rails 4 re-write of Coursemology","fork":true,"url":"https://api.github.com/repos/coursemology-collab/coursemology2","forks_url":"https://api.github.com/repos/coursemology-collab/coursemology2/forks","keys_url":"https://api.github.com/repos/coursemology-collab/coursemology2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coursemology-collab/coursemology2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coursemology-collab/coursemology2/teams","hooks_url":"https://api.github.com/repos/coursemology-collab/coursemology2/hooks","issue_events_url":"https://api.github.com/repos/coursemology-collab/coursemology2/issues/events{/number}","events_url":"https://api.github.com/repos/coursemology-collab/coursemology2/events","assignees_url":"https://api.github.com/repos/coursemology-collab/coursemology2/assignees{/user}","branches_url":"https://api.github.com/repos/coursemology-collab/coursemology2/branches{/branch}","tags_url":"https://api.github.com/repos/coursemology-collab/coursemology2/tags","blobs_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/refs{/sha}","trees_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coursemology-collab/coursemology2/statuses/{sha}","languages_url":"https://api.github.com/repos/coursemology-collab/coursemology2/languages","stargazers_url":"https://api.github.com/repos/coursemology-collab/coursemology2/stargazers","contributors_url":"https://api.github.com/repos/coursemology-collab/coursemology2/contributors","subscribers_url":"https://api.github.com/repos/coursemology-collab/coursemology2/subscribers","subscription_url":"https://api.github.com/repos/coursemology-collab/coursemology2/subscription","commits_url":"https://api.github.com/repos/coursemology-collab/coursemology2/commits{/sha}","git_commits_url":"https://api.github.com/repos/coursemology-collab/coursemology2/git/commits{/sha}","comments_url":"https://api.github.com/repos/coursemology-collab/coursemology2/comments{/number}","issue_comment_url":"https://api.github.com/repos/coursemology-collab/coursemology2/issues/comments{/number}","contents_url":"https://api.github.com/repos/coursemology-collab/coursemology2/contents/{+path}","compare_url":"https://api.github.com/repos/coursemology-collab/coursemology2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coursemology-collab/coursemology2/merges","archive_url":"https://api.github.com/repos/coursemology-collab/coursemology2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coursemology-collab/coursemology2/downloads","issues_url":"https://api.github.com/repos/coursemology-collab/coursemology2/issues{/number}","pulls_url":"https://api.github.com/repos/coursemology-collab/coursemology2/pulls{/number}","milestones_url":"https://api.github.com/repos/coursemology-collab/coursemology2/milestones{/number}","notifications_url":"https://api.github.com/repos/coursemology-collab/coursemology2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coursemology-collab/coursemology2/labels{/name}","releases_url":"https://api.github.com/repos/coursemology-collab/coursemology2/releases{/id}","created_at":"2014-09-05T09:32:07Z","updated_at":"2015-04-24T08:37:06Z","pushed_at":"2015-05-11T06:55:52Z","git_url":"git://github.com/coursemology-collab/coursemology2.git","ssh_url":"git@github.com:coursemology-collab/coursemology2.git","clone_url":"https://github.com/coursemology-collab/coursemology2.git","svn_url":"https://github.com/coursemology-collab/coursemology2","homepage":null,"size":3530,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"lowjoel/master"}},"base":{"label":"Coursemology:master","ref":"master","sha":"4c38f2912ef4cc43a2b002be9aa07108da5debd5","user":{"login":"Coursemology","id":4427741,"avatar_url":"https://avatars.githubusercontent.com/u/4427741?v=3","gravatar_id":"","url":"https://api.github.com/users/Coursemology","html_url":"https://github.com/Coursemology","followers_url":"https://api.github.com/users/Coursemology/followers","following_url":"https://api.github.com/users/Coursemology/following{/other_user}","gists_url":"https://api.github.com/users/Coursemology/gists{/gist_id}","starred_url":"https://api.github.com/users/Coursemology/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Coursemology/subscriptions","organizations_url":"https://api.github.com/users/Coursemology/orgs","repos_url":"https://api.github.com/users/Coursemology/repos","events_url":"https://api.github.com/users/Coursemology/events{/privacy}","received_events_url":"https://api.github.com/users/Coursemology/received_events","type":"Organization","site_admin":false},"repo":{"id":22155032,"name":"coursemology2","full_name":"Coursemology/coursemology2","owner":{"login":"Coursemology","id":4427741,"avatar_url":"https://avatars.githubusercontent.com/u/4427741?v=3","gravatar_id":"","url":"https://api.github.com/users/Coursemology","html_url":"https://github.com/Coursemology","followers_url":"https://api.github.com/users/Coursemology/followers","following_url":"https://api.github.com/users/Coursemology/following{/other_user}","gists_url":"https://api.github.com/users/Coursemology/gists{/gist_id}","starred_url":"https://api.github.com/users/Coursemology/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Coursemology/subscriptions","organizations_url":"https://api.github.com/users/Coursemology/orgs","repos_url":"https://api.github.com/users/Coursemology/repos","events_url":"https://api.github.com/users/Coursemology/events{/privacy}","received_events_url":"https://api.github.com/users/Coursemology/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Coursemology/coursemology2","description":"Rails 4 re-write of Coursemology","fork":false,"url":"https://api.github.com/repos/Coursemology/coursemology2","forks_url":"https://api.github.com/repos/Coursemology/coursemology2/forks","keys_url":"https://api.github.com/repos/Coursemology/coursemology2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Coursemology/coursemology2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Coursemology/coursemology2/teams","hooks_url":"https://api.github.com/repos/Coursemology/coursemology2/hooks","issue_events_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/events{/number}","events_url":"https://api.github.com/repos/Coursemology/coursemology2/events","assignees_url":"https://api.github.com/repos/Coursemology/coursemology2/assignees{/user}","branches_url":"https://api.github.com/repos/Coursemology/coursemology2/branches{/branch}","tags_url":"https://api.github.com/repos/Coursemology/coursemology2/tags","blobs_url":"https://api.github.com/repos/Coursemology/coursemology2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Coursemology/coursemology2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Coursemology/coursemology2/git/refs{/sha}","trees_url":"https://api.github.com/repos/Coursemology/coursemology2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Coursemology/coursemology2/statuses/{sha}","languages_url":"https://api.github.com/repos/Coursemology/coursemology2/languages","stargazers_url":"https://api.github.com/repos/Coursemology/coursemology2/stargazers","contributors_url":"https://api.github.com/repos/Coursemology/coursemology2/contributors","subscribers_url":"https://api.github.com/repos/Coursemology/coursemology2/subscribers","subscription_url":"https://api.github.com/repos/Coursemology/coursemology2/subscription","commits_url":"https://api.github.com/repos/Coursemology/coursemology2/commits{/sha}","git_commits_url":"https://api.github.com/repos/Coursemology/coursemology2/git/commits{/sha}","comments_url":"https://api.github.com/repos/Coursemology/coursemology2/comments{/number}","issue_comment_url":"https://api.github.com/repos/Coursemology/coursemology2/issues/comments{/number}","contents_url":"https://api.github.com/repos/Coursemology/coursemology2/contents/{+path}","compare_url":"https://api.github.com/repos/Coursemology/coursemology2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Coursemology/coursemology2/merges","archive_url":"https://api.github.com/repos/Coursemology/coursemology2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Coursemology/coursemology2/downloads","issues_url":"https://api.github.com/repos/Coursemology/coursemology2/issues{/number}","pulls_url":"https://api.github.com/repos/Coursemology/coursemology2/pulls{/number}","milestones_url":"https://api.github.com/repos/Coursemology/coursemology2/milestones{/number}","notifications_url":"https://api.github.com/repos/Coursemology/coursemology2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Coursemology/coursemology2/labels{/name}","releases_url":"https://api.github.com/repos/Coursemology/coursemology2/releases{/id}","created_at":"2014-07-23T14:57:06Z","updated_at":"2015-05-07T09:29:14Z","pushed_at":"2015-05-11T06:55:54Z","git_url":"git://github.com/Coursemology/coursemology2.git","ssh_url":"git@github.com:Coursemology/coursemology2.git","clone_url":"https://github.com/Coursemology/coursemology2.git","svn_url":"https://github.com/Coursemology/coursemology2","homepage":null,"size":3993,"stargazers_count":11,"watchers_count":11,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":31,"forks":9,"open_issues":31,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/155"},"html":{"href":"https://github.com/Coursemology/coursemology2/pull/155"},"issue":{"href":"https://api.github.com/repos/Coursemology/coursemology2/issues/155"},"comments":{"href":"https://api.github.com/repos/Coursemology/coursemology2/issues/155/comments"},"review_comments":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/155/comments"},"review_comment":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Coursemology/coursemology2/pulls/155/commits"},"statuses":{"href":"https://api.github.com/repos/Coursemology/coursemology2/statuses/369af9d6e4df9febbf7624837ebfb43853bc6efa"}}}}