qiita_matome 0.0.1
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.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.rubocop.yml +0 -0
- data/.travis.yml +8 -0
- data/CONTRIBUTING.md +44 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +210 -0
- data/Rakefile +8 -0
- data/bin/qiitam +34 -0
- data/lib/display.rb +10 -0
- data/lib/display/display_consts.rb +35 -0
- data/lib/display/displayer.rb +81 -0
- data/lib/file_writer.rb +19 -0
- data/lib/models/article.rb +38 -0
- data/lib/models/articles.rb +40 -0
- data/lib/qiita_json_loader.rb +43 -0
- data/lib/qiita_matome/version.rb +4 -0
- data/lib/qiita_matome_core.rb +121 -0
- data/lib/qiita_matome_dsl.rb +31 -0
- data/lib/qiita_matome_dsl_model.rb +37 -0
- data/lib/sort.rb +10 -0
- data/lib/sort/sort_consts.rb +28 -0
- data/lib/sort/sorter.rb +51 -0
- data/lib/validators.rb +13 -0
- data/lib/validators/article_validator.rb +19 -0
- data/lib/validators/articles_validator.rb +16 -0
- data/lib/validators/display_columns_validator.rb +41 -0
- data/lib/validators/sort_type_validator.rb +19 -0
- data/manual_test_docs/.gitkeep +0 -0
- data/qiita_matome.gemspec +28 -0
- data/samples/matome_title_asc.md +25 -0
- data/spec/display/displayer_spec.rb +341 -0
- data/spec/file_writer_spec.rb +92 -0
- data/spec/models/article_spec.rb +131 -0
- data/spec/models/articles_spec.rb +305 -0
- data/spec/qiita_matome_core_spec.rb +46 -0
- data/spec/sort/sorter_spec.rb +392 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/validators/article_validator_spec.rb +53 -0
- data/spec/validators/articles_validator_spec.rb +54 -0
- data/spec/validators/display_columns_validator_spec.rb +58 -0
- data/spec/validators/sort_type_validator_spec.rb +54 -0
- metadata +202 -0
| @@ -0,0 +1,46 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
            require 'spec_helper'
         | 
| 3 | 
            +
            require 'qiita_matome_core'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            # rubocop:disable LineLength, UnusedMethodArgument, UselessAssignment
         | 
| 6 | 
            +
            describe QiitaMatome::Core do
         | 
| 7 | 
            +
              context :execute do
         | 
| 8 | 
            +
                cases = [
         | 
| 9 | 
            +
                  {
         | 
| 10 | 
            +
                    case_no: 1,
         | 
| 11 | 
            +
                    case_title: 'case_title',
         | 
| 12 | 
            +
                    expected: 'expected'
         | 
| 13 | 
            +
                  }
         | 
| 14 | 
            +
                ]
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                cases.each do |c|
         | 
| 17 | 
            +
                  it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
         | 
| 18 | 
            +
                    begin
         | 
| 19 | 
            +
                      case_before c
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                      # -- given --
         | 
| 22 | 
            +
                      qiita_matome_core = QiitaMatome::Core.new
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                      # -- when --
         | 
| 25 | 
            +
                      # TODO: implement execute code
         | 
| 26 | 
            +
                      # actual = qiita_matome_core.execute
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                      # -- then --
         | 
| 29 | 
            +
                      # TODO: implement assertion code
         | 
| 30 | 
            +
                      # expect(actual).to eq(c[:expected])
         | 
| 31 | 
            +
                    ensure
         | 
| 32 | 
            +
                      case_after c
         | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  def case_before(c)
         | 
| 37 | 
            +
                    # implement each case before
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def case_after(c)
         | 
| 41 | 
            +
                    # implement each case after
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| 46 | 
            +
            # rubocop:enable LineLength, UnusedMethodArgument, UselessAssignment
         | 
| @@ -0,0 +1,392 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
            require 'spec_helper'
         | 
| 3 | 
            +
            require 'sort/sort_consts'
         | 
| 4 | 
            +
            require 'sort/sorter'
         | 
| 5 | 
            +
            require 'models/article'
         | 
| 6 | 
            +
            require 'models/articles'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            # rubocop:disable LineLength, UnusedMethodArgument
         | 
| 9 | 
            +
            describe QiitaMatome::Sort::Sorter do
         | 
| 10 | 
            +
              context :new do
         | 
| 11 | 
            +
                cases = [
         | 
| 12 | 
            +
                  {
         | 
| 13 | 
            +
                    case_no: 1,
         | 
| 14 | 
            +
                    case_title: 'valid args',
         | 
| 15 | 
            +
                    articles: [QiitaMatome::Article.new, QiitaMatome::Article.new],
         | 
| 16 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::CREATED_AT_ASC
         | 
| 17 | 
            +
                  },
         | 
| 18 | 
            +
                  {
         | 
| 19 | 
            +
                    case_no: 2,
         | 
| 20 | 
            +
                    case_title: 'invalid articles class "String"',
         | 
| 21 | 
            +
                    articles: 'String',
         | 
| 22 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::CREATED_AT_ASC,
         | 
| 23 | 
            +
                    expect_error: true
         | 
| 24 | 
            +
                  },
         | 
| 25 | 
            +
                  {
         | 
| 26 | 
            +
                    case_no: 3,
         | 
| 27 | 
            +
                    case_title: 'invalid article class "String"',
         | 
| 28 | 
            +
                    articles: [QiitaMatome::Article.new, 'String'],
         | 
| 29 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::CREATED_AT_ASC,
         | 
| 30 | 
            +
                    expect_error: true
         | 
| 31 | 
            +
                  },
         | 
| 32 | 
            +
                  {
         | 
| 33 | 
            +
                    case_no: 4,
         | 
| 34 | 
            +
                    case_title: 'invalid sort_type "invalid"',
         | 
| 35 | 
            +
                    articles: [QiitaMatome::Article.new, QiitaMatome::Article.new],
         | 
| 36 | 
            +
                    sort_type: 'invalid',
         | 
| 37 | 
            +
                    expect_error: true
         | 
| 38 | 
            +
                  }
         | 
| 39 | 
            +
                ]
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                cases.each do |c|
         | 
| 42 | 
            +
                  it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
         | 
| 43 | 
            +
                    begin
         | 
| 44 | 
            +
                      case_before c
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                      # -- given --
         | 
| 47 | 
            +
                      if c[:expect_error]
         | 
| 48 | 
            +
                        -> { QiitaMatome::Sort::Sorter.new(c[:articles], c[:sort_type]) }.should raise_error(ArgumentError)
         | 
| 49 | 
            +
                        next
         | 
| 50 | 
            +
                      end
         | 
| 51 | 
            +
                      qss = QiitaMatome::Sort::Sorter.new(c[:articles], c[:sort_type])
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                      # -- when --
         | 
| 54 | 
            +
                      actual_articles = qss.articles
         | 
| 55 | 
            +
                      actual_sort_type = qss.sort_type
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                      # -- then --
         | 
| 58 | 
            +
                      expect(actual_articles).to eq(c[:articles])
         | 
| 59 | 
            +
                      expect(actual_sort_type).to eq(c[:sort_type])
         | 
| 60 | 
            +
                    ensure
         | 
| 61 | 
            +
                      case_after c
         | 
| 62 | 
            +
                    end
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  def case_before(c)
         | 
| 66 | 
            +
                    # implement each case before
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                  def case_after(c)
         | 
| 70 | 
            +
                    # implement each case after
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
              end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
              context :sort do
         | 
| 76 | 
            +
                ARTICLES = [
         | 
| 77 | 
            +
                  QiitaMatome::Article.new(
         | 
| 78 | 
            +
                    user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 79 | 
            +
                    title: 'title1',
         | 
| 80 | 
            +
                    created_at: '2014-06-18 22:37:54 +0900',
         | 
| 81 | 
            +
                    updated_at: '2014-06-26 02:25:11 +0900',
         | 
| 82 | 
            +
                    tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 83 | 
            +
                    stock_count: 2
         | 
| 84 | 
            +
                  ),
         | 
| 85 | 
            +
                  QiitaMatome::Article.new(
         | 
| 86 | 
            +
                    user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 87 | 
            +
                    title: 'title2',
         | 
| 88 | 
            +
                    created_at: '2014-06-18 22:37:53 +0900',
         | 
| 89 | 
            +
                    updated_at: '2014-06-26 02:25:09 +0900',
         | 
| 90 | 
            +
                    tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 91 | 
            +
                    stock_count: 3
         | 
| 92 | 
            +
                  ),
         | 
| 93 | 
            +
                  QiitaMatome::Article.new(
         | 
| 94 | 
            +
                    user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 95 | 
            +
                    title: 'title3',
         | 
| 96 | 
            +
                    created_at: '2014-06-18 22:37:52 +0900',
         | 
| 97 | 
            +
                    updated_at: '2014-06-26 02:25:10 +0900',
         | 
| 98 | 
            +
                    tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 99 | 
            +
                    stock_count: 10
         | 
| 100 | 
            +
                  )
         | 
| 101 | 
            +
                ]
         | 
| 102 | 
            +
                cases = [
         | 
| 103 | 
            +
                  {
         | 
| 104 | 
            +
                    case_no: 1,
         | 
| 105 | 
            +
                    case_title: 'create date asc',
         | 
| 106 | 
            +
                    articles: ARTICLES,
         | 
| 107 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::CREATED_AT_ASC,
         | 
| 108 | 
            +
                    expected: [
         | 
| 109 | 
            +
                      QiitaMatome::Article.new(
         | 
| 110 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 111 | 
            +
                        title: 'title3',
         | 
| 112 | 
            +
                        created_at: '2014-06-18 22:37:52 +0900',
         | 
| 113 | 
            +
                        updated_at: '2014-06-26 02:25:10 +0900',
         | 
| 114 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 115 | 
            +
                        stock_count: 10
         | 
| 116 | 
            +
                      ),
         | 
| 117 | 
            +
                      QiitaMatome::Article.new(
         | 
| 118 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 119 | 
            +
                        title: 'title2',
         | 
| 120 | 
            +
                        created_at: '2014-06-18 22:37:53 +0900',
         | 
| 121 | 
            +
                        updated_at: '2014-06-26 02:25:09 +0900',
         | 
| 122 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 123 | 
            +
                        stock_count: 3
         | 
| 124 | 
            +
                      ),
         | 
| 125 | 
            +
                      QiitaMatome::Article.new(
         | 
| 126 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 127 | 
            +
                        title: 'title1',
         | 
| 128 | 
            +
                        created_at: '2014-06-18 22:37:54 +0900',
         | 
| 129 | 
            +
                        updated_at: '2014-06-26 02:25:11 +0900',
         | 
| 130 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 131 | 
            +
                        stock_count: 2
         | 
| 132 | 
            +
                      )
         | 
| 133 | 
            +
                    ]
         | 
| 134 | 
            +
                  },
         | 
| 135 | 
            +
                  {
         | 
| 136 | 
            +
                    case_no: 2,
         | 
| 137 | 
            +
                    case_title: 'create date desc',
         | 
| 138 | 
            +
                    articles: ARTICLES,
         | 
| 139 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::CREATED_AT_DESC,
         | 
| 140 | 
            +
                    expected: [
         | 
| 141 | 
            +
                      QiitaMatome::Article.new(
         | 
| 142 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 143 | 
            +
                        title: 'title1',
         | 
| 144 | 
            +
                        created_at: '2014-06-18 22:37:54 +0900',
         | 
| 145 | 
            +
                        updated_at: '2014-06-26 02:25:11 +0900',
         | 
| 146 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 147 | 
            +
                        stock_count: 2
         | 
| 148 | 
            +
                      ),
         | 
| 149 | 
            +
                      QiitaMatome::Article.new(
         | 
| 150 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 151 | 
            +
                        title: 'title2',
         | 
| 152 | 
            +
                        created_at: '2014-06-18 22:37:53 +0900',
         | 
| 153 | 
            +
                        updated_at: '2014-06-26 02:25:09 +0900',
         | 
| 154 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 155 | 
            +
                        stock_count: 3
         | 
| 156 | 
            +
                      ),
         | 
| 157 | 
            +
                      QiitaMatome::Article.new(
         | 
| 158 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 159 | 
            +
                        title: 'title3',
         | 
| 160 | 
            +
                        created_at: '2014-06-18 22:37:52 +0900',
         | 
| 161 | 
            +
                        updated_at: '2014-06-26 02:25:10 +0900',
         | 
| 162 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 163 | 
            +
                        stock_count: 10
         | 
| 164 | 
            +
                      )
         | 
| 165 | 
            +
                    ]
         | 
| 166 | 
            +
                  },
         | 
| 167 | 
            +
                  {
         | 
| 168 | 
            +
                    case_no: 3,
         | 
| 169 | 
            +
                    case_title: 'update date asc',
         | 
| 170 | 
            +
                    articles: ARTICLES,
         | 
| 171 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::UPDATED_AT_ASC,
         | 
| 172 | 
            +
                    expected: [
         | 
| 173 | 
            +
                      QiitaMatome::Article.new(
         | 
| 174 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 175 | 
            +
                        title: 'title2',
         | 
| 176 | 
            +
                        created_at: '2014-06-18 22:37:53 +0900',
         | 
| 177 | 
            +
                        updated_at: '2014-06-26 02:25:09 +0900',
         | 
| 178 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 179 | 
            +
                        stock_count: 3
         | 
| 180 | 
            +
                      ),
         | 
| 181 | 
            +
                      QiitaMatome::Article.new(
         | 
| 182 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 183 | 
            +
                        title: 'title3',
         | 
| 184 | 
            +
                        created_at: '2014-06-18 22:37:52 +0900',
         | 
| 185 | 
            +
                        updated_at: '2014-06-26 02:25:10 +0900',
         | 
| 186 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 187 | 
            +
                        stock_count: 10
         | 
| 188 | 
            +
                      ),
         | 
| 189 | 
            +
                      QiitaMatome::Article.new(
         | 
| 190 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 191 | 
            +
                        title: 'title1',
         | 
| 192 | 
            +
                        created_at: '2014-06-18 22:37:54 +0900',
         | 
| 193 | 
            +
                        updated_at: '2014-06-26 02:25:11 +0900',
         | 
| 194 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 195 | 
            +
                        stock_count: 2
         | 
| 196 | 
            +
                      )
         | 
| 197 | 
            +
                    ]
         | 
| 198 | 
            +
                  },
         | 
| 199 | 
            +
                  {
         | 
| 200 | 
            +
                    case_no: 4,
         | 
| 201 | 
            +
                    case_title: 'update date desc',
         | 
| 202 | 
            +
                    articles: ARTICLES,
         | 
| 203 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::UPDATED_AT_DESC,
         | 
| 204 | 
            +
                    expected: [
         | 
| 205 | 
            +
                      QiitaMatome::Article.new(
         | 
| 206 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 207 | 
            +
                        title: 'title1',
         | 
| 208 | 
            +
                        created_at: '2014-06-18 22:37:54 +0900',
         | 
| 209 | 
            +
                        updated_at: '2014-06-26 02:25:11 +0900',
         | 
| 210 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 211 | 
            +
                        stock_count: 2
         | 
| 212 | 
            +
                      ),
         | 
| 213 | 
            +
                      QiitaMatome::Article.new(
         | 
| 214 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 215 | 
            +
                        title: 'title3',
         | 
| 216 | 
            +
                        created_at: '2014-06-18 22:37:52 +0900',
         | 
| 217 | 
            +
                        updated_at: '2014-06-26 02:25:10 +0900',
         | 
| 218 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 219 | 
            +
                        stock_count: 10
         | 
| 220 | 
            +
                      ),
         | 
| 221 | 
            +
                      QiitaMatome::Article.new(
         | 
| 222 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 223 | 
            +
                        title: 'title2',
         | 
| 224 | 
            +
                        created_at: '2014-06-18 22:37:53 +0900',
         | 
| 225 | 
            +
                        updated_at: '2014-06-26 02:25:09 +0900',
         | 
| 226 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 227 | 
            +
                        stock_count: 3
         | 
| 228 | 
            +
                      )
         | 
| 229 | 
            +
                    ]
         | 
| 230 | 
            +
                  },
         | 
| 231 | 
            +
                  {
         | 
| 232 | 
            +
                    case_no: 5,
         | 
| 233 | 
            +
                    case_title: 'title asc',
         | 
| 234 | 
            +
                    articles: ARTICLES,
         | 
| 235 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::TITLE_ASC,
         | 
| 236 | 
            +
                    expected: [
         | 
| 237 | 
            +
                      QiitaMatome::Article.new(
         | 
| 238 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 239 | 
            +
                        title: 'title1',
         | 
| 240 | 
            +
                        created_at: '2014-06-18 22:37:54 +0900',
         | 
| 241 | 
            +
                        updated_at: '2014-06-26 02:25:11 +0900',
         | 
| 242 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 243 | 
            +
                        stock_count: 2
         | 
| 244 | 
            +
                      ),
         | 
| 245 | 
            +
                      QiitaMatome::Article.new(
         | 
| 246 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 247 | 
            +
                        title: 'title2',
         | 
| 248 | 
            +
                        created_at: '2014-06-18 22:37:53 +0900',
         | 
| 249 | 
            +
                        updated_at: '2014-06-26 02:25:09 +0900',
         | 
| 250 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 251 | 
            +
                        stock_count: 3
         | 
| 252 | 
            +
                      ),
         | 
| 253 | 
            +
                      QiitaMatome::Article.new(
         | 
| 254 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 255 | 
            +
                        title: 'title3',
         | 
| 256 | 
            +
                        created_at: '2014-06-18 22:37:52 +0900',
         | 
| 257 | 
            +
                        updated_at: '2014-06-26 02:25:10 +0900',
         | 
| 258 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 259 | 
            +
                        stock_count: 10
         | 
| 260 | 
            +
                      )
         | 
| 261 | 
            +
                    ]
         | 
| 262 | 
            +
                  },
         | 
| 263 | 
            +
                  {
         | 
| 264 | 
            +
                    case_no: 6,
         | 
| 265 | 
            +
                    case_title: 'title desc',
         | 
| 266 | 
            +
                    articles: ARTICLES,
         | 
| 267 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::TITLE_DESC,
         | 
| 268 | 
            +
                    expected: [
         | 
| 269 | 
            +
                      QiitaMatome::Article.new(
         | 
| 270 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 271 | 
            +
                        title: 'title3',
         | 
| 272 | 
            +
                        created_at: '2014-06-18 22:37:52 +0900',
         | 
| 273 | 
            +
                        updated_at: '2014-06-26 02:25:10 +0900',
         | 
| 274 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 275 | 
            +
                        stock_count: 10
         | 
| 276 | 
            +
                      ),
         | 
| 277 | 
            +
                      QiitaMatome::Article.new(
         | 
| 278 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 279 | 
            +
                        title: 'title2',
         | 
| 280 | 
            +
                        created_at: '2014-06-18 22:37:53 +0900',
         | 
| 281 | 
            +
                        updated_at: '2014-06-26 02:25:09 +0900',
         | 
| 282 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 283 | 
            +
                        stock_count: 3
         | 
| 284 | 
            +
                      ),
         | 
| 285 | 
            +
                      QiitaMatome::Article.new(
         | 
| 286 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 287 | 
            +
                        title: 'title1',
         | 
| 288 | 
            +
                        created_at: '2014-06-18 22:37:54 +0900',
         | 
| 289 | 
            +
                        updated_at: '2014-06-26 02:25:11 +0900',
         | 
| 290 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 291 | 
            +
                        stock_count: 2
         | 
| 292 | 
            +
                      )
         | 
| 293 | 
            +
                    ]
         | 
| 294 | 
            +
                  },
         | 
| 295 | 
            +
                  {
         | 
| 296 | 
            +
                    case_no: 7,
         | 
| 297 | 
            +
                    case_title: 'stock_count asc',
         | 
| 298 | 
            +
                    articles: ARTICLES,
         | 
| 299 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::STOCK_COUNT_ASC,
         | 
| 300 | 
            +
                    expected: [
         | 
| 301 | 
            +
                      QiitaMatome::Article.new(
         | 
| 302 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 303 | 
            +
                        title: 'title1',
         | 
| 304 | 
            +
                        created_at: '2014-06-18 22:37:54 +0900',
         | 
| 305 | 
            +
                        updated_at: '2014-06-26 02:25:11 +0900',
         | 
| 306 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 307 | 
            +
                        stock_count: 2
         | 
| 308 | 
            +
                      ),
         | 
| 309 | 
            +
                      QiitaMatome::Article.new(
         | 
| 310 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 311 | 
            +
                        title: 'title2',
         | 
| 312 | 
            +
                        created_at: '2014-06-18 22:37:53 +0900',
         | 
| 313 | 
            +
                        updated_at: '2014-06-26 02:25:09 +0900',
         | 
| 314 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 315 | 
            +
                        stock_count: 3
         | 
| 316 | 
            +
                      ),
         | 
| 317 | 
            +
                      QiitaMatome::Article.new(
         | 
| 318 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 319 | 
            +
                        title: 'title3',
         | 
| 320 | 
            +
                        created_at: '2014-06-18 22:37:52 +0900',
         | 
| 321 | 
            +
                        updated_at: '2014-06-26 02:25:10 +0900',
         | 
| 322 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 323 | 
            +
                        stock_count: 10
         | 
| 324 | 
            +
                      )
         | 
| 325 | 
            +
                    ]
         | 
| 326 | 
            +
                  },
         | 
| 327 | 
            +
                  {
         | 
| 328 | 
            +
                    case_no: 8,
         | 
| 329 | 
            +
                    case_title: 'stock_count desc',
         | 
| 330 | 
            +
                    articles: ARTICLES,
         | 
| 331 | 
            +
                    sort_type: QiitaMatome::Sort::Consts::STOCK_COUNT_DESC,
         | 
| 332 | 
            +
                    expected: [
         | 
| 333 | 
            +
                      QiitaMatome::Article.new(
         | 
| 334 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 335 | 
            +
                        title: 'title3',
         | 
| 336 | 
            +
                        created_at: '2014-06-18 22:37:52 +0900',
         | 
| 337 | 
            +
                        updated_at: '2014-06-26 02:25:10 +0900',
         | 
| 338 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 339 | 
            +
                        stock_count: 10
         | 
| 340 | 
            +
                      ),
         | 
| 341 | 
            +
                      QiitaMatome::Article.new(
         | 
| 342 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 343 | 
            +
                        title: 'title2',
         | 
| 344 | 
            +
                        created_at: '2014-06-18 22:37:53 +0900',
         | 
| 345 | 
            +
                        updated_at: '2014-06-26 02:25:09 +0900',
         | 
| 346 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 347 | 
            +
                        stock_count: 3
         | 
| 348 | 
            +
                      ),
         | 
| 349 | 
            +
                      QiitaMatome::Article.new(
         | 
| 350 | 
            +
                        user: { 'id' => 99_999, 'url_name' => 'tbpgr', 'profile_image_url' => '' },
         | 
| 351 | 
            +
                        title: 'title1',
         | 
| 352 | 
            +
                        created_at: '2014-06-18 22:37:54 +0900',
         | 
| 353 | 
            +
                        updated_at: '2014-06-26 02:25:11 +0900',
         | 
| 354 | 
            +
                        tags: [{ 'name' => 'Ruby', 'url_name' => 'ruby', 'icon_url' => '', 'versions' => [] }],
         | 
| 355 | 
            +
                        stock_count: 2
         | 
| 356 | 
            +
                      )
         | 
| 357 | 
            +
                    ]
         | 
| 358 | 
            +
                  }
         | 
| 359 | 
            +
                ]
         | 
| 360 | 
            +
             | 
| 361 | 
            +
                cases.each do |c|
         | 
| 362 | 
            +
                  it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
         | 
| 363 | 
            +
                    begin
         | 
| 364 | 
            +
                      case_before c
         | 
| 365 | 
            +
             | 
| 366 | 
            +
                      # -- given --
         | 
| 367 | 
            +
                      qss = QiitaMatome::Sort::Sorter.new(c[:articles], c[:sort_type])
         | 
| 368 | 
            +
             | 
| 369 | 
            +
                      # -- when --
         | 
| 370 | 
            +
                      qss.sort
         | 
| 371 | 
            +
                      actual_list = qss.articles
         | 
| 372 | 
            +
             | 
| 373 | 
            +
                      # -- then --
         | 
| 374 | 
            +
                      actual_list.each_with_index do |actual_article, i|
         | 
| 375 | 
            +
                        expect(actual_article.title).to eq(c[:expected][i].title)
         | 
| 376 | 
            +
                      end
         | 
| 377 | 
            +
                    ensure
         | 
| 378 | 
            +
                      case_after c
         | 
| 379 | 
            +
                    end
         | 
| 380 | 
            +
                  end
         | 
| 381 | 
            +
             | 
| 382 | 
            +
                  def case_before(c)
         | 
| 383 | 
            +
                    # implement each case before
         | 
| 384 | 
            +
                  end
         | 
| 385 | 
            +
             | 
| 386 | 
            +
                  def case_after(c)
         | 
| 387 | 
            +
                    # implement each case after
         | 
| 388 | 
            +
                  end
         | 
| 389 | 
            +
                end
         | 
| 390 | 
            +
              end
         | 
| 391 | 
            +
            end
         | 
| 392 | 
            +
            # rubocop:enable LineLength, UnusedMethodArgument
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            # encoding: utf-8
         | 
| 2 | 
            +
            require 'simplecov'
         | 
| 3 | 
            +
            require 'coveralls'
         | 
| 4 | 
            +
            Coveralls.wear!
         | 
| 5 | 
            +
            SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
         | 
| 6 | 
            +
              SimpleCov::Formatter::HTMLFormatter,
         | 
| 7 | 
            +
              Coveralls::SimpleCov::Formatter
         | 
| 8 | 
            +
            ]
         | 
| 9 | 
            +
            SimpleCov.start do
         | 
| 10 | 
            +
              add_filter '/spec/'
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
            RSpec.configure do |config|
         | 
| 13 | 
            +
              config.treat_symbols_as_metadata_keys_with_true_values = true
         | 
| 14 | 
            +
              config.run_all_when_everything_filtered = true
         | 
| 15 | 
            +
              config.filter_run :focus
         | 
| 16 | 
            +
            end
         |